Repository navigation
246 lines (243 loc) Β· 9.72 KB
/
Copy pathpython-publish.yml
File metadata and controls
246 lines (243 loc) Β· 9.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: Upload Python Package
on:
release:
types: [created, edited]
jobs:
tests:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.12"]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
with:
# Install a specific version of uv.
version: "0.11.28"
python-version: ${{ matrix.python-version }}
enable-cache: true
- name: Sync dependencies
run: uv sync --group tests
- name: Run the Tests
run: uv run pytest
json_schemas_artifact:
name: Generate JSON-Schemas
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- name: Check out Git repository
uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
with:
# Install a specific version of uv.
version: "0.11.28"
python-version: ${{ matrix.python-version }}
enable-cache: true
- name: Sync dependencies
run: uv sync --group json_schemas
- name: Build JSON Schemas
run: uv run python generate_or_validate_json_schemas.py --mode generate
env:
TARGET_VERSION: ${{ github.ref_name }}
- name: Upload JSON Schemas as artifact
uses: actions/upload-artifact@v7
with:
name: json-schemas
path: json_schemas/
if-no-files-found: "error"
retention-days: 1
include-hidden-files: "true"
check_version_tag:
name: Check if the version tag is correct
runs-on: ubuntu-latest
env:
# bo4e CLI only reads GITHUB_ACCESS_TOKEN, not GITHUB_TOKEN. Without
# this, anonymous API calls hit GitHub's 60 req/hr rate limit and
# `bo4e repo versions` / `bo4e pull` fail mid-job.
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
needs: [json_schemas_artifact]
steps:
- name: Check out Git repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Download JSON Schemas artifact
uses: actions/download-artifact@v8
with:
name: json-schemas
path: json_schemas/
- name: Install bo4e CLI
uses: ./.github/actions/setup-bo4e
- name: Verify version bump
run: |
LAST_VERSION=$(bo4e repo versions -qcn 1 -r ${{ github.ref_name }})
bo4e pull -t "$LAST_VERSION" -o tmp/last_schemas
bo4e diff schemas tmp/last_schemas json_schemas -o tmp/diff.json
bo4e diff version-bump tmp/diff.json -q
json_schemas_publish:
name: Publish JSON-Schemas
runs-on: ubuntu-latest
needs: [tests, check_version_tag]
concurrency: build-n-publish-json-schemas
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
with:
# Install a specific version of uv.
version: "0.11.28"
python-version: ${{ matrix.python-version }}
enable-cache: true
- name: Download JSON Schemas artifact
uses: actions/download-artifact@v8
with:
name: json-schemas
path: json_schemas/
- name: Remove .version file
run: |
# Remove .version file as we don't want to commit it to BO4E-Schemas
rm json_schemas/.version
- name: Push schemas to BO4E-Schemas repo
uses: cpina/github-action-push-to-another-repository@v1.7.3
env:
API_TOKEN_GITHUB: ${{ secrets.BO4E_PYTHON_GENERATE_SCHEMAS }} # this token expires on 2024-10-09
# token with repo scope
# https://github.com/Hochfrequenz/BO4E-python/settings/secrets/actions/BO4E_PYTHON_GENERATE_SCHEMAS
with:
source-directory: "json_schemas"
target-directory: "src/bo4e_schemas"
destination-github-username: "Hochfrequenz"
destination-repository-name: "BO4E-Schemas"
user-email: bo4e-schemas@hochfrequenz.de
target-branch: main
commit-message: "Update JSON-Schemas - BO4E ${{ github.ref_name }}"
# This step uses the github API to automatically create a release with the same version tag
# in the BO4E-Schemas repo. For this we have to retrieve the commits SHA via the API first.
# For this, we use the lightweight tool jq (https://stedolan.github.io/jq/) to parse the JSON
# response from the API.
- name: Install dependencies for creating release
run: |
uv pip install --system requests click
- name: Tag and release the new version in BO4E-Schemas
run: python bo4e_schemas_create_release.py
env:
GITHUB_TOKEN: ${{ secrets.BO4E_PYTHON_GENERATE_SCHEMAS }} # this token expires on 2024-10-09
VERSION: ${{ github.ref_name }}
docs:
name: ππ Build and deploy documentation to GitHub Pages
# This setup is inspired by
# https://github.com/KernelTuner/kernel_tuner/blob/master/.github/workflows/docs-on-release.yml
runs-on: ubuntu-latest
needs: [tests, check_version_tag]
concurrency: build-n-publish-docs
env:
# bo4e CLI only reads GITHUB_ACCESS_TOKEN, not GITHUB_TOKEN. Required so
# the documentation asset script (bo4e repo versions, bo4e pull) doesn't
# hit GitHub's 60 req/hr anonymous rate limit.
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
- name: Install uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
with:
# Install a specific version of uv.
version: "0.11.28"
python-version: ${{ matrix.python-version }}
enable-cache: true
- name: Sync dependencies
run: uv sync --group docs
- name: Download JSON Schemas artifact
uses: actions/download-artifact@v8
with:
name: json-schemas
path: json_schemas/
- name: Verify BO4E package version
# Note: this relies on the fetch-depth: 0 checkout above so hatch-vcs
# can derive the version from git tags, which feeds the JSON-Schema links.
run: uv run python -c "import bo4e; print(bo4e.__gh_version__)"
- name: Run kroki with docker
run: |
docker compose up -d
- name: Install bo4e CLI
uses: ./.github/actions/setup-bo4e
- name: Generate documentation assets
run: uv run python scripts/generate_docs_assets.py
env:
BO4E_DOCS_REF: ${{ github.ref_name }}
BO4E_DOCS_LABEL: ${{ github.ref_name }}
- name: Build the documentation
uses: sphinx-notes/pages@v2
# Note: This action has a newer version (v3 atm), but it doesn't has the feature to specify the target path.
# We need that in order to be able to store (and deploy) multiple versions of the documentation.
with:
requirements_path: docs/requirements.txt
documentation_path: docs/
target_path: ${{ github.ref_name }}
target_branch: gh-pages
sphinx_options: -W -j auto
env:
SPHINX_DOCS_RELEASE: ${{ github.ref_name }}
SPHINX_DOCS_VERSION: ${{ github.ref_name }}
- name: Export LATEST_TAG
run: |
echo "LATEST_TAG=$(curl -qsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${{ github.api_url }}/repos/${{ github.repository }}/releases/latest" \
| jq -r .tag_name)" >> $GITHUB_ENV
- name: Redirect stable to new release if the new release is marked as latest
if: ${{ env.LATEST_TAG == github.ref_name }}
run: |
echo "Redirecting stable to new version ${{ github.ref_name }}"
rm -rf stable
ln -s ${{ github.ref_name }} stable
git add stable
git commit -m "Redirect stable to new version ${{ github.ref_name }}"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
build-n-publish:
name: Build and publish Python π distributions π¦ to PyPI and TestPyPI
runs-on: ubuntu-latest
# Specifying a GitHub environment, which is strongly recommended by PyPI: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
needs: [tests, json_schemas_publish, docs]
strategy:
matrix:
python-version: ["3.12"]
concurrency: build-n-publish-distributions
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
with:
# Install a specific version of uv.
version: "0.11.28"
python-version: ${{ matrix.python-version }}
enable-cache: true
- name: Build wheel and source distributions
run: uv build
- name: Publish distribution π¦ to PyPI
run: uv publish