3838 run : python -m django test tests --settings=tests.test_settings --verbosity=1
3939
4040 - name : Build package
41- run : python -m build
41+ run : python -m build --sdist --wheel
42+
43+ - name : Ensure wheel and source distribution exist
44+ run : |
45+ shopt -s nullglob
46+ wheel_files=(dist/*.whl)
47+ sdist_files=(dist/*.tar.gz)
48+
49+ if [ ${#wheel_files[@]} -eq 0 ]; then
50+ echo "Wheel artifact is missing from dist/." >&2
51+ exit 1
52+ fi
53+
54+ if [ ${#sdist_files[@]} -eq 0 ]; then
55+ echo "Source distribution artifact is missing from dist/." >&2
56+ exit 1
57+ fi
58+
59+ printf 'Wheel artifacts:\n'
60+ printf '%s\n' "${wheel_files[@]}"
61+ printf 'Source distribution artifacts:\n'
62+ printf '%s\n' "${sdist_files[@]}"
4263
4364 - name : Validate package metadata
4465 run : python -m twine check dist/*
5879 environment : pypi
5980
6081 permissions :
61- contents : read
82+ contents : write
6283 id-token : write
6384
6485 steps :
@@ -70,11 +91,21 @@ jobs:
7091 with :
7192 python-version : " 3.12"
7293
94+ - name : Install metadata tooling
95+ run : python -m pip install --upgrade setuptools
96+
7397 - name : Read package metadata
7498 id : package
7599 run : |
76- echo "name=$(python setup.py --name)" >> "$GITHUB_OUTPUT"
77- echo "version=$(python setup.py --version)" >> "$GITHUB_OUTPUT"
100+ package_name="$(python setup.py --name)"
101+ package_version="$(python setup.py --version)"
102+ if [ -z "$package_name" ] || [ -z "$package_version" ]; then
103+ echo "Could not read package name/version from setup.py" >&2
104+ exit 1
105+ fi
106+ echo "name=$package_name" >> "$GITHUB_OUTPUT"
107+ echo "version=$package_version" >> "$GITHUB_OUTPUT"
108+ echo "Package: $package_name $package_version"
78109
79110 - name : Ensure version is not already on PyPI
80111 env :
@@ -89,7 +120,10 @@ jobs:
89120
90121 package_name = os.environ["PACKAGE_NAME"].replace("_", "-")
91122 package_version = os.environ["PACKAGE_VERSION"]
123+ if not package_name or not package_version:
124+ raise SystemExit("PACKAGE_NAME and PACKAGE_VERSION must not be empty.")
92125 url = f"https://pypi.org/pypi/{package_name}/{package_version}/json"
126+ print(f"Checking {url}")
93127
94128 try:
95129 urllib.request.urlopen(url, timeout=15)
@@ -111,5 +145,37 @@ jobs:
111145 name : package-dist
112146 path : dist
113147
148+ - name : Ensure downloaded wheel and source distribution exist
149+ run : |
150+ shopt -s nullglob
151+ wheel_files=(dist/*.whl)
152+ sdist_files=(dist/*.tar.gz)
153+
154+ if [ ${#wheel_files[@]} -eq 0 ]; then
155+ echo "Wheel artifact is missing from downloaded dist/." >&2
156+ exit 1
157+ fi
158+
159+ if [ ${#sdist_files[@]} -eq 0 ]; then
160+ echo "Source distribution artifact is missing from downloaded dist/." >&2
161+ exit 1
162+ fi
163+
164+ printf 'Publishing wheel artifacts:\n'
165+ printf '%s\n' "${wheel_files[@]}"
166+ printf 'Publishing source distribution artifacts:\n'
167+ printf '%s\n' "${sdist_files[@]}"
168+
114169 - name : Publish package distributions to PyPI
115170 uses : pypa/gh-action-pypi-publish@release/v1
171+
172+ - name : Create GitHub release
173+ env :
174+ GH_TOKEN : ${{ github.token }}
175+ PACKAGE_NAME : ${{ steps.package.outputs.name }}
176+ PACKAGE_VERSION : ${{ steps.package.outputs.version }}
177+ run : |
178+ gh release create "$PACKAGE_VERSION" dist/* \
179+ --target "$GITHUB_SHA" \
180+ --title "$PACKAGE_NAME $PACKAGE_VERSION" \
181+ --generate-notes
0 commit comments