| 1 |
name: Publish cloudpickle 🥒 distribution 📦 to PyPI and TestPyPI |
| 2 |
# Taken from: |
| 3 |
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ |
| 4 |
|
| 5 |
on: push |
| 6 |
|
| 7 |
jobs: |
| 8 |
build: |
| 9 |
name: Build distribution 📦 |
| 10 |
# Don't run on forked repositories |
| 11 |
if: github.event.repository.fork != true |
| 12 |
runs-on: ubuntu-latest |
| 13 |
|
| 14 |
steps: |
| 15 |
- uses: actions/checkout@v4 |
| 16 |
with: |
| 17 |
persist-credentials: false |
| 18 |
- name: Set up Python |
| 19 |
uses: actions/setup-python@v5 |
| 20 |
with: |
| 21 |
python-version: "3.x" |
| 22 |
- name: Install pypa/build |
| 23 |
run: >- |
| 24 |
python3 -m |
| 25 |
pip install |
| 26 |
build |
| 27 |
--user |
| 28 |
- name: Build a binary wheel and a source tarball |
| 29 |
run: python3 -m build |
| 30 |
- name: Store the distribution packages |
| 31 |
uses: actions/upload-artifact@v4 |
| 32 |
with: |
| 33 |
name: python-package-distributions |
| 34 |
path: dist/ |
| 35 |
retention-days: 1 |
| 36 |
|
| 37 |
publish-to-pypi: |
| 38 |
name: >- |
| 39 |
Publish cloudpickle 🥒 distribution 📦 to PyPI |
| 40 |
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes |
| 41 |
needs: |
| 42 |
- build |
| 43 |
runs-on: ubuntu-latest |
| 44 |
environment: |
| 45 |
name: pypi |
| 46 |
url: https://pypi.org/p/cloudpickle |
| 47 |
permissions: |
| 48 |
id-token: write # IMPORTANT: mandatory for trusted publishing |
| 49 |
|
| 50 |
steps: |
| 51 |
- name: Download all the dists |
| 52 |
uses: actions/download-artifact@v4 |
| 53 |
with: |
| 54 |
name: python-package-distributions |
| 55 |
path: dist/ |
| 56 |
- name: Publish distribution 📦 to PyPI |
| 57 |
uses: pypa/gh-action-pypi-publish@release/v1 |
| 58 |
|
| 59 |
github-release: |
| 60 |
name: >- |
| 61 |
Sign the cloudpickle 🥒 distribution 📦 with Sigstore |
| 62 |
and upload them to GitHub Release |
| 63 |
needs: |
| 64 |
- publish-to-pypi |
| 65 |
runs-on: ubuntu-latest |
| 66 |
|
| 67 |
permissions: |
| 68 |
contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 69 |
id-token: write # IMPORTANT: mandatory for sigstore |
| 70 |
|
| 71 |
steps: |
| 72 |
- name: Download all the dists |
| 73 |
uses: actions/download-artifact@v4 |
| 74 |
with: |
| 75 |
name: python-package-distributions |
| 76 |
path: dist/ |
| 77 |
- name: Sign the dists with Sigstore |
| 78 |
uses: sigstore/[email protected] |
| 79 |
with: |
| 80 |
inputs: >- |
| 81 |
./dist/*.tar.gz |
| 82 |
./dist/*.whl |
| 83 |
- name: Create GitHub Release |
| 84 |
env: |
| 85 |
GITHUB_TOKEN: ${{ github.token }} |
| 86 |
run: >- |
| 87 |
gh release create |
| 88 |
"$GITHUB_REF_NAME" |
| 89 |
--repo "$GITHUB_REPOSITORY" |
| 90 |
--notes "" |
| 91 |
- name: Upload artifact signatures to GitHub Release |
| 92 |
env: |
| 93 |
GITHUB_TOKEN: ${{ github.token }} |
| 94 |
# Upload to GitHub Release using the `gh` CLI. |
| 95 |
# `dist/` contains the built packages, and the |
| 96 |
# sigstore-produced signatures and certificates. |
| 97 |
run: >- |
| 98 |
gh release upload |
| 99 |
"$GITHUB_REF_NAME" dist/** |
| 100 |
--repo "$GITHUB_REPOSITORY" |
| 101 |
|
| 102 |
publish-to-testpypi: |
| 103 |
name: Publish cloudpickle 🥒 distribution 📦 to TestPyPI |
| 104 |
needs: |
| 105 |
- build |
| 106 |
if: github.ref_name == 'master' |
| 107 |
runs-on: ubuntu-latest |
| 108 |
|
| 109 |
environment: |
| 110 |
name: testpypi |
| 111 |
url: https://test.pypi.org/p/cloudpickle |
| 112 |
|
| 113 |
permissions: |
| 114 |
id-token: write # IMPORTANT: mandatory for trusted publishing |
| 115 |
|
| 116 |
steps: |
| 117 |
- name: Download all the dists |
| 118 |
uses: actions/download-artifact@v4 |
| 119 |
with: |
| 120 |
name: python-package-distributions |
| 121 |
path: dist/ |
| 122 |
- name: Publish distribution 📦 to TestPyPI |
| 123 |
uses: pypa/gh-action-pypi-publish@release/v1 |
| 124 |
with: |
| 125 |
verbose: true |
| 126 |
# skip-existing is required for .dev0 versions with fixed names but |
| 127 |
# different contents. See also: https://github.com/pypa/flit/issues/257 |
| 128 |
skip-existing: true |
| 129 |
repository-url: https://test.pypi.org/legacy/ |