v0.4.2 #48
Workflow file for this run
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: Build & Release PyPI Package | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
permissions: | |
attestations: write | |
contents: read | |
id-token: write | |
jobs: | |
build-package: | |
name: Build & verify package | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Needed for dynamic versioning to see all tags | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.13" | |
- name: Install Poetry & dynamic versioning plugin | |
run: | | |
pip install "poetry>=1.8.0" "poetry-dynamic-versioning[plugin]>=1.0.0" | |
- name: Build and inspect package | |
uses: hynek/build-and-inspect-python-package@v2 | |
with: | |
attest-build-provenance-github: "true" | |
release-pypi: | |
name: Publish released package to PyPI | |
environment: release-pypi | |
runs-on: ubuntu-latest | |
needs: build-package | |
if: github.event.action == 'published' || startsWith(github.ref, 'refs/tags/') | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.13" | |
- name: Install Poetry & dynamic versioning plugin | |
run: | | |
pip install "poetry>=1.8.0" "poetry-dynamic-versioning[plugin]>=1.0.0" | |
- name: Download built package | |
uses: actions/download-artifact@v4 | |
with: | |
name: Packages | |
path: dist | |
- name: Get dynamic version | |
id: get_version | |
run: echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT | |
- name: Check if version exists on PyPI | |
id: version_check | |
run: | | |
VERSION="${{ steps.get_version.outputs.version }}" | |
PKG="mkdocs-zettelkasten" | |
if curl -fsS "https://pypi.org/pypi/$PKG/json" | jq -e ".releases | has(\"$VERSION\")" > /dev/null; then | |
echo "exists=true" >> $GITHUB_OUTPUT | |
else | |
echo "exists=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Publish to PyPI | |
if: steps.version_check.outputs.exists == 'false' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
- name: Version exists in PyPI | |
if: steps.version_check.outputs.exists == 'true' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
core.setFailed('This version was already published to PyPI!') | |
- name: Clean up local build artifacts | |
if: always() | |
run: rm -rf dist/* | |
- name: Delete all workflow artifacts | |
if: always() | |
uses: geekyeggo/delete-artifact@v5 |