|
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 |
25 | 49 | with: |
26 | | - python-version: ${{ matrix.python-version }} |
| 50 | + name: python-package-distributions |
| 51 | + path: dist/ |
| 52 | + - name: Publish distribution 📦 to PyPI |
| 53 | + uses: pypa/gh-action-pypi-publish@release/v1 |
27 | 54 |
|
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 |
| 55 | + github-release: |
| 56 | + name: >- |
| 57 | + Sign the Python 🐍 distribution 📦 with Sigstore |
| 58 | + and upload them to GitHub Release |
| 59 | + needs: |
| 60 | + - publish-to-pypi |
| 61 | + runs-on: ubuntu-latest |
33 | 62 |
|
34 | | - # Step 4: Build the package (wheel and source distribution) |
35 | | - - name: Build the package |
36 | | - run: | |
37 | | - python setup.py sdist bdist_wheel |
| 63 | + permissions: |
| 64 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 65 | + id-token: write # IMPORTANT: mandatory for sigstore |
38 | 66 |
|
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 |
| 67 | + steps: |
| 68 | + - name: Download all the dists |
| 69 | + uses: actions/download-artifact@v4 |
| 70 | + with: |
| 71 | + name: python-package-distributions |
| 72 | + path: dist/ |
| 73 | + - name: Sign the dists with Sigstore |
| 74 | + |
| 75 | + with: |
| 76 | + inputs: >- |
| 77 | + ./dist/*.tar.gz |
| 78 | + ./dist/*.whl |
| 79 | + - name: Create GitHub Release |
42 | 80 | 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 |
| 81 | + GITHUB_TOKEN: ${{ github.token }} |
| 82 | + run: >- |
| 83 | + gh release create |
| 84 | + '${{ github.ref_name }}' |
| 85 | + --repo '${{ github.repository }}' |
| 86 | + --notes "" |
| 87 | + - name: Upload artifact signatures to GitHub Release |
| 88 | + env: |
| 89 | + GITHUB_TOKEN: ${{ github.token }} |
| 90 | + # Upload to GitHub Release using the `gh` CLI. |
| 91 | + # `dist/` contains the built packages, and the |
| 92 | + # sigstore-produced signatures and certificates. |
| 93 | + run: >- |
| 94 | + gh release upload |
| 95 | + '${{ github.ref_name }}' dist/** |
| 96 | + --repo '${{ github.repository }}' |
0 commit comments