1
- # #
2
- # Derived from:
3
- # https://github.com/django-commons/django-commons-playground/blob/main/.github/workflows/release.yml
4
- #
5
1
6
2
name : Publish Release
7
3
8
4
permissions : read-all
9
5
6
+ concurrency :
7
+ # stop previous release runs if tag is recreated
8
+ group : release-${{ github.ref }}
9
+ cancel-in-progress : true
10
+
10
11
on :
11
12
push :
12
13
tags :
13
14
- ' v*' # only publish on version tags (e.g. v1.0.0)
14
- workflow_dispatch :
15
- inputs :
16
- pypi :
17
- description : ' Publish to PyPi'
18
- required : true
19
- default : false
20
- type : boolean
21
- github :
22
- description : ' Publish a GitHub Release'
23
- required : true
24
- default : false
25
- type : boolean
26
- testpypi :
27
- description : ' Publish to TestPyPi'
28
- required : true
29
- default : true
30
- type : boolean
31
-
32
- env :
33
- PYPI_URL : https://pypi.org/p/django-typer
34
- PYPI_TEST_URL : https://test.pypi.org/project/django-typer
35
15
36
16
jobs :
37
17
18
+ lint :
19
+ permissions :
20
+ contents : read
21
+ actions : write
22
+ uses : ./.github/workflows/lint.yml
23
+ secrets : inherit
24
+
25
+ test :
26
+ permissions :
27
+ contents : read
28
+ actions : write
29
+ uses : ./.github/workflows/test.yml
30
+ secrets : inherit
31
+
38
32
build :
39
33
name : Build Package
40
34
runs-on : ubuntu-latest
41
35
permissions :
36
+ contents : read
42
37
actions : write
43
-
38
+ outputs :
39
+ PACKAGE_NAME : ${{ steps.set-package.outputs.package_name }}
40
+ RELEASE_VERSION : ${{ steps.set-package.outputs.release_version }}
44
41
steps :
45
42
- uses : actions/checkout@v4
46
43
- name : Set up Python
47
44
uses : actions/setup-python@v5
48
45
with :
49
- python-version : " 3.x"
50
- - name : Install pypa/build
51
- run :
52
- python3 -m pip install build --user
53
- - name : Build a binary wheel and a source tarball
54
- run : python3 -m build
46
+ python-version : " >=3.11" # for tomlib
47
+ - name : Install uv
48
+ uses : astral-sh/setup-uv@v5
49
+ with :
50
+ enable-cache : true
51
+ - name : Setup Just
52
+ uses : extractions/setup-just@v2
53
+ - name : Verify Tag
54
+ run : |
55
+ TAG_NAME=${GITHUB_REF#refs/tags/}
56
+ echo "Verifying tag $TAG_NAME..."
57
+ # if a tag was deleted and recreated we may have the old one cached
58
+ # be sure that we're publishing the current tag!
59
+ git fetch --force origin refs/tags/$TAG_NAME:refs/tags/$TAG_NAME
60
+
61
+ # verify signature
62
+ curl -sL https://github.com/${{ github.actor }}.gpg | gpg --import
63
+ git tag -v "$TAG_NAME"
64
+
65
+ # verify version
66
+ RELEASE_VERSION=$(just validate_version $TAG_NAME)
67
+
68
+ # export the release version
69
+ echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
70
+ - name : Build the binary wheel and a source tarball
71
+ run : just build
55
72
- name : Store the distribution packages
56
73
uses : actions/upload-artifact@v4
57
74
with :
58
75
name : python-package-distributions
59
76
path : dist/
77
+ - name : Set Package Name
78
+ id : set-package
79
+ run :
80
+ PACKAGE_NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])")
81
+ echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV
60
82
61
83
publish-to-pypi :
62
84
name : Publish to PyPI
63
- if : ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.pypi == 'true') || github.event_name != 'workflow_dispatch' }}
64
85
needs :
65
- - build
86
+ - lint
87
+ - test
88
+ - build
89
+ - publish-to-testpypi
66
90
runs-on : ubuntu-latest
67
91
environment :
68
92
name : pypi
69
- url : ${{ env.PYPI_URL }}
93
+ url : https://pypi.org/p/ ${{ needs.build.outputs.PACKAGE_NAME }}
70
94
permissions :
71
95
id-token : write # IMPORTANT: mandatory for trusted publishing
72
96
steps :
@@ -80,10 +104,11 @@ jobs:
80
104
81
105
github-release :
82
106
name : Publish GitHub Release
83
- if : ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.github == 'true') || github.event_name != 'workflow_dispatch' }}
84
107
runs-on : ubuntu-latest
85
108
needs :
86
- - build
109
+ - lint
110
+ - test
111
+ - build
87
112
permissions :
88
113
contents : write # IMPORTANT: mandatory for making GitHub Releases
89
114
id-token : write # IMPORTANT: mandatory for sigstore
@@ -121,14 +146,13 @@ jobs:
121
146
122
147
publish-to-testpypi :
123
148
name : Publish to TestPyPI
124
- if : ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.testpypi == 'true') || github.event_name != 'workflow_dispatch' }}
125
149
needs :
126
150
- build
127
151
runs-on : ubuntu-latest
128
152
129
153
environment :
130
154
name : testpypi
131
- url : ${{ env.PYPI_TEST_URL }}
155
+ url : https://test.pypi.org/project/ ${{ needs.build.outputs.PACKAGE_NAME }}
132
156
133
157
permissions :
134
158
id-token : write # IMPORTANT: mandatory for trusted publishing
@@ -144,14 +168,3 @@ jobs:
144
168
with :
145
169
repository-url : https://test.pypi.org/legacy/
146
170
skip-existing : true
147
-
148
- # TODO fetch-data requires login
149
- # notify-django-packages:
150
- # name: Notify Django Packages
151
- # runs-on: ubuntu-latest
152
- # needs:
153
- # - publish-to-pypi
154
- # steps:
155
- # - name: Notify Django Packages
156
- # run:
157
- # curl -X GET "https://djangopackages.org/packages/django-typer/fetch-data/"
0 commit comments