Release #34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Release version (e.g. v0.1.0)" | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: pip | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[dev]" | |
| - name: Lint | |
| run: ruff check hedwig_cg/ | |
| - name: Test | |
| run: pytest --tb=short -q | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| environment: pypi | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: pip | |
| - name: Validate version format | |
| env: | |
| VERSION: ${{ inputs.version }} | |
| run: | | |
| if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "::error::Version must match vX.Y.Z format (e.g. v0.1.0)" | |
| exit 1 | |
| fi | |
| - name: Check tag does not already exist | |
| env: | |
| VERSION: ${{ inputs.version }} | |
| run: | | |
| if git rev-parse "$VERSION" >/dev/null 2>&1; then | |
| echo "::error::Tag $VERSION already exists" | |
| exit 1 | |
| fi | |
| - name: Build package | |
| run: | | |
| pip install build | |
| python -m build | |
| - name: Verify wheel | |
| run: | | |
| pip install dist/*.whl | |
| hedwig-cg --version | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| - name: Generate changelog | |
| env: | |
| VERSION: ${{ inputs.version }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$PREV_TAG" ]; then | |
| COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges) | |
| COMPARE_BASE=$(git rev-list --max-parents=0 HEAD | head -1) | |
| else | |
| COMMITS=$(git log "${PREV_TAG}..HEAD" --pretty=format:"- %s (%h)" --no-merges) | |
| COMPARE_BASE="$PREV_TAG" | |
| fi | |
| { | |
| echo "## What's Changed" | |
| echo "" | |
| echo "$COMMITS" | |
| echo "" | |
| echo "**Full Changelog**: https://github.com/${REPO}/compare/${COMPARE_BASE}...${VERSION}" | |
| } > release_notes.md | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ inputs.version }} | |
| SHA: ${{ github.sha }} | |
| run: | | |
| gh release create "$VERSION" dist/* \ | |
| --title "$VERSION" \ | |
| --notes-file release_notes.md \ | |
| --target "$SHA" |