Skip to content

bump version number #54

bump version number

bump version number #54

name: Publish to PyPI
on:
push:
branches:
- main # 或你用来发布的分支
jobs:
build-and-publish:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10.14
- name: Install poetry
run: |
pip install poetry
- name: mint API token
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: Configure poetry
run: |
poetry config pypi-token.pypi ${{ steps.mint-token.outputs.api-token }}
- name: Parse version
id: parse_version
run: |
VERSION=$(poetry version -s)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Check if version exists on PyPI
id: check_version
run: |
response=$(curl -s https://pypi.org/pypi/codelinker/$VERSION/json)
if echo "$response" | grep -q 'Not Found'; then
echo "Version $VERSION does not exist on PyPI. Proceeding with publish."
echo "exists=false" >> $GITHUB_ENV
else
echo "Version $VERSION already exists on PyPI. Skipping publish."
echo "exists=true" >> $GITHUB_ENV
fi
- name: Build and publish
if: env.exists == 'false'
run: |
poetry build
poetry publish