Skip to content

Commit 057f51d

Browse files
committed
cleanup release workflows
1 parent f6f10a3 commit 057f51d

File tree

2 files changed

+310
-200
lines changed

2 files changed

+310
-200
lines changed

.github/workflows/release.yml

Lines changed: 45 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
name: Release
22
on:
3-
# workflow_call event lets this workflow be called from elsewhere
3+
# workflow_call trigger lets this workflow be called from elsewhere
44
workflow_call:
55
inputs:
6+
branch:
7+
description: Branch to release from.
8+
required: true
9+
type: string
610
cliff_config:
7-
description: Path to the git-cliff config ile, relative to the project root.
11+
description: Path of the git-cliff config file relative to the project root.
812
required: false
913
default: cliff.toml
1014
type: string
1115
cumulative_changelog:
12-
description: Path to the cumulative changelog file relative to the project root.
16+
description: Path of the cumulative changelog file relative to the project root.
1317
required: false
1418
default: HISTORY.md
1519
type: string
16-
draft_release:
17-
description: Draft a release post with assets and changelog.
18-
required: false
19-
default: false
20-
type: boolean
2120
package_name:
21+
# currently assumes module dir is in project root
2222
description: Name of the Python package to release (must be identical to the module name).
2323
required: true
2424
type: string
25-
publish_package:
26-
description: Publish the package to PyPI.
27-
required: false
28-
default: false
29-
type: boolean
3025
python_version:
31-
description: Python version to use to build and test the package.
26+
description: Python version to build the package with.
3227
required: true
3328
default: 3.8
3429
type: number
35-
reset_develop:
36-
description: Reset the develop branch from the trunk.
30+
run_tests:
31+
# currently assumes tests are in autotest/
32+
description: Run tests after building binaries.
3733
required: false
38-
default: false
3934
type: boolean
35+
default: true
4036
trunk_branch:
41-
description: Name of the trunk branch (either 'main' or 'master').
37+
description: Name of the trunk branch (e.g. 'main' or 'master').
4238
required: false
4339
default: main
4440
type: string
41+
version:
42+
description: Version number to use for release.
43+
required: true
44+
type: string
45+
4546
jobs:
4647
prep:
4748
name: Prepare release
@@ -76,11 +77,35 @@ jobs:
7677
run: |
7778
ref="${{ github.ref_name }}"
7879
version="${ref#"v"}"
80+
package="${{ inputs.package_name }}"
81+
# assume module name is the same as package
82+
# name with hyphens swapped for underscores
83+
module="${package//-/_}"
7984
python scripts/update_version.py -v "$version"
80-
black -v ${{ inputs.package_name }}/version.py
81-
python -c "import ${{ inputs.package_name }}; print('Version: ', ${{ inputs.package_name }}.__version__)"
85+
black -v $module/version.py
86+
python -c "import $module; print('Version: ', $module.__version__)"
8287
echo "version=$version" >> $GITHUB_OUTPUT
8388
89+
- name: Build package
90+
run: python -m build
91+
92+
- name: Check package
93+
run: twine check --strict dist/*
94+
95+
- name: Upload package
96+
uses: actions/upload-artifact@v3
97+
with:
98+
name: dist
99+
path: dist
100+
101+
- name: Run tests
102+
if: inputs.run_tests == true
103+
# todo make configurable
104+
working-directory: autotest
105+
run: pytest -v -n=auto --durations=0
106+
env:
107+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
84109
- name: Touch changelog
85110
run: touch HISTORY.md
86111

@@ -122,174 +147,3 @@ jobs:
122147
with:
123148
name: changelog
124149
path: ${{ steps.update-changelog.outputs.changelog }}
125-
126-
- name: Create release PR
127-
env:
128-
GITHUB_TOKEN: ${{ github.token }}
129-
run: |
130-
ver="${{ steps.version.outputs.version }}"
131-
changelog=$(cat ${{ steps.update-changelog.outputs.changelog }} | grep -v "### Version $ver")
132-
133-
# remove this release's changelog so we don't commit it
134-
# the changes have already been prepended to HISTORY.md
135-
rm ${{ steps.update-changelog.outputs.changelog }}
136-
rm -f CHANGELOG.md
137-
138-
# commit and push changes
139-
git config core.sharedRepository true
140-
git config user.name "github-actions[bot]"
141-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
142-
git add -A
143-
git commit -m "ci(release): version ${{ steps.version.outputs.version }}"
144-
git push origin "${{ github.ref_name }}"
145-
146-
title="Release $ver"
147-
body='
148-
# Release '$ver'
149-
150-
The release can be approved by merging this pull request into `${{ inputs.trunk_branch }}`. This will trigger jobs to publish the release to PyPI and reset `develop` from `${{ inputs.trunk_branch }}`.
151-
152-
## Changelog
153-
154-
'$changelog'
155-
'
156-
gh pr create -B "${{ inputs.trunk_branch }}" -H "${{ github.ref_name }}" --title "$title" --draft --body "$body"
157-
158-
release:
159-
name: Draft release
160-
# runs only when changes are merged to trunk
161-
if: github.event_name == 'push' && github.ref_name == inputs.trunk_branch && inputs.draft_release == true
162-
runs-on: ubuntu-22.04
163-
permissions:
164-
contents: write
165-
pull-requests: write
166-
steps:
167-
168-
- name: Checkout repo
169-
uses: actions/checkout@v3
170-
with:
171-
ref: ${{ inputs.trunk_branch }}
172-
173-
# actions/download-artifact won't look at previous workflow runs but we need to in order to get changelog
174-
- name: Download artifacts
175-
uses: dawidd6/action-download-artifact@v2
176-
177-
- name: Draft release
178-
env:
179-
GITHUB_TOKEN: ${{ github.token }}
180-
run: |
181-
version=$(cat version.txt)
182-
title="${{ inputs.package_name }} $version"
183-
notes=$(cat "changelog/CHANGELOG_$version.md" | grep -v "### Version $version")
184-
gh release create "$version" \
185-
--target ${{ inputs.trunk_branch }} \
186-
--title "$title" \
187-
--notes "$notes" \
188-
--draft \
189-
--latest
190-
191-
publish:
192-
name: Publish package
193-
# runs only after release is published (manually promoted from draft)
194-
if: github.event_name == 'release' && inputs.publish_package == true
195-
runs-on: ubuntu-22.04
196-
permissions:
197-
contents: write
198-
pull-requests: write
199-
id-token: write # mandatory for trusted publishing
200-
environment: # requires a 'pypi' environment in repo settings
201-
name: pypi
202-
url: https://pypi.org/p/${{ inputs.package_name }}
203-
steps:
204-
205-
- name: Checkout trunk
206-
uses: actions/checkout@v3
207-
with:
208-
ref: ${{ inputs.trunk_branch }}
209-
210-
- name: Setup Python
211-
uses: actions/setup-python@v4
212-
with:
213-
python-version: ${{ inputs.python_version }}
214-
215-
- name: Install Python dependencies
216-
run: |
217-
pip install --upgrade pip
218-
pip install build twine
219-
pip install .
220-
221-
- name: Build package
222-
run: python -m build
223-
224-
- name: Check package
225-
run: twine check --strict dist/*
226-
227-
- name: Publish package
228-
run: twine upload dist/*
229-
230-
reset:
231-
name: Draft reset PR
232-
if: github.event_name == 'release' && inputs.reset_develop == true
233-
runs-on: ubuntu-22.04
234-
permissions:
235-
contents: write
236-
pull-requests: write
237-
steps:
238-
239-
- name: Checkout trunk branch
240-
uses: actions/checkout@v3
241-
with:
242-
ref: ${{ inputs.trunk_branch }}
243-
244-
- name: Setup Python
245-
uses: actions/setup-python@v4
246-
with:
247-
python-version: ${{ inputs.python_version }}
248-
cache: 'pip'
249-
cache-dependency-path: pyproject.toml
250-
251-
- name: Install Python dependencies
252-
run: |
253-
pip install --upgrade pip
254-
pip install black filelock
255-
256-
- name: Get release tag
257-
uses: oprypin/find-latest-tag@v1
258-
id: latest_tag
259-
with:
260-
repository: ${{ github.repository }}
261-
releases-only: true
262-
263-
- name: Draft pull request
264-
env:
265-
GITHUB_TOKEN: ${{ github.token }}
266-
run: |
267-
# create reset branch from trunk
268-
reset_branch="post-release-${{ steps.latest_tag.outputs.tag }}-reset"
269-
git switch -c $reset_branch
270-
271-
# increment patch version
272-
major_version=$(echo "${{ steps.latest_tag.outputs.tag }}" | cut -d. -f1)
273-
minor_version=$(echo "${{ steps.latest_tag.outputs.tag }}" | cut -d. -f2)
274-
patch_version=$(echo "${{ steps.latest_tag.outputs.tag }}" | cut -d. -f3)
275-
version="$major_version.$minor_version.$((patch_version + 1))"
276-
277-
# update version (add + to version.txt to indicate development status)
278-
python scripts/update_version.py -v "$version"
279-
black -v ${{ inputs.package_name}}/version.py
280-
281-
# commit and push reset branch
282-
git config core.sharedRepository true
283-
git config user.name "github-actions[bot]"
284-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
285-
git add -A
286-
git commit -m "ci(post-release): update develop from ${{ inputs.trunk_branch }}"
287-
git push -u origin $reset_branch
288-
289-
# create PR into develop
290-
body='
291-
# Reinitialize for development
292-
293-
Updates the `develop` branch from `${{ inputs.trunk_branch }}` following a successful release.
294-
'
295-
gh pr create -B "develop" -H "$reset_branch" --title "Reinitialize develop branch" --draft --body "$body"

0 commit comments

Comments
 (0)