|
1 | 1 | # Maintained in moderation-api/sdk-generator (custom/python). Edits here are overwritten. |
| 2 | +# Every push to main whose package version has no release tag yet publishes |
| 3 | +# that version and creates the GitHub release (notes: .github/release-notes/vX.Y.Z.md |
| 4 | +# if present, otherwise generated from the merged pull requests). |
2 | 5 | name: Publish PyPI |
3 | 6 | on: |
4 | | - release: |
5 | | - types: [published] |
| 7 | + push: |
| 8 | + branches: [main] |
6 | 9 | workflow_dispatch: |
7 | 10 |
|
| 11 | +concurrency: release |
| 12 | + |
8 | 13 | permissions: |
9 | | - contents: read |
| 14 | + contents: write |
10 | 15 |
|
11 | 16 | jobs: |
12 | 17 | publish: |
13 | 18 | runs-on: ubuntu-latest |
14 | 19 | steps: |
15 | 20 | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 21 | + - name: Read the version |
| 22 | + run: echo "VERSION=$(sed -n 's/^version = \"\(.*\)\"$/\1/p' pyproject.toml | head -n 1)" >> "$GITHUB_ENV" |
| 23 | + - name: Check for an unreleased version |
| 24 | + id: version |
| 25 | + run: | |
| 26 | + echo "VERSION=${VERSION}" >> "$GITHUB_ENV" |
| 27 | + if git ls-remote --exit-code --tags origin "refs/tags/v${VERSION}" >/dev/null; then |
| 28 | + echo "v${VERSION} is already released." |
| 29 | + echo "release=false" >> "$GITHUB_OUTPUT" |
| 30 | + else |
| 31 | + echo "release=true" >> "$GITHUB_OUTPUT" |
| 32 | + fi |
16 | 33 | - uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2 |
| 34 | + if: steps.version.outputs.release == 'true' |
17 | 35 | with: |
18 | 36 | version: "0.9.13" |
19 | | - - name: Check the release tag matches pyproject.toml |
20 | | - if: github.event_name == 'release' |
21 | | - run: | |
22 | | - version=$(sed -n 's/^version = "\(.*\)"$/\1/p' pyproject.toml | head -1) |
23 | | - if [ "${GITHUB_REF_NAME#v}" != "$version" ]; then |
24 | | - echo "::error::Release tag $GITHUB_REF_NAME does not match pyproject.toml version $version" |
25 | | - exit 1 |
26 | | - fi |
27 | | - - run: bash scripts/publish.sh |
| 37 | + - if: steps.version.outputs.release == 'true' |
| 38 | + run: bash scripts/publish.sh |
28 | 39 | env: |
29 | 40 | PYPI_TOKEN: ${{ secrets.MODERATION_API_PYPI_TOKEN || secrets.PYPI_TOKEN }} |
| 41 | + - name: Create the GitHub release |
| 42 | + if: steps.version.outputs.release == 'true' |
| 43 | + env: |
| 44 | + GH_TOKEN: ${{ github.token }} |
| 45 | + run: | |
| 46 | + notes=".github/release-notes/v${VERSION}.md" |
| 47 | + if [ -f "$notes" ]; then |
| 48 | + gh release create "v${VERSION}" --target "$GITHUB_SHA" --title "v${VERSION}" --notes-file "$notes" |
| 49 | + else |
| 50 | + gh release create "v${VERSION}" --target "$GITHUB_SHA" --title "v${VERSION}" --generate-notes |
| 51 | + fi |
0 commit comments