Skip to content

Commit 2f9f445

Browse files
authored
Merge pull request #246 from bgilbert/publish
workflows: automatically publish releases to PyPI and GitHub
2 parents d123249 + d8cfc7d commit 2f9f445

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

.github/ISSUE_TEMPLATE/release.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
- [ ] Update `CHANGELOG.md` and version in `openslide/_version.py`
44
- [ ] Create and push signed tag
5-
- [ ] `git clean -dxf && mkdir dist`
6-
- [ ] Find the [workflow run](https://github.com/openslide/openslide-python/actions/workflows/python.yml) for the tag; download its dist and docs artifacts
7-
- [ ] `unzip /path/to/downloaded/openslide-python-dist.zip && mv openslide-python-dist-*/* dist/`
8-
- [ ] `twine upload dist/*`
9-
- [ ] Recompress tarball with `xz`
10-
- [ ] Attach release notes to [GitHub release](https://github.com/openslide/openslide-python/releases/new); upload tarballs and wheels
5+
- [ ] Find the [workflow run](https://github.com/openslide/openslide-python/actions/workflows/python.yml) for the tag
6+
- [ ] Once the build finishes, approve deployment to PyPI
7+
- [ ] Download the docs artifact
8+
- [ ] Verify that the workflow created a [PyPI release](https://pypi.org/p/openslide-python) with a description, source tarball, and wheels
9+
- [ ] Verify that the workflow created a [GitHub release](https://github.com/openslide/openslide-python/releases) with release notes, a source tarball, and wheels
1110
- [ ] `cd` into website checkout; `rm -r api/python && unzip /path/to/downloaded/openslide-python-docs.zip && mv openslide-python-docs-* api/python`
1211
- [ ] Update website: `_data/releases.yaml`, `_includes/news.md`
1312
- [ ] Update Ubuntu PPA

.github/workflows/python.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,45 @@ jobs:
218218
with:
219219
name: ${{ needs.pre-commit.outputs.docs-base }}
220220
path: artifact
221+
222+
release:
223+
name: Release
224+
if: github.ref_type == 'tag'
225+
environment:
226+
name: pypi
227+
url: https://pypi.org/p/openslide-python
228+
needs: [pre-commit, tests, windows]
229+
runs-on: ubuntu-latest
230+
concurrency: release-${{ github.ref }}
231+
permissions:
232+
contents: write
233+
id-token: write
234+
steps:
235+
- name: Download artifacts
236+
uses: actions/download-artifact@v3
237+
with:
238+
name: ${{ needs.pre-commit.outputs.dist-base }}
239+
- name: Release to PyPI
240+
uses: pypa/gh-action-pypi-publish@release/v1
241+
with:
242+
packages-dir: ${{ needs.pre-commit.outputs.dist-base }}
243+
- name: Release to GitHub
244+
env:
245+
GITHUB_TOKEN: ${{ github.token }}
246+
run: |
247+
version=$(echo "${{ github.ref_name }}" | sed "s/^v//")
248+
# recompress tarball with xz
249+
gunzip -k "${{ needs.pre-commit.outputs.dist-base }}/openslide-python-${version}.tar.gz"
250+
tar xf "${{ needs.pre-commit.outputs.dist-base }}/openslide-python-${version}.tar"
251+
xz -9 "${{ needs.pre-commit.outputs.dist-base }}/openslide-python-${version}.tar"
252+
# extract changelog
253+
awk -e '/^## / && ok {exit}' \
254+
-e '/^## / {ok=1; next}' \
255+
-e 'ok {print}' \
256+
"openslide-python-$version/CHANGELOG.md" > changes
257+
gh release create --latest --verify-tag \
258+
--repo "${{ github.repository }}" \
259+
--title "OpenSlide Python $version" \
260+
--notes-file changes \
261+
"${{ github.ref_name }}" \
262+
"${{ needs.pre-commit.outputs.dist-base }}/"*

0 commit comments

Comments
 (0)