arcade-mcp/.github/workflows/publish-toolkit.yml
Eric Gustin 8795871d51
Check if toolkit version changed before attempting publish (#198)
# PR Description
Changes to a toolkit without changes to the toolkit's version fail the
'Publish Toolkit' workflow with `HTTP Error 400: File already exists
('arcade_zoom-0.1.7.tar.gz', with blake2_256 hash
'02183cda607f06616e7edb17e3d22bc11d1d83b074b3e44066b78ec72602fb37'). See
https://pypi.org/help/#file-name-reuse for more information.`, for
example.

This PR adds the `--skip-existing` flag to `poetry publish` to avoid
attempting to publish an existing version. Skips slack notification if
publish is skipped.


The `grep`'d string comes from
https://github.com/python-poetry/poetry/blob/main/src/poetry/publishing/uploader.py#L246-L249
2025-01-13 10:00:24 -08:00

80 lines
2.5 KiB
YAML

name: Publish Toolkit
on:
workflow_dispatch:
inputs:
toolkit:
description: 'The directory of the toolkit to publish'
required: true
jobs:
release-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Set toolkit input
id: set-toolkit
run: |
if [ "${{ github.event_name }}" = "push" ]; then
# Extract toolkit name from changed files
TOOLKIT=this_is_for_testing
echo "toolkit=$TOOLKIT" >> $GITHUB_OUTPUT
else
echo "toolkit=${{ inputs.toolkit }}" >> $GITHUB_OUTPUT
fi
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.5
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Test Toolkit
id: Test_Toolkit
working-directory: toolkits/${{ steps.set-toolkit.outputs.toolkit }}
run: |
make install
make check
make test
- name: Publish Toolkit
# Publish the toolkit to PyPI if the version is not already published
id: Publish_Toolkit
working-directory: toolkits/${{ steps.set-toolkit.outputs.toolkit }}
run: |
poetry build
# Extract version from pyproject.toml using poetry and save it
VERSION=$(poetry version -s)
echo "version=$VERSION" >> $GITHUB_OUTPUT
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
# Attempt to publish the toolkit to PyPI. Skip if the version already exists
if poetry publish --skip-existing 2>&1 | grep -q "File exists. Skipping"; then
echo "Version already exists on PyPI. Skipping publish."
echo "skip_publish=true" >> $GITHUB_OUTPUT
else
echo "skip_publish=false" >> $GITHUB_OUTPUT
fi
- name: Send status to Slack
if: steps.Publish_Toolkit.outputs.skip_publish != 'true'
uses: slackapi/slack-github-action@v2.0.0
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: webhook-trigger
payload: |
status: "${{ (steps.Test_Toolkit.outcome == 'failure' || steps.Publish_Toolkit.outcome == 'failure') && 'Failed' || 'Success' }}"
toolkit: ${{ steps.set-toolkit.outputs.toolkit }}
version: ${{ steps.Publish_Toolkit.outputs.version }}
url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"