From 6d9f14ed89fff3568dbba060d207428f5bb0e31c Mon Sep 17 00:00:00 2001 From: Kim Davies Date: Fri, 2 Aug 2024 19:43:27 -0700 Subject: [PATCH 1/7] Use latest reference code for CI/CD to PyPI using Github Actions --- .github/workflows/deploy.yml | 129 ++++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 25 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ee59e0b..42d9f76 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,35 +1,114 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions +# Adapted from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ -name: "Publish to PyPI" +name: Publish to PyPI +on: push +jobs: -on: - push: - tags: - - "*" + build: + name: Build distribution + runs-on: ubuntu-latest -permissions: - contents: "read" + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install pypa/build + run: python3 -m pip install build --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ -jobs: - publish: - name: "Publish to PyPI" - runs-on: "ubuntu-latest" + publish-to-pypi: + name: >- + Publish Python distribution to PyPI + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + needs: + - build + runs-on: ubuntu-latest environment: - name: "publish" + name: pypi + url: https://pypi.org/p/idna # Replace with your PyPI project name + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: - - name: "Checkout repository" - uses: "actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b" + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + name: >- + Sign the Python distribution with Sigstore + and upload them to GitHub Release + needs: + - publish-to-pypi + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore - - name: "Setup Python" - uses: "actions/setup-python@b55428b1882923874294fa556849718a1d7f2ca5" + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 with: - python-version: "3.x" + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + '${{ github.ref_name }}' + --repo '${{ github.repository }}' + --notes "" + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' - - name: "Build dists" - run: | - python -m pip install build - python -m build + publish-to-testpypi: + name: Publish Python distribution to TestPyPI + needs: + - build + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/idna-preflight - - name: "Publish to PyPI" - uses: "pypa/gh-action-pypi-publish@37f50c210e3d2f9450da2cd423303d6a14a6e29f" + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ \ No newline at end of file From e98f6b8e70942760e116137d41bd1329e913092c Mon Sep 17 00:00:00 2001 From: Kim Davies Date: Fri, 2 Aug 2024 20:01:34 -0700 Subject: [PATCH 2/7] Verbose reporting on Test PyPI upload --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 42d9f76..d0a5e64 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -111,4 +111,6 @@ jobs: - name: Publish distribution to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 with: + verbose: true + print-hash: true repository-url: https://test.pypi.org/legacy/ \ No newline at end of file From 1361c16eab9cc347bd9bd103ab9031d83d9d493b Mon Sep 17 00:00:00 2001 From: Kim Davies Date: Fri, 2 Aug 2024 20:49:15 -0700 Subject: [PATCH 3/7] Rename idna* to idna_preflight* --- .github/workflows/deploy.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d0a5e64..3c7c289 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,7 +19,7 @@ jobs: - name: Build a binary wheel and a source tarball run: python3 -m build - name: Store the distribution packages - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: python-package-distributions path: dist/ @@ -39,7 +39,7 @@ jobs: steps: - name: Download all the dists - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: python-package-distributions path: dist/ @@ -60,7 +60,7 @@ jobs: steps: - name: Download all the dists - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: python-package-distributions path: dist/ @@ -108,6 +108,12 @@ jobs: with: name: python-package-distributions path: dist/ + - name: List directory + run: ls -R + - name: Rename packages to idna-preflight + run: find . -exec bash -c 'mv $0 ${0/idna/idna_preflight}' {} \; + - name: List directory + run: ls -R - name: Publish distribution to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 with: From 7e2073a19b72ced518e99f239f71b5ba31577a2a Mon Sep 17 00:00:00 2001 From: Kim Davies Date: Fri, 2 Aug 2024 20:54:45 -0700 Subject: [PATCH 4/7] Use actions/download-artifact@v4 --- .github/workflows/deploy.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3c7c289..9b8e089 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,7 +26,7 @@ jobs: publish-to-pypi: name: >- - Publish Python distribution to PyPI + Publish to PyPI if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes needs: - build @@ -48,8 +48,7 @@ jobs: github-release: name: >- - Sign the Python distribution with Sigstore - and upload them to GitHub Release + Upload GitHub Release w/ signature needs: - publish-to-pypi runs-on: ubuntu-latest @@ -90,7 +89,7 @@ jobs: --repo '${{ github.repository }}' publish-to-testpypi: - name: Publish Python distribution to TestPyPI + name: Publish to Test PyPI needs: - build runs-on: ubuntu-latest @@ -104,7 +103,7 @@ jobs: steps: - name: Download all the dists - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: python-package-distributions path: dist/ From b8d9784451fd795a69b7ce3f70b0eb037d6d875f Mon Sep 17 00:00:00 2001 From: Kim Davies Date: Fri, 2 Aug 2024 21:41:43 -0700 Subject: [PATCH 5/7] Back out idna_preflight substitution --- .github/workflows/deploy.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9b8e089..84ca1e3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -47,8 +47,7 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 github-release: - name: >- - Upload GitHub Release w/ signature + name: Sign and upload GitHub Release needs: - publish-to-pypi runs-on: ubuntu-latest @@ -58,12 +57,12 @@ jobs: id-token: write # IMPORTANT: mandatory for sigstore steps: - - name: Download all the dists + - name: Download the dists uses: actions/download-artifact@v4 with: name: python-package-distributions path: dist/ - - name: Sign the dists with Sigstore + - name: Sign with Sigstore uses: sigstore/gh-action-sigstore-python@v2.1.1 with: inputs: >- @@ -107,12 +106,6 @@ jobs: with: name: python-package-distributions path: dist/ - - name: List directory - run: ls -R - - name: Rename packages to idna-preflight - run: find . -exec bash -c 'mv $0 ${0/idna/idna_preflight}' {} \; - - name: List directory - run: ls -R - name: Publish distribution to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 with: From f8a8de43db509c7e7fa0e9e08a7e7f1fe1c1a165 Mon Sep 17 00:00:00 2001 From: Kim Davies Date: Thu, 22 Aug 2024 14:35:38 -0700 Subject: [PATCH 6/7] Do not try to build/send packages to TestPyPI for now We don't have access to test.pypi.org to do this for now as someone else has claimed this project. Have opened at ticket at https://github.com/pypi/support/issues/4484 to remedy but looks like there is a ~6 month backlog so unlikely to get relief soon. --- .github/workflows/deploy.yml | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 84ca1e3..84c6b62 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -87,28 +87,28 @@ jobs: '${{ github.ref_name }}' dist/** --repo '${{ github.repository }}' - publish-to-testpypi: - name: Publish to Test PyPI - needs: - - build - runs-on: ubuntu-latest +# publish-to-testpypi: +# name: Publish to Test PyPI +# needs: +# - build +# runs-on: ubuntu-latest - environment: - name: testpypi - url: https://test.pypi.org/p/idna-preflight +# environment: +# name: testpypi +# url: https://test.pypi.org/p/idna - permissions: - id-token: write # IMPORTANT: mandatory for trusted publishing +# permissions: +# id-token: write # IMPORTANT: mandatory for trusted publishing - steps: - - name: Download all the dists - uses: actions/download-artifact@v4 - with: - name: python-package-distributions - path: dist/ - - name: Publish distribution to TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - verbose: true - print-hash: true - repository-url: https://test.pypi.org/legacy/ \ No newline at end of file +# steps: +# - name: Download all the dists +# uses: actions/download-artifact@v4 +# with: +# name: python-package-distributions +# path: dist/ +# - name: Publish distribution to TestPyPI +# uses: pypa/gh-action-pypi-publish@release/v1 +# with: +# verbose: true +# print-hash: true +# repository-url: https://test.pypi.org/legacy/ \ No newline at end of file From e1a15412eb0de3de9b7bee345e9888d46f32cde4 Mon Sep 17 00:00:00 2001 From: Kim Davies Date: Thu, 22 Aug 2024 15:30:59 -0700 Subject: [PATCH 7/7] Pin Github Actions dependencies --- .github/workflows/deploy.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 84c6b62..b8d1175 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,9 +9,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5 with: python-version: "3.x" - name: Install pypa/build @@ -19,7 +19,7 @@ jobs: - name: Build a binary wheel and a source tarball run: python3 -m build - name: Store the distribution packages - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4 with: name: python-package-distributions path: dist/ @@ -39,7 +39,7 @@ jobs: steps: - name: Download all the dists - uses: actions/download-artifact@v4 + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 with: name: python-package-distributions path: dist/ @@ -58,7 +58,7 @@ jobs: steps: - name: Download the dists - uses: actions/download-artifact@v4 + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 with: name: python-package-distributions path: dist/