Skip to content

docs: add CITATION.cff (enables GitHub Cite-this-repository) #2

docs: add CITATION.cff (enables GitHub Cite-this-repository)

docs: add CITATION.cff (enables GitHub Cite-this-repository) #2

Workflow file for this run

name: Release
# Tag-driven release: push a `vX.Y.Z` tag and this builds, publishes to PyPI
# via Trusted Publishing (OIDC — no API token stored anywhere), and cuts a
# GitHub release with the artifacts attached.
#
# git tag v0.1.0 && git push origin v0.1.0
#
# One-time setup required on PyPI: project `ghostcite` → Settings → Publishing →
# add a GitHub Actions trusted publisher (owner=musharna, repo=ghostcite,
# workflow=release.yml, environment=pypi). And create a GitHub environment
# named `pypi` (Settings → Environments).
on:
push:
tags: ["v*"]
jobs:
build:
name: Build distributions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
- name: Verify tag matches package version
run: |
TAG="${GITHUB_REF_NAME#v}"
VER=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
if [ "$TAG" != "$VER" ]; then
echo "Release tag '$TAG' != pyproject version '$VER'"; exit 1
fi
- name: Build sdist + wheel
run: uv build
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
pypi:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write # OIDC token for Trusted Publishing; no password/token needed
steps:
- uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: Publish to PyPI (trusted publishing)
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
github-release:
name: Create GitHub release
needs: pypi
runs-on: ubuntu-latest
permissions:
contents: write # create the release + upload assets
steps:
- uses: actions/checkout@v6 # for CHANGELOG.md
- uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: Create release with artifacts
env:
GH_TOKEN: ${{ github.token }}
run: |
# Prefer the matching CHANGELOG.md section as release notes; fall back
# to GitHub's auto-generated notes if the version has no section.
VER="${GITHUB_REF_NAME#v}"
awk -v h="## [$VER]" '
index($0, h) == 1 { grab = 1; next }
grab && index($0, "## ") == 1 { exit }
grab { print }
' CHANGELOG.md > release-notes.md
if grep -q '[^[:space:]]' release-notes.md; then
gh release create "${GITHUB_REF_NAME}" \
--repo "${GITHUB_REPOSITORY}" \
--title "${GITHUB_REF_NAME}" \
--notes-file release-notes.md \
dist/*
else
gh release create "${GITHUB_REF_NAME}" \
--repo "${GITHUB_REPOSITORY}" \
--title "${GITHUB_REF_NAME}" \
--generate-notes \
dist/*
fi