Debian Codegraph @

.github/workflows/release.yml

raw
1 name: Publish Release
2
3 permissions:
4 contents: read
5
6 concurrency:
7 # stop previous release runs if tag is recreated
8 group: release-${{ github.ref }}
9 cancel-in-progress: true
10
11 on:
12 push:
13 tags:
14 - "v[0-9]*.[0-9]*.[0-9]*" # only publish on version tags (e.g. v1.0.0)
15
16 jobs:
17 lint:
18 permissions:
19 contents: read
20 uses: ./.github/workflows/lint.yml
21
22 test:
23 permissions:
24 contents: read
25 id-token: write # to allow codecov oidc upload
26 uses: ./.github/workflows/test.yml
27
28 build:
29 name: Build Package
30 runs-on: ubuntu-latest
31 permissions:
32 contents: read
33 outputs:
34 PACKAGE_NAME: ${{ steps.set-package.outputs.package_name }}
35 RELEASE_VERSION: ${{ steps.set-package.outputs.release_version }}
36 steps:
37 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
38 with:
39 persist-credentials: false
40 - name: Set up Python
41 uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1
42 with:
43 python-version: "3.14" # for tomlib
44 - name: Install uv
45 uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39
46 with:
47 enable-cache: false
48 restore-cache: false
49 save-cache: false
50 - name: Setup Just
51 uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3
52 - name: Verify Tag
53 run: |
54 TAG_NAME=${GITHUB_REF#refs/tags/}
55 echo "Verifying tag $TAG_NAME..."
56 # if a tag was deleted and recreated we may have the old one cached
57 # be sure that we're publishing the current tag!
58 git fetch --force origin refs/tags/$TAG_NAME:refs/tags/$TAG_NAME
59
60 # verify signature
61 curl -sL "https://github.com/${GITHUB_ACTOR}.gpg" | gpg --import
62 git tag -v "$TAG_NAME"
63
64 # verify version
65 RELEASE_VERSION=$(just validate_version $TAG_NAME)
66
67 # export the release version
68 echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
69 - name: Install gettext
70 run: sudo apt-get install -y gettext
71 - name: Build the binary wheel and a source tarball
72 run: just build
73 - name: Store the distribution packages
74 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
75 with:
76 name: python-package-distributions
77 path: dist/
78 - name: Set Package Name
79 id: set-package
80 run:
81 PACKAGE_NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])")
82 echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV
83
84 publish-to-pypi:
85 name: Publish to PyPI
86 needs:
87 - lint
88 - test
89 - build
90 runs-on: ubuntu-latest
91 environment:
92 name: pypi
93 url: https://pypi.org/p/${{ needs.build.outputs.PACKAGE_NAME }}
94 permissions:
95 id-token: write # IMPORTANT: mandatory for trusted publishing
96 steps:
97 - name: Download all the dists
98 uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
99 with:
100 name: python-package-distributions
101 path: dist/
102 - name: Publish distribution 📦 to PyPI
103 uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b
104
105 github-release:
106 name: Publish GitHub Release
107 runs-on: ubuntu-latest
108 needs:
109 - lint
110 - test
111 - build
112 permissions:
113 contents: write # IMPORTANT: mandatory for making GitHub Releases
114 id-token: write # IMPORTANT: mandatory for sigstore
115
116 steps:
117 - name: Download all the dists
118 uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
119 with:
120 name: python-package-distributions
121 path: dist/
122 - name: Sign the dists with Sigstore
123 uses: sigstore/gh-action-sigstore-python@5b79a39c381910c090341a2c9b0bf022c8b387e1
124 with:
125 inputs: >-
126 ./dist/*.tar.gz
127 ./dist/*.whl
128 - name: Create GitHub Release
129 env:
130 GITHUB_TOKEN: ${{ github.token }}
131 GITHUB_REF_NAME: ${{ github.ref_name }}
132 GITHUB_REPOSITORY: ${{ github.repository }}
133 run: >-
134 gh release create
135 "$GITHUB_REF_NAME"
136 --repo "$GITHUB_REPOSITORY"
137 --generate-notes
138 - name: Upload artifact signatures to GitHub Release
139 env:
140 GITHUB_TOKEN: ${{ github.token }}
141 GITHUB_REF_NAME: ${{ github.ref_name }}
142 GITHUB_REPOSITORY: ${{ github.repository }}
143 # Upload to GitHub Release using the `gh` CLI.
144 # `dist/` contains the built packages, and the
145 # sigstore-produced signatures and certificates.
146 run: >-
147 gh release upload
148 "$GITHUB_REF_NAME" dist/**
149 --repo "$GITHUB_REPOSITORY"
150
151 # chrisglass owns this: https://test.pypi.org/project/django-polymorphic/
152 # publish-to-testpypi:
153 # name: Publish to TestPyPI
154 # needs:
155 # - build
156 # runs-on: ubuntu-latest
157
158 # environment:
159 # name: testpypi
160 # url: https://test.pypi.org/project/${{ needs.build.outputs.PACKAGE_NAME }}
161
162 # permissions:
163 # id-token: write # IMPORTANT: mandatory for trusted publishing
164
165 # steps:
166 # - name: Download all the dists
167 # uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
168 # with:
169 # name: python-package-distributions
170 # path: dist/
171 # - name: Publish distribution 📦 to TestPyPI
172 # uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b
173 # with:
174 # repository-url: https://test.pypi.org/legacy/
175 # skip-existing: true