Release Python CLI or SDK #45
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: Release Python CLI or SDK | |
on: | |
workflow_dispatch: | |
inputs: | |
package: | |
type: choice | |
description: Publish which Python package? | |
options: | |
- cli | |
- sdk | |
jobs: | |
release-build: | |
runs-on: ubuntu-latest | |
outputs: | |
semver: ${{ steps.buildreleasedist.outputs.semver }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
- name: build release dist | |
id: buildreleasedist | |
working-directory: ./python/${{ inputs.package }} | |
run: | | |
python -m pip install -U build | |
python -m build | |
setup_semver=$(grep version setup.cfg | cut -d' ' -f3) | |
echo "semver=$setup_semver" >> "$GITHUB_OUTPUT" | |
- name: upload release dist | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-dist | |
path: ./python/${{ inputs.package }}/dist/ | |
pypi-publish: | |
environment: release | |
runs-on: ubuntu-latest | |
needs: | |
- release-build | |
permissions: | |
contents: write | |
id-token: write | |
steps: | |
- name: download release dist | |
uses: actions/download-artifact@v4 | |
with: | |
name: release-dist | |
path: dist/ | |
- name: publish release dist to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
- name: checkout for tagging | |
if: success() | |
uses: actions/checkout@v4 | |
- name: tag repo | |
if: success() | |
run: | | |
git config user.name "GitHub Action" | |
git config user.email "[email protected]" | |
tag="python/${{ inputs.package }}/${{ needs.release-build.outputs.semver }}" | |
git tag $tag | |
git push origin $tag | |
- name: Notify Slack | |
if: always() | |
uses: slackapi/[email protected] | |
with: | |
payload: | | |
{ | |
"text": "Python ${{ inputs.package }} published (${{ github.triggering_actor }}): ${{ github.ref }} - ${{ job.status }}", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "Python ${{ inputs.package }} published (${{ github.triggering_actor }}): ${{ github.ref }} - ${{ job.status }}" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.US1_SLACK_URL }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |