|
| 1 | +name: Publish release build to pypi and create release tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + outputs: |
| 12 | + version: ${{ steps.build-step.outputs.version }} |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + - name: Set up Python 3.10 |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: "3.9" |
| 20 | + - name: Install pip and flake package |
| 21 | + run: | |
| 22 | + python -m pip install --upgrade pip |
| 23 | + pip install flake8 pytest |
| 24 | + - name: Lint with flake8 |
| 25 | + run: | |
| 26 | + # stop the build if there are Python syntax errors or undefined names |
| 27 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 28 | + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide |
| 29 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 30 | + - name: Install poetry and project dependencies |
| 31 | + run: | |
| 32 | + python -m pip install poetry |
| 33 | + poetry install |
| 34 | + - name: Test with pytest |
| 35 | + run: | |
| 36 | + echo ${{ github.workspace }} |
| 37 | + cd ${{ github.workspace }}/tests |
| 38 | + poetry run pytest |
| 39 | + - name: Build |
| 40 | + id: build-step |
| 41 | + run: | |
| 42 | + poetry build |
| 43 | + VERSION=$(poetry version -s) |
| 44 | + echo "$VERSION" |
| 45 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 46 | + - name: Print release version |
| 47 | + run: | |
| 48 | + echo "the version number is ${{ steps.build-step.outputs.version }}" |
| 49 | + - name: Archive production artifacts |
| 50 | + uses: actions/upload-artifact@v4 |
| 51 | + with: |
| 52 | + name: dwcahandler-dist-v${{ steps.build-step.outputs.version }} |
| 53 | + path: dist |
| 54 | + |
| 55 | + publish-to-pypi: |
| 56 | + name: Publish dwcahandler distribution to PyPI |
| 57 | + runs-on: ubuntu-latest |
| 58 | + |
| 59 | + needs: |
| 60 | + - build |
| 61 | + |
| 62 | + environment: |
| 63 | + name: production |
| 64 | + url: https://pypi.org/p/dwcahandler |
| 65 | + |
| 66 | + permissions: |
| 67 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 68 | + |
| 69 | + steps: |
| 70 | + - name: Download all the dists |
| 71 | + uses: actions/download-artifact@v4 |
| 72 | + with: |
| 73 | + name: dwcahandler-dist-v${{ needs.build.outputs.version }} |
| 74 | + path: dist/ |
| 75 | + - name: Publish dwcahandler distribution to PyPI |
| 76 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 77 | + |
| 78 | + github-release: |
| 79 | + name: >- |
| 80 | + Sign the dwcahandler distribution with Sigstore |
| 81 | + and upload them to GitHub Release |
| 82 | + needs: [build, publish-to-pypi] |
| 83 | + runs-on: ubuntu-latest |
| 84 | + |
| 85 | + permissions: |
| 86 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 87 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 88 | + |
| 89 | + steps: |
| 90 | + - name: Download all the dists |
| 91 | + uses: actions/download-artifact@v4 |
| 92 | + with: |
| 93 | + name: dwcahandler-dist-v${{ needs.build.outputs.version }} |
| 94 | + path: dist/ |
| 95 | + - name: Sign the dists with Sigstore |
| 96 | + uses: sigstore/gh-action-sigstore-python@v2.1.1 |
| 97 | + with: |
| 98 | + inputs: >- |
| 99 | + ./dist/*.tar.gz |
| 100 | + ./dist/*.whl |
| 101 | + - name: Create GitHub Release |
| 102 | + id: create-release |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ github.token }} |
| 105 | + run: | |
| 106 | + version="v${{ needs.build.outputs.version }}" |
| 107 | + gh release create $version --repo ${{ github.repository }} |
| 108 | + echo "tag-version=$version" >> "$GITHUB_OUTPUT" |
| 109 | + - name: Upload artifact signatures to GitHub Release |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ github.token }} |
| 112 | + # Upload to GitHub Release using the `gh` CLI. |
| 113 | + # `dist/` contains the built packages, and the |
| 114 | + # sigstore-produced signatures and certificates. |
| 115 | + run: >- |
| 116 | + gh release upload |
| 117 | + '${{ steps.create-release.outputs.tag-version }}' dist/** |
| 118 | + --repo '${{ github.repository }}' |
0 commit comments