| 1 |
name: Publish to PyPI |
| 2 |
on: push |
| 3 |
permissions: |
| 4 |
contents: read |
| 5 |
|
| 6 |
jobs: |
| 7 |
|
| 8 |
build: |
| 9 |
name: Build distribution |
| 10 |
runs-on: ubuntu-latest |
| 11 |
|
| 12 |
steps: |
| 13 |
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 14 |
- name: Set up Python |
| 15 |
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 16 |
with: |
| 17 |
python-version: "3.x" |
| 18 |
- name: Install build tools |
| 19 |
run: python -m pip install build twine |
| 20 |
- name: Check the tag matches the package version |
| 21 |
if: startsWith(github.ref, 'refs/tags/') |
| 22 |
run: | |
| 23 |
version="$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' idna/package_data.py)" |
| 24 |
if [ "$GITHUB_REF_NAME" != "v$version" ]; then |
| 25 |
echo "::error::Tag $GITHUB_REF_NAME does not match idna.__version__ $version" >&2 |
| 26 |
exit 1 |
| 27 |
fi |
| 28 |
- name: Build a binary wheel and a source tarball |
| 29 |
run: python -m build |
| 30 |
- name: Check the distributions |
| 31 |
run: twine check --strict dist/* |
| 32 |
- name: Install test dependencies |
| 33 |
run: python -m pip install --require-hashes -r .github/requirements/test.txt |
| 34 |
- name: Install the wheel and run the test suite against it |
| 35 |
# Run from outside the checkout with --import-mode=importlib so that |
| 36 |
# ``import idna`` resolves to the installed wheel, not the source tree: |
| 37 |
# only an artifact that passes the suite gets published. |
| 38 |
# --force-reinstall because twine (via requests) has already pulled |
| 39 |
# the released idna from PyPI, and pip would otherwise skip our wheel |
| 40 |
# as "already installed" whenever the version numbers coincide. |
| 41 |
run: | |
| 42 |
python -m pip install --no-deps --force-reinstall dist/*.whl |
| 43 |
cd "$RUNNER_TEMP" |
| 44 |
python -c 'import idna, sys; assert "site-packages" in idna.__file__, idna.__file__; print(idna.__version__, idna.__file__)' |
| 45 |
pytest -q --import-mode=importlib -p no:cacheprovider "$GITHUB_WORKSPACE/tests" |
| 46 |
- name: Store the distribution packages |
| 47 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 48 |
with: |
| 49 |
name: python-package-distributions |
| 50 |
path: dist/ |
| 51 |
|
| 52 |
publish-to-pypi: |
| 53 |
name: Publish to PyPI |
| 54 |
if: startsWith(github.ref, 'refs/tags/v') # only publish to PyPI on version tag pushes |
| 55 |
needs: |
| 56 |
- build |
| 57 |
runs-on: ubuntu-latest |
| 58 |
environment: |
| 59 |
name: pypi |
| 60 |
url: https://pypi.org/p/idna |
| 61 |
permissions: |
| 62 |
id-token: write # IMPORTANT: mandatory for trusted publishing |
| 63 |
|
| 64 |
steps: |
| 65 |
- name: Download all the dists |
| 66 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 67 |
with: |
| 68 |
name: python-package-distributions |
| 69 |
path: dist/ |
| 70 |
- name: Publish distribution to PyPI |
| 71 |
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 |
| 72 |
|
| 73 |
github-release: |
| 74 |
name: Sign and upload GitHub Release |
| 75 |
needs: |
| 76 |
- publish-to-pypi |
| 77 |
runs-on: ubuntu-latest |
| 78 |
|
| 79 |
permissions: |
| 80 |
contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 81 |
id-token: write # IMPORTANT: mandatory for sigstore |
| 82 |
|
| 83 |
steps: |
| 84 |
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 85 |
- name: Download the dists |
| 86 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 87 |
with: |
| 88 |
name: python-package-distributions |
| 89 |
path: dist/ |
| 90 |
- name: Sign with Sigstore |
| 91 |
uses: sigstore/gh-action-sigstore-python@04cffa1d795717b140764e8b640de88853c92acc # v3.3.0 |
| 92 |
with: |
| 93 |
inputs: >- |
| 94 |
./dist/*.tar.gz |
| 95 |
./dist/*.whl |
| 96 |
- name: Extract release notes from HISTORY.md |
| 97 |
# The section headed "## <version> (<date>)" for the tagged version, |
| 98 |
# without its heading. A release without a HISTORY entry is an error. |
| 99 |
run: | |
| 100 |
version="${GITHUB_REF_NAME#v}" |
| 101 |
awk -v v="$version" '/^## /{p = ($2 == v)} p' HISTORY.md | tail -n +2 | sed '/./,$!d' > "$RUNNER_TEMP/release-notes.md" |
| 102 |
if [ ! -s "$RUNNER_TEMP/release-notes.md" ]; then |
| 103 |
echo "::error::No HISTORY.md section found for version $version" >&2 |
| 104 |
exit 1 |
| 105 |
fi |
| 106 |
cat "$RUNNER_TEMP/release-notes.md" |
| 107 |
- name: Create GitHub Release |
| 108 |
env: |
| 109 |
GITHUB_TOKEN: ${{ github.token }} |
| 110 |
run: >- |
| 111 |
gh release create |
| 112 |
'${{ github.ref_name }}' |
| 113 |
--repo '${{ github.repository }}' |
| 114 |
--verify-tag |
| 115 |
--notes-file "$RUNNER_TEMP/release-notes.md" |
| 116 |
- name: Upload artifact signatures to GitHub Release |
| 117 |
env: |
| 118 |
GITHUB_TOKEN: ${{ github.token }} |
| 119 |
# Upload to GitHub Release using the `gh` CLI. |
| 120 |
# `dist/` contains the built packages, and the |
| 121 |
# sigstore-produced signatures and certificates. |
| 122 |
run: >- |
| 123 |
gh release upload |
| 124 |
'${{ github.ref_name }}' dist/** |
| 125 |
--repo '${{ github.repository }}' |
| 126 |
|
| 127 |
publish-to-testpypi: |
| 128 |
name: Publish to Test PyPI |
| 129 |
# Only master, release branches (where the rcN pre-release commit lands |
| 130 |
# before tagging) and version tags reach TestPyPI; topic and Dependabot |
| 131 |
# branches still build and test but do not publish. |
| 132 |
if: >- |
| 133 |
github.ref == 'refs/heads/master' || |
| 134 |
startsWith(github.ref, 'refs/heads/release-') || |
| 135 |
startsWith(github.ref, 'refs/tags/v') |
| 136 |
needs: |
| 137 |
- build |
| 138 |
runs-on: ubuntu-latest |
| 139 |
|
| 140 |
environment: |
| 141 |
name: testpypi |
| 142 |
url: https://test.pypi.org/p/idna |
| 143 |
|
| 144 |
permissions: |
| 145 |
id-token: write # IMPORTANT: mandatory for trusted publishing |
| 146 |
|
| 147 |
steps: |
| 148 |
- name: Download all the dists |
| 149 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 150 |
with: |
| 151 |
name: python-package-distributions |
| 152 |
path: dist/ |
| 153 |
- name: Publish distribution to TestPyPI |
| 154 |
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 |
| 155 |
with: |
| 156 |
verbose: true |
| 157 |
print-hash: true |
| 158 |
repository-url: https://test.pypi.org/legacy/ |
| 159 |
skip-existing: true |