-
Notifications
You must be signed in to change notification settings - Fork 5
211 lines (208 loc) Β· 8.48 KB
/
Copy pathpython-publish.yml
File metadata and controls
211 lines (208 loc) Β· 8.48 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
# 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: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: pip install tox tox-uv
- name: Run the Tests
run: |
tox -e tests
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 }}
steps:
- name: Check out Git repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install dependencies for schema generation
run: |
pip install uv
uv pip install --system -e . --group json_schemas
- name: Build JSON Schemas
run: python generate_or_validate_json_schemas.py --mode generate
env:
TARGET_VERSION: ${{ github.ref_name }}
- 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:
name: Generate JSON-Schemas
runs-on: ubuntu-latest
needs: [tests, check_version_tag]
concurrency: build-n-publish-json-schemas
steps:
- name: Check out Git repository
uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install tox
run: pip install tox tox-uv
- name: Build JSON Schemas
run: |
tox -e generate_json_schemas
# Remove .version file as we don't want to commit it to BO4E-Schemas
rm json_schemas/.version
env:
TARGET_VERSION: ${{ github.ref_name }}
- 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: |
pip install 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 }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install dependencies
run: |
pip install tox tox-uv
pip install -r requirements.txt
# Note: The sphinx action below can only install a single requirements file.
- name: Build JSON Schemas
run: tox -e generate_json_schemas
env:
TARGET_VERSION: ${{ github.ref_name }}
- name: Build BO4E package
# Note: This step necessary to correctly set the version in the JSON-Schema-links
run: |
pip install -e .
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: 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, docs]
concurrency: build-n-publish-distributions
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10.x"
- name: Install dependencies
run: |
pip install uv
uv pip install --system --group packaging
- name: Build wheel and source distributions
run: python -m build
- name: Publish distribution π¦ to PyPI
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1