forked from bo4e/BO4E-python
-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (196 loc) Β· 7.84 KB
/
python-publish.yml
File metadata and controls
199 lines (196 loc) Β· 7.84 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
# 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@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run the Tests
run: |
tox -e tests
check_version_tag:
name: Check if the version tag is correct
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
pip install -r requirements.txt -r docs/requirements.txt
- name: Build JSON Schemas
run: tox -e generate_json_schemas
env:
TARGET_VERSION: ${{ github.ref_name }}
- name: Check version tag
run: |
# Get last version tag
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 -aq
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@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- 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
steps:
- uses: actions/checkout@v6
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: |
python -m pip install --upgrade pip
pip install tox
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: 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@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r dev_requirements/requirements-packaging.txt
- 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