|
5 | 5 | name: Build and publish |
6 | 6 |
|
7 | 7 | on: |
8 | | - workflow_dispatch: {} # allows triggering this workflow manually |
| 8 | + workflow_dispatch: {} |
9 | 9 | push: |
10 | | - branches: # trigger on commits to main branch |
| 10 | + branches: |
11 | 11 | - main |
12 | | - pull_request: # trigger on pull requests affecting relevant files |
| 12 | + pull_request: |
13 | 13 | branches: |
14 | 14 | - main |
15 | 15 | paths: |
16 | | - - '**workflows/on-release.yml' |
| 16 | + - '.github/workflows/on-release.yml' |
17 | 17 | - 'pyproject.toml' |
18 | | - release: # trigger on published release |
| 18 | + release: |
19 | 19 | types: |
20 | 20 | - published |
21 | 21 |
|
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + |
22 | 25 | 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' |
26 | 29 | steps: |
27 | | - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # ratchet:actions/checkout@v4 |
| 30 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
28 | 31 | with: |
| 32 | + ref: ${{ github.event.release.tag_name || github.ref }} |
29 | 33 | submodules: true |
30 | 34 |
|
31 | | - - uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # ratchet:actions/setup-python@v5 |
| 35 | + - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 |
32 | 36 | with: |
33 | | - python-version: '3.10' |
| 37 | + cache: 'pip' |
| 38 | + python-version: 3.12 |
34 | 39 |
|
35 | 40 | - name: Install build tools |
36 | | - run: python -m pip install build |
| 41 | + run: python -m pip install build twine |
37 | 42 |
|
38 | | - - name: Build sdist |
39 | | - run: python -m build -s |
| 43 | + - name: Build distributions |
| 44 | + run: python -m build -s -w |
40 | 45 |
|
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/* |
45 | 48 |
|
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 |
51 | 50 | with: |
52 | | - submodules: true |
| 51 | + name: dist |
| 52 | + path: dist/ |
53 | 53 |
|
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 |
55 | 64 | 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 |
63 | 67 |
|
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 |
68 | 76 |
|
69 | 77 | upload-pypi: |
70 | | - name: Release and upload to PyPI |
| 78 | + name: Publish distributions to PyPI |
71 | 79 | 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' |
76 | 83 | 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 |
77 | 89 | steps: |
78 | 90 | - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4 |
79 | 91 | with: |
80 | | - # Unpacks sdist and wheel builds to dist/ directory. |
| 92 | + name: dist |
81 | 93 | path: dist |
82 | | - merge-multiple: true |
83 | 94 |
|
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