diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..07fc6a8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,99 @@ +name: Release + +on: + push: + tags: + - "v*" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: read + +jobs: + build: + name: Build dists + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install uv + uses: astral-sh/setup-uv@v6 + with: + version: "0.8.4" + enable-cache: true + + - name: Verify tag matches project version + run: | + VER=$(uv version --short) + TAG=${GITHUB_REF_NAME#v} + test "$VER" = "$TAG" || { echo "Tag $TAG != version $VER"; exit 1; } + + - name: Build sdist and wheel with uv + run: uv build --no-sources + + - name: Upload dist artifacts + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/* + + publish: + name: Publish to PyPI + needs: build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/PubChemPy + permissions: + id-token: write + contents: read + steps: + - name: Download dist artifacts + uses: actions/download-artifact@v4 + with: + name: dist + path: dist + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + release: + name: Create GitHub Release + needs: publish + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - name: Download dist artifacts + uses: actions/download-artifact@v4 + with: + name: dist + path: dist + + - name: Create GitHub Release (draft) + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + run: | + args=( + "${TAG}" dist/* + --title "PubChemPy ${TAG#v}" + --generate-notes + --draft + ) + if gh release view "${TAG}" >/dev/null 2>&1; then + echo "Release ${TAG} already exists; skipping create." + else + gh release create "${args[@]}" + fi