|
| 1 | +name: Build and Publish |
| 2 | +# based on official doc |
| 3 | +# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ |
| 4 | + |
| 5 | +on: [push, workflow_dispatch] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + name: Build |
| 10 | + runs-on: ubuntu-22.04 |
| 11 | + |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: "3.x" |
| 19 | + |
| 20 | + - name: Install pypa/build |
| 21 | + run: python3 -m pip install build --user |
| 22 | + |
| 23 | + - name: Build a binary wheel and a source tarball (agentlab) |
| 24 | + run: python3 -m build . --outdir dist/ |
| 25 | + |
| 26 | + - name: Store the distribution packages |
| 27 | + uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + name: python-package-distributions |
| 30 | + path: dist/ |
| 31 | + |
| 32 | + publish-to-pypi: |
| 33 | + name: Publish to PyPI |
| 34 | + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes # tweak so it doesnt publish all tags |
| 35 | + needs: |
| 36 | + - build |
| 37 | + runs-on: ubuntu-22.04 |
| 38 | + environment: pypi |
| 39 | + permissions: |
| 40 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Download all the distribution packages |
| 44 | + uses: actions/download-artifact@v4 |
| 45 | + with: |
| 46 | + name: python-package-distributions |
| 47 | + path: dist/ |
| 48 | + |
| 49 | + - name: Publish all distribution packages to PyPI |
| 50 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 51 | + |
| 52 | + github-release: |
| 53 | + name: Sign packages with Sigstore and upload them to GitHub Release |
| 54 | + needs: |
| 55 | + - publish-to-pypi |
| 56 | + runs-on: ubuntu-22.04 |
| 57 | + |
| 58 | + permissions: |
| 59 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 60 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 61 | + |
| 62 | + steps: |
| 63 | + - name: Download all the dists |
| 64 | + uses: actions/download-artifact@v4 |
| 65 | + with: |
| 66 | + name: python-package-distributions |
| 67 | + path: dist/ |
| 68 | + |
| 69 | + - name: Sign the dists with Sigstore |
| 70 | + |
| 71 | + with: |
| 72 | + inputs: >- |
| 73 | + ./dist/*.tar.gz |
| 74 | + ./dist/*.whl |
| 75 | +
|
| 76 | + - name: Create GitHub Release |
| 77 | + env: |
| 78 | + GITHUB_TOKEN: ${{ github.token }} |
| 79 | + run: >- |
| 80 | + gh release create |
| 81 | + '${{ github.ref_name }}' |
| 82 | + --repo '${{ github.repository }}' |
| 83 | + --notes "" |
| 84 | +
|
| 85 | + - name: Upload artifact signatures to GitHub Release |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ github.token }} |
| 88 | + # Upload to GitHub Release using the `gh` CLI. |
| 89 | + # `dist/` contains the built packages, and the |
| 90 | + # sigstore-produced signatures and certificates. |
| 91 | + run: >- |
| 92 | + gh release upload |
| 93 | + '${{ github.ref_name }}' dist/** |
| 94 | + --repo '${{ github.repository }}' |
| 95 | +
|
| 96 | + - name: Set GitHub Release as pre-release |
| 97 | + if: contains(github.ref, '.dev') # only set tags vA.B.C.devD as pre-release |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ github.token }} |
| 100 | + run: >- |
| 101 | + gh release edit |
| 102 | + '${{ github.ref_name }}' |
| 103 | + --repo '${{ github.repository }}' |
| 104 | + --prerelease |
| 105 | +
|
| 106 | + # publish-to-testpypi: |
| 107 | + # name: Publish to TestPyPI |
| 108 | + # needs: |
| 109 | + # - build |
| 110 | + # runs-on: ubuntu-latest |
| 111 | + # environment: testpypi |
| 112 | + # permissions: |
| 113 | + # id-token: write # IMPORTANT: mandatory for trusted publishing |
| 114 | + |
| 115 | + # steps: |
| 116 | + # - name: Download all the distribution packages |
| 117 | + # uses: actions/download-artifact@v4 |
| 118 | + # with: |
| 119 | + # name: python-package-distributions |
| 120 | + # path: dist/ |
| 121 | + |
| 122 | + # - name: Publish distribution packages to TestPyPI |
| 123 | + # uses: pypa/gh-action-pypi-publish@release/v1 |
| 124 | + # with: |
| 125 | + # repository-url: https://test.pypi.org/legacy/ |
0 commit comments