Package and Release #5
Workflow file for this run
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: Package and Release | |
on: | |
workflow_dispatch: | |
inputs: | |
release_notes: | |
required: false | |
description: 'Override release notes (default uses tag body).' | |
release_version: | |
required: false | |
description: 'Override `github.ref_name`. Must be semver.' | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
# NOTE: https://github.com/actions/download-artifact | |
- name: Checkout. | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# NOTE Check that the ref matches semver. | |
- name: Verify Ref. | |
id: release-ref-verify | |
run: | | |
github_ref_name='${{ github.event.inputs.release_version }}' || '${{ github.ref_name }}' | |
if [[ \ | |
! $( \ | |
echo $github_ref_name \ | |
| grep '^\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)\(-[a-z0-9]\+\)\?$' \ | |
) \ | |
]]; then | |
echo 'Illegal git ref name `${{ github.ref_name }}`. Exitting.' | |
exit 1 | |
else | |
echo 'Valid git ref name `${{ github.ref_name }}`.' | |
fi | |
- name: Get Body. | |
id: release-get-body | |
run: | | |
release_notes='${{ github.event.inputs.release_notes }}' | |
if [[ ! $release_notes ]]; | |
then | |
tag_body=$( git tag -l --format='%(contents:body)' '${{ github.ref_name }}' ) | |
echo "CAPTURA_RELEASE_NOTES=$tag_body" >> $GITHUB_ENV | |
else | |
echo "CAPTURA_RELEASE_NOTES=$release_notes" >> $GITHUB_ENV | |
fi | |
- name: Cache Pip | |
uses: actions/cache@v3 | |
id: release-venv | |
with: | |
path: .venv | |
key: ${{ runner.os }}-venv-release | |
- name: Install Dependencies. | |
id: release-depends | |
run: | | |
python3 -m venv .venv | |
source .venv/bin/activate | |
python3 -m pip install twine poetry | |
- name: Build and Verify. | |
id: release-build-and-verify | |
run: | | |
source .venv/bin/activate | |
echo "## Build\n\n~~~stdout" >> $GITHUB_STEP_SUMMARY | |
poetry build >> $GITHUB_STEP_SUMMARY | |
echo "~~~\n\n## Twine Check\n\n~~~stdout" >> $GITHUB_STEP_SUMMARY | |
python3 -m twine check dist/* >> $GITHUB_STEP_SUMMARY | |
echo "~~~" >> $GITHUB_STEP_SUMMARY | |
- name: Publish to PyPI. | |
id: release-publish | |
run: | | |
source .venv/bin/activate | |
poetry config repositories.pypi pypi.org | |
poetry config pypi-token.pypi '${{ secrets.PYPI_TOKEN }}' | |
poetry publish | |
- name: Create Release | |
id: release-create | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
with: | |
tag_name: ${{ github.ref_name }} | |
release_name: v${{ github.ref_name }} | |
body: ${{ env.CAPTURA_RELEASE_NOTES }} | |
draft: false | |
prerelease: false | |