|
4 | 4 | # Trigger this workflow when a new tag is pushed
|
5 | 5 | push:
|
6 | 6 | tags:
|
7 |
| - - '*' |
| 7 | + - 'v*' |
8 | 8 |
|
9 | 9 | jobs:
|
10 |
| - build-and-publish: |
| 10 | + build: |
| 11 | + name: Build distribution 📦 |
11 | 12 | runs-on: ubuntu-latest
|
12 | 13 |
|
13 |
| - strategy: |
14 |
| - matrix: |
15 |
| - python-version: ["3.9", "3.10", "3.11", "3.12"] |
16 |
| - |
17 | 14 | steps:
|
18 |
| - # Step 1: Check out the repository |
19 |
| - - name: Check out code |
20 |
| - uses: actions/checkout@v3 |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: "3.x" |
| 20 | + - name: Install pypa/build |
| 21 | + run: >- |
| 22 | + python3 -m |
| 23 | + pip install |
| 24 | + build |
| 25 | + --user |
| 26 | + - name: Build a binary wheel and a source tarball |
| 27 | + run: python3 -m build |
| 28 | + - name: Store the distribution packages |
| 29 | + uses: actions/upload-artifact@v4 |
| 30 | + with: |
| 31 | + name: python-package-distributions |
| 32 | + path: dist/ |
21 | 33 |
|
22 |
| - # Step 2: Set up Python environment with matrix |
23 |
| - - name: Set up Python ${{ matrix.python-version }} |
24 |
| - uses: actions/setup-python@v4 |
| 34 | + publish-to-pypi: |
| 35 | + name: >- |
| 36 | + Publish Python 🐍 distribution 📦 to PyPI |
| 37 | + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes |
| 38 | + needs: |
| 39 | + - build |
| 40 | + runs-on: ubuntu-latest |
| 41 | + environment: |
| 42 | + name: pypi |
| 43 | + url: https://pypi.org/p/GenerativeRL # Replace <package-name> with your PyPI project name |
| 44 | + permissions: |
| 45 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 46 | + steps: |
| 47 | + - name: Download all the dists |
| 48 | + uses: actions/download-artifact@v4 |
| 49 | + with: |
| 50 | + name: python-package-distributions |
| 51 | + path: dist/ |
| 52 | + - name: Publish distribution 📦 to PyPI |
| 53 | + uses: pypa/gh-action-pypi-publish@release/v1 |
25 | 54 | with:
|
26 |
| - python-version: ${{ matrix.python-version }} |
| 55 | + password: ${{ secrets.PYPI_API_TOKEN }} |
27 | 56 |
|
28 |
| - # Step 3: Install build dependencies |
29 |
| - - name: Install build dependencies |
30 |
| - run: | |
31 |
| - python -m pip install --upgrade pip |
32 |
| - pip install setuptools wheel twine |
| 57 | + github-release: |
| 58 | + name: >- |
| 59 | + Sign the Python 🐍 distribution 📦 with Sigstore |
| 60 | + and upload them to GitHub Release |
| 61 | + needs: |
| 62 | + - publish-to-pypi |
| 63 | + runs-on: ubuntu-latest |
33 | 64 |
|
34 |
| - # Step 4: Build the package (wheel and source distribution) |
35 |
| - - name: Build the package |
36 |
| - run: | |
37 |
| - python setup.py sdist bdist_wheel |
| 65 | + permissions: |
| 66 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 67 | + id-token: write # IMPORTANT: mandatory for sigstore |
38 | 68 |
|
39 |
| - # Step 5: Publish the package to PyPI (only run once for one version) |
40 |
| - - name: Publish to PyPI |
41 |
| - if: matrix.python-version == '3.9' # Publish only once, on Python 3.9 |
| 69 | + steps: |
| 70 | + - name: Download all the dists |
| 71 | + uses: actions/download-artifact@v4 |
| 72 | + with: |
| 73 | + name: python-package-distributions |
| 74 | + path: dist/ |
| 75 | + - name: Sign the dists with Sigstore |
| 76 | + uses: sigstore/gh-action-sigstore-python@v3.0.0 |
| 77 | + with: |
| 78 | + inputs: >- |
| 79 | + ./dist/*.tar.gz |
| 80 | + ./dist/*.whl |
| 81 | + - name: Create GitHub Release |
42 | 82 | env:
|
43 |
| - PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} # Use the PyPI token stored in GitHub Secrets |
44 |
| - run: | |
45 |
| - python -m twine upload dist/* |
46 |
| -
|
47 |
| - # Step 6: Clean up the build artifacts |
48 |
| - - name: Remove build artifacts |
49 |
| - if: matrix.python-version == '3.9' # Clean up once after publishing |
50 |
| - run: rm -rf dist build *.egg-info |
| 83 | + GITHUB_TOKEN: ${{ github.token }} |
| 84 | + run: >- |
| 85 | + gh release create |
| 86 | + '${{ github.ref_name }}' |
| 87 | + --repo '${{ github.repository }}' |
| 88 | + --notes "" |
| 89 | + - name: Upload artifact signatures to GitHub Release |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ github.token }} |
| 92 | + # Upload to GitHub Release using the `gh` CLI. |
| 93 | + # `dist/` contains the built packages, and the |
| 94 | + # sigstore-produced signatures and certificates. |
| 95 | + run: >- |
| 96 | + gh release upload |
| 97 | + '${{ github.ref_name }}' dist/** |
| 98 | + --repo '${{ github.repository }}' |
0 commit comments