Publish to PyPI #704
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
name: Publish to PyPI | |
on: | |
workflow_dispatch: | |
schedule: | |
# Run every day at midnight UTC (4 or 5 PM Pacific, depending on daylight savings) | |
- cron: '0 0 * * *' | |
jobs: | |
bugswarm-common: | |
name: Publish ${{ matrix.artifact-name }} to PyPI | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
artifact-name: | |
- bugswarm-common-build | |
- bugswarm-client-build | |
permissions: | |
# Permission to publish with a Trusted Publisher: https://docs.pypi.org/trusted-publishers/using-a-publisher/#the-easy-way | |
id-token: write | |
steps: | |
# Because actions/download-artifact can only download artifacts from the same workflow run, | |
# we have to get it ourselves from the API | |
- name: Get artifact download URL | |
uses: actions/github-script@v6 | |
id: get-download-url | |
# We don't want to fail the entire job if there aren't any new artifacts. | |
# Make sure that all later steps check that steps.get-download-url.outcome == 'success'. | |
continue-on-error: true | |
env: | |
ARTIFACT_NAME: ${{ matrix.artifact-name }} | |
with: | |
result-encoding: string | |
script: | | |
const { ARTIFACT_NAME } = process.env; | |
const mostRecentArtifact = (await github.rest.actions.listArtifactsForRepo({ | |
...context.repo, | |
name: ARTIFACT_NAME, | |
})).data.artifacts[0]; | |
const creationTime = new Date(mostRecentArtifact.created_at); | |
const currentTime = new Date(); | |
if (currentTime - creationTime > 86400000) throw "No new artifacts to push"; | |
return mostRecentArtifact.archive_download_url; | |
- name: Download and extract artifact | |
if: steps.get-download-url.outcome == 'success' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
DOWNLOAD_URL: ${{ steps.get-download-url.outputs.result }} | |
run: | | |
wget --header "Authorization: token $GITHUB_TOKEN" -O artifact.zip "$DOWNLOAD_URL" | |
unzip -d dist artifact.zip | |
- name: Upload to TestPyPI | |
if: github.repository == 'BugSwarm/bugswarm-dev' && steps.get-download-url.outcome == 'success' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository_url: https://test.pypi.org/legacy/ | |
- name: Upload to PyPI | |
if: github.repository == 'BugSwarm/bugswarm' && steps.get-download-url.outcome == 'success' | |
uses: pypa/gh-action-pypi-publish@release/v1 |