|  | 
| 1 | 1 | name: Release New PyPi Version | 
| 2 | 2 | 
 | 
|  | 3 | +permissions: | 
|  | 4 | +  id-token: write | 
|  | 5 | +  contents: write | 
|  | 6 | + | 
| 3 | 7 | on: | 
| 4 | 8 |   workflow_dispatch: # This event allows manual triggering | 
| 5 | 9 | 
 | 
| 6 | 10 | jobs: | 
| 7 | 11 |   release: | 
| 8 | 12 |     runs-on: ubuntu-latest | 
|  | 13 | +     | 
|  | 14 | +    outputs: | 
|  | 15 | +      version: ${{ steps.version.outputs.version }} | 
| 9 | 16 | 
 | 
| 10 | 17 |     steps: | 
| 11 | 18 |       - name: Checkout Repository | 
| 12 | 19 |         uses: actions/checkout@v5 | 
|  | 20 | +        with: | 
|  | 21 | +          fetch-tags: true | 
|  | 22 | +          fetch-depth: 0 | 
| 13 | 23 | 
 | 
| 14 | 24 |       - name: Setup Python | 
| 15 | 25 |         uses: actions/setup-python@v6 | 
|  | 
| 28 | 38 |       - name: Install dependencies | 
| 29 | 39 |         run: poetry install --all-extras | 
| 30 | 40 | 
 | 
|  | 41 | +      - name: Check for version bump | 
|  | 42 | +        id: version | 
|  | 43 | +        continue-on-error: false | 
|  | 44 | +        shell: bash {0} | 
|  | 45 | +        run: | | 
|  | 46 | +          PYPROJECT_TOML="pyproject.toml" | 
|  | 47 | +
 | 
|  | 48 | +          # Extract the version using grep and sed | 
|  | 49 | +          version=$(grep -m 1 "version" "$PYPROJECT_TOML" | sed -E 's/.*version[[:space:]]*=[[:space:]]*"([^"]*)".*/\1/') | 
|  | 50 | +
 | 
|  | 51 | +          echo "Project version: $version" | 
|  | 52 | +
 | 
|  | 53 | +          if [ -z "$version" ] | 
|  | 54 | +          then | 
|  | 55 | +            echo "Missing version file!" | 
|  | 56 | +            echo "Repository must have a package.json or a version.txt file!" | 
|  | 57 | +            exit 1 | 
|  | 58 | +          fi | 
|  | 59 | +
 | 
|  | 60 | +          echo "Checking if $version already exists..." | 
|  | 61 | +          version_commit="$(git rev-parse "$version" 2>/dev/null)" | 
|  | 62 | +          if [ ! -z "$version_commit" ] && [ "$version_commit" != "$version" ]; | 
|  | 63 | +          then | 
|  | 64 | +              echo "Version $version already exist on commit $version_commit!" | 
|  | 65 | +              echo "Abandoning build..." | 
|  | 66 | +              echo "To complete this release update the version field in the package.json with an appropriate semantic version." | 
|  | 67 | +              exit 1 | 
|  | 68 | +          else | 
|  | 69 | +            echo "version=$version" >> "$GITHUB_OUTPUT" | 
|  | 70 | +            exit 0 | 
|  | 71 | +          fi | 
|  | 72 | +
 | 
| 31 | 73 |       - name: Upload to PyPI | 
| 32 | 74 |         env: | 
| 33 | 75 |           PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | 
| 34 | 76 |         run: poetry publish --build -u __token__ -p $PYPI_PASSWORD | 
|  | 77 | + | 
|  | 78 | +      - name: Tag | 
|  | 79 | +        id: tag | 
|  | 80 | +        continue-on-error: false | 
|  | 81 | +        run: | | 
|  | 82 | +          version="${{ steps.version.outputs.version }}" | 
|  | 83 | +          echo "Configuring github bot" | 
|  | 84 | +          git config user.name "github-actions[bot]" | 
|  | 85 | +          # Comes from https://api.github.com/users/github-actions%5Bbot%5D | 
|  | 86 | +          git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | 
|  | 87 | +          echo "Creating github tag: $version" | 
|  | 88 | +          git tag "$version" | 
|  | 89 | +          echo "Pushing tags" | 
|  | 90 | +          git push --tags | 
0 commit comments