|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: false |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Build dists |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: "3.11" |
| 27 | + |
| 28 | + - name: Install uv |
| 29 | + uses: astral-sh/setup-uv@v6 |
| 30 | + with: |
| 31 | + version: "0.8.4" |
| 32 | + enable-cache: true |
| 33 | + |
| 34 | + - name: Verify tag matches project version |
| 35 | + run: | |
| 36 | + VER=$(uv version --short) |
| 37 | + TAG=${GITHUB_REF_NAME#v} |
| 38 | + test "$VER" = "$TAG" || { echo "Tag $TAG != version $VER"; exit 1; } |
| 39 | +
|
| 40 | + - name: Build sdist and wheel with uv |
| 41 | + run: uv build --no-sources |
| 42 | + |
| 43 | + - name: Upload dist artifacts |
| 44 | + uses: actions/upload-artifact@v4 |
| 45 | + with: |
| 46 | + name: dist |
| 47 | + path: dist/* |
| 48 | + |
| 49 | + publish: |
| 50 | + name: Publish to PyPI |
| 51 | + needs: build |
| 52 | + runs-on: ubuntu-latest |
| 53 | + environment: |
| 54 | + name: pypi |
| 55 | + url: https://pypi.org/p/PubChemPy |
| 56 | + permissions: |
| 57 | + id-token: write |
| 58 | + contents: read |
| 59 | + steps: |
| 60 | + - name: Download dist artifacts |
| 61 | + uses: actions/download-artifact@v4 |
| 62 | + with: |
| 63 | + name: dist |
| 64 | + path: dist |
| 65 | + |
| 66 | + - name: Publish package distributions to PyPI |
| 67 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 68 | + |
| 69 | + release: |
| 70 | + name: Create GitHub Release |
| 71 | + needs: publish |
| 72 | + runs-on: ubuntu-latest |
| 73 | + permissions: |
| 74 | + contents: write |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Download dist artifacts |
| 79 | + uses: actions/download-artifact@v4 |
| 80 | + with: |
| 81 | + name: dist |
| 82 | + path: dist |
| 83 | + |
| 84 | + - name: Create GitHub Release (draft) |
| 85 | + env: |
| 86 | + GH_TOKEN: ${{ github.token }} |
| 87 | + TAG: ${{ github.ref_name }} |
| 88 | + run: | |
| 89 | + args=( |
| 90 | + "${TAG}" dist/* |
| 91 | + --title "PubChemPy ${TAG#v}" |
| 92 | + --generate-notes |
| 93 | + --draft |
| 94 | + ) |
| 95 | + if gh release view "${TAG}" >/dev/null 2>&1; then |
| 96 | + echo "Release ${TAG} already exists; skipping create." |
| 97 | + else |
| 98 | + gh release create "${args[@]}" |
| 99 | + fi |
0 commit comments