Skip to content

Commit b27031b

Browse files
committed
Update release pipeline
1 parent e82af66 commit b27031b

1 file changed

Lines changed: 56 additions & 46 deletions

File tree

.github/workflows/on-release.yml

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,92 @@
55
name: Build and publish
66

77
on:
8-
workflow_dispatch: {} # allows triggering this workflow manually
8+
workflow_dispatch: {}
99
push:
10-
branches: # trigger on commits to main branch
10+
branches:
1111
- main
12-
pull_request: # trigger on pull requests affecting relevant files
12+
pull_request:
1313
branches:
1414
- main
1515
paths:
16-
- '**workflows/on-release.yml'
16+
- '.github/workflows/on-release.yml'
1717
- 'pyproject.toml'
18-
release: # trigger on published release
18+
release:
1919
types:
2020
- published
2121

22+
permissions:
23+
contents: read
24+
2225
jobs:
23-
build-sdist:
24-
name: Build source distribution
25-
runs-on: ubuntu-latest
26+
build-dist:
27+
name: Build distributions
28+
runs-on: 'ubuntu-24.04'
2629
steps:
27-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # ratchet:actions/checkout@v4
30+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2831
with:
32+
ref: ${{ github.event.release.tag_name || github.ref }}
2933
submodules: true
3034

31-
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # ratchet:actions/setup-python@v5
35+
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
3236
with:
33-
python-version: '3.10'
37+
cache: 'pip'
38+
python-version: 3.12
3439

3540
- name: Install build tools
36-
run: python -m pip install build
41+
run: python -m pip install build twine
3742

38-
- name: Build sdist
39-
run: python -m build -s
43+
- name: Build distributions
44+
run: python -m build -s -w
4045

41-
- uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # ratchet: actions/upload-artifact@v4
42-
with:
43-
name: sdist
44-
path: dist/*.tar.gz
46+
- name: Check distributions
47+
run: python -m twine check dist/*
4548

46-
build-wheels:
47-
name: Build wheel distribution
48-
runs-on: ubuntu-latest
49-
steps:
50-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # ratchet:actions/checkout@v4
49+
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
5150
with:
52-
submodules: true
51+
name: dist
52+
path: dist/
5353

54-
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # ratchet:actions/setup-python@v5
54+
upload-github-release-assets:
55+
name: Upload GitHub Release assets
56+
needs:
57+
- build-dist
58+
runs-on: 'ubuntu-24.04'
59+
if: github.event_name == 'release' && github.event.action == 'published'
60+
permissions:
61+
contents: write
62+
steps:
63+
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4
5564
with:
56-
python-version: '3.10'
57-
58-
- name: Install build tools
59-
run: python -m pip install build
60-
61-
- name: Build wheel
62-
run: python -m build -w
65+
name: dist
66+
path: dist
6367

64-
- uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # ratchet: actions/upload-artifact@v4
65-
with:
66-
name: wheel
67-
path: dist/*.whl
68+
- name: Upload distributions to GitHub Release
69+
env:
70+
GH_TOKEN: ${{ github.token }}
71+
TAG_NAME: ${{ github.event.release.tag_name }}
72+
run: |
73+
gh release upload "$TAG_NAME" dist/* \
74+
--repo "$GITHUB_REPOSITORY" \
75+
--clobber
6876
6977
upload-pypi:
70-
name: Release and upload to PyPI
78+
name: Publish distributions to PyPI
7179
needs:
72-
- build-sdist
73-
- build-wheels
74-
runs-on: ubuntu-latest
75-
# Only publish release to PyPI when a github release is created.
80+
- build-dist
81+
- upload-github-release-assets
82+
runs-on: 'ubuntu-24.04'
7683
if: github.event_name == 'release' && github.event.action == 'published'
84+
environment:
85+
name: pypi
86+
url: https://pypi.org/p/mpl-typst
87+
permissions:
88+
id-token: write
7789
steps:
7890
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4
7991
with:
80-
# Unpacks sdist and wheel builds to dist/ directory.
92+
name: dist
8193
path: dist
82-
merge-multiple: true
8394

84-
- uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # ratchet:pypa/gh-action-pypi-publish@v1.12.4
85-
with:
86-
password: ${{ secrets.PYPI_API_TOKEN }}
95+
- name: Publish distributions to PyPI
96+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # ratchet:pypa/gh-action-pypi-publish@v1.12.4

0 commit comments

Comments
 (0)