publish #14
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: publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| confirm_version: | |
| description: Version to publish. Must match pyproject.toml. | |
| required: true | |
| type: string | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| name: Build release artifacts | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Refuse non-main refs | |
| if: github.ref != 'refs/heads/main' | |
| run: | | |
| echo "Publishing is only allowed from main. Current ref: $GITHUB_REF" | |
| exit 1 | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: true | |
| - name: Sync environment | |
| run: uv sync --locked | |
| - name: Validate requested version | |
| env: | |
| CONFIRM_VERSION: ${{ inputs.confirm_version }} | |
| run: | | |
| set -euo pipefail | |
| project_version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')" | |
| if [ "$project_version" != "$CONFIRM_VERSION" ]; then | |
| echo "confirm_version ($CONFIRM_VERSION) does not match pyproject.toml ($project_version)." | |
| exit 1 | |
| fi | |
| case "$project_version" in | |
| *dev*|*a*|*b*|*rc*) | |
| echo "Stable publishing refuses pre-release version: $project_version" | |
| exit 1 | |
| ;; | |
| esac | |
| - name: Test | |
| run: uv run pytest | |
| - name: Lint | |
| run: uv run ruff check . | |
| - name: Diff hygiene | |
| run: git diff --check | |
| - name: Build artifacts | |
| run: uv build --out-dir dist | |
| - name: Check artifacts | |
| run: uvx twine check dist/* | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: codealmanac-dist | |
| path: dist/* | |
| if-no-files-found: error | |
| publish: | |
| name: Publish to PyPI | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/codealmanac | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: codealmanac-dist | |
| path: dist | |
| - name: Publish artifacts | |
| uses: pypa/gh-action-pypi-publish@release/v1 |