This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
first commit #2
This file contains 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
# .github/workflows/workflow.yaml | |
name: Publish | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install Poetry and Packages | |
run: | | |
curl -sSL https://install.python-poetry.org | python3 - | |
poetry install | |
- name: Determine Version Change | |
id: version_check | |
run: | | |
VERSION="v$(poetry version -s)" | |
echo "Current version: $VERSION" | |
LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ github.token }}" \ | |
https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name') | |
echo "Latest release version: $LATEST_RELEASE" | |
if [ "$VERSION" != "$LATEST_RELEASE" ]; then | |
echo "Version has changed." | |
echo "version_changed=true" >> $GITHUB_OUTPUT | |
echo "new_version=$VERSION" >> $GITHUB_OUTPUT | |
else | |
echo "No version change detected." | |
echo "version_changed=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Create Release | |
if: steps.version_check.outputs.version_changed == 'true' | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ steps.version_check.outputs.new_version }} | |
generate_release_notes: True | |
- name: mint API token | |
if: steps.version_check.outputs.version_changed == 'true' | |
id: mint-token | |
run: | | |
# retrieve the ambient OIDC token | |
resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ | |
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi") | |
oidc_token=$(jq -r '.value' <<< "${resp}") | |
# exchange the OIDC token for an API token | |
resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}") | |
api_token=$(jq -r '.token' <<< "${resp}") | |
# mask the newly minted API token, so that we don't accidentally leak it | |
echo "::add-mask::${api_token}" | |
# see the next step in the workflow for an example of using this step output | |
echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}" | |
- name: Build and publish to PyPI | |
if: steps.version_check.outputs.version_changed == 'true' | |
run: | | |
poetry build | |
poetry publish -u __token__ -p ${{ steps.mint-token.outputs.api-token }} |