Skip to content

Commit 0399fe1

Browse files
committed
ci: add github workflow to publish
1 parent 5a4fb9f commit 0399fe1

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish Python 🐍 distributions 📦
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
publish_testpypi:
7+
type: boolean
8+
default: false
9+
description: Publish to TestPyPI
10+
publish_pypi:
11+
type: boolean
12+
default: false
13+
description: Publish to PyPI
14+
publish_gh_release:
15+
type: boolean
16+
default: true
17+
description: Publish to GitHub Release
18+
use_changelog:
19+
type: boolean
20+
default: true
21+
description: Extract release notes from CHANGELOG.md
22+
changelog_file:
23+
type: string
24+
default: CHANGELOG.md
25+
description: Path to changelog file
26+
required: false
27+
release_tag:
28+
type: string
29+
description: Tag to package (empty for latest tag)
30+
required: false
31+
32+
jobs:
33+
get-tag:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
release_tag: ${{ steps.set_release_tag.outputs.tag }}
37+
steps:
38+
- name: Checkout code
39+
uses: actions/checkout@v4
40+
- name: Fetch all tags
41+
run: |
42+
git fetch --prune --unshallow --tags
43+
- name: Verify and set release tag
44+
id: set_release_tag
45+
run: |
46+
release_tag=${{ inputs.release_tag }}
47+
if [ -z "$release_tag" ]; then
48+
echo "Input tag is empty. Fetching latest tag."
49+
release_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
50+
if [ -z "$release_tag" ]; then
51+
echo "No latest tag available. Exiting workflow."
52+
exit 1
53+
fi
54+
else
55+
if ! git rev-parse -q --verify "refs/tags/$release_tag" >/dev/null; then
56+
echo "Invalid tag '$release_tag'. Exiting workflow."
57+
exit 1
58+
fi
59+
fi
60+
echo "tag=$release_tag" >> $GITHUB_OUTPUT
61+
build-n-publish:
62+
needs: get-tag
63+
permissions:
64+
id-token: write # IMPORTANT: mandatory for trusted publishing and sigstore
65+
contents: write # IMPORTANT: mandatory for making GitHub Releases
66+
uses: atomiechen/reusable-workflows/.github/workflows/publish-python-distributions.yml@main
67+
with:
68+
publish_testpypi: ${{ inputs.publish_testpypi }}
69+
publish_pypi: ${{ inputs.publish_pypi }}
70+
publish_gh_release: ${{ inputs.publish_gh_release }}
71+
use_changelog: ${{ inputs.use_changelog }}
72+
changelog_file: ${{ inputs.changelog_file }}
73+
release_tag: ${{ needs.get-tag.outputs.release_tag }}
74+
secrets:
75+
TEST_PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
76+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)