| 1 |
# Based on |
| 2 |
# https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ |
| 3 |
|
| 4 |
name: Test builds and publish Python distribution to PyPI |
| 5 |
|
| 6 |
on: |
| 7 |
release: |
| 8 |
types: [published] |
| 9 |
push: |
| 10 |
branches: [main] |
| 11 |
pull_request: |
| 12 |
|
| 13 |
permissions: |
| 14 |
contents: read |
| 15 |
|
| 16 |
concurrency: |
| 17 |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 18 |
cancel-in-progress: true |
| 19 |
|
| 20 |
jobs: |
| 21 |
build: |
| 22 |
name: Build distribution |
| 23 |
runs-on: ubuntu-latest |
| 24 |
|
| 25 |
steps: |
| 26 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 27 |
with: |
| 28 |
persist-credentials: false |
| 29 |
- name: Set up Python |
| 30 |
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 31 |
with: |
| 32 |
python-version: "3.x" |
| 33 |
- name: Check package metadata |
| 34 |
env: |
| 35 |
GITHUB_REF: ${{ github.ref }} |
| 36 |
run: python scripts/check_package.py "${GITHUB_REF}" |
| 37 |
- name: Install pypa/build |
| 38 |
run: | |
| 39 |
# Be wary of running `pip install` here, since it becomes easy for us to |
| 40 |
# accidentally pick up typing_extensions as installed by a dependency |
| 41 |
python -m pip install --upgrade build |
| 42 |
python -m pip list |
| 43 |
- name: Build a binary wheel and a source tarball |
| 44 |
run: python -m build |
| 45 |
- name: Store the distribution packages |
| 46 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 |
| 47 |
with: |
| 48 |
name: python-package-distributions |
| 49 |
path: dist/ |
| 50 |
|
| 51 |
test-wheel: |
| 52 |
name: Test wheel |
| 53 |
needs: |
| 54 |
- build |
| 55 |
runs-on: ubuntu-latest |
| 56 |
|
| 57 |
steps: |
| 58 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 59 |
with: |
| 60 |
persist-credentials: false |
| 61 |
- name: Set up Python |
| 62 |
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 63 |
with: |
| 64 |
python-version: "3.x" |
| 65 |
- name: Download all the dists |
| 66 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 |
| 67 |
with: |
| 68 |
name: python-package-distributions |
| 69 |
path: dist/ |
| 70 |
- name: Install wheel |
| 71 |
run: | |
| 72 |
path_to_file="$(find dist -type f -name "typing_extensions-*.whl")" |
| 73 |
export path_to_file |
| 74 |
echo "::notice::Installing wheel: $path_to_file" |
| 75 |
python -m pip install --user "$path_to_file" |
| 76 |
python -m pip list |
| 77 |
- name: Run typing_extensions tests against installed package |
| 78 |
run: rm src/typing_extensions.py && python src/test_typing_extensions.py |
| 79 |
|
| 80 |
test-sdist: |
| 81 |
name: Test source distribution |
| 82 |
needs: |
| 83 |
- build |
| 84 |
runs-on: ubuntu-latest |
| 85 |
|
| 86 |
steps: |
| 87 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 88 |
with: |
| 89 |
persist-credentials: false |
| 90 |
- name: Set up Python |
| 91 |
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 92 |
with: |
| 93 |
python-version: "3.x" |
| 94 |
- name: Download all the dists |
| 95 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 |
| 96 |
with: |
| 97 |
name: python-package-distributions |
| 98 |
path: dist/ |
| 99 |
- name: Unpack and test source distribution |
| 100 |
run: | |
| 101 |
path_to_file="$(find dist -type f -name "typing_extensions-*.tar.gz")" |
| 102 |
export path_to_file |
| 103 |
echo "::notice::Unpacking source distribution: $path_to_file" |
| 104 |
tar xzf "$path_to_file" -C dist/ |
| 105 |
cd "${path_to_file%.tar.gz}/src" |
| 106 |
python test_typing_extensions.py |
| 107 |
|
| 108 |
test-sdist-installed: |
| 109 |
name: Test installed source distribution |
| 110 |
needs: |
| 111 |
- build |
| 112 |
runs-on: ubuntu-latest |
| 113 |
|
| 114 |
steps: |
| 115 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 116 |
with: |
| 117 |
persist-credentials: false |
| 118 |
- name: Set up Python |
| 119 |
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 |
| 120 |
with: |
| 121 |
python-version: "3.x" |
| 122 |
- name: Download all the dists |
| 123 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 |
| 124 |
with: |
| 125 |
name: python-package-distributions |
| 126 |
path: dist/ |
| 127 |
- name: Install source distribution |
| 128 |
run: | |
| 129 |
path_to_file="$(find dist -type f -name "typing_extensions-*.tar.gz")" |
| 130 |
export path_to_file |
| 131 |
echo "::notice::Installing source distribution: $path_to_file" |
| 132 |
python -m pip install --user "$path_to_file" |
| 133 |
python -m pip list |
| 134 |
- name: Run typing_extensions tests against installed package |
| 135 |
run: rm src/typing_extensions.py && python src/test_typing_extensions.py |
| 136 |
|
| 137 |
publish-to-pypi: |
| 138 |
name: >- |
| 139 |
Publish Python distribution to PyPI |
| 140 |
if: github.event_name == 'release' # only publish to PyPI on releases |
| 141 |
needs: |
| 142 |
- test-sdist |
| 143 |
- test-sdist-installed |
| 144 |
- test-wheel |
| 145 |
- build |
| 146 |
runs-on: ubuntu-latest |
| 147 |
environment: |
| 148 |
name: publish |
| 149 |
url: https://pypi.org/p/typing-extensions |
| 150 |
permissions: |
| 151 |
id-token: write # IMPORTANT: mandatory for trusted publishing |
| 152 |
|
| 153 |
steps: |
| 154 |
- name: Download all the dists |
| 155 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 |
| 156 |
with: |
| 157 |
name: python-package-distributions |
| 158 |
path: dist/ |
| 159 |
- name: Ensure exactly one sdist and one wheel have been downloaded |
| 160 |
run: test "$(find dist/*.tar.gz | wc -l | xargs)" = 1 && test "$(find dist/*.whl | wc -l | xargs)" = 1 |
| 161 |
- name: Publish distribution to PyPI |
| 162 |
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b |