Skip to content

Commit

Permalink
fix(package): Added build to release step.
Browse files Browse the repository at this point in the history
No more artifacts.
Added caching for dependencies.
Added verification that the provided is semver.
  • Loading branch information
acederberg committed Aug 22, 2024
1 parent 21bf65f commit 95de50f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 38 deletions.
69 changes: 56 additions & 13 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,76 @@
name: Package and Release
on:
push:
# NOTE: From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
tags: ["0.*"]
workflow_dispatch:
inputs:
release_notes:
required: false
description: 'Override release notes (default uses tag body).'

jobs:
release:
runs-on: ubuntu-latest
needs: bumpver
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.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: |
tag_body=$( git tag -l --format='%(contents:body)' 0.1.5 )
echo "CAPTURA_TAG_BODY=$tag_body" >> $GITHUB_ENV
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: Get Artifacts.
uses: actions/download-artifact@v4
- name: Cache Pip
uses: actions/cache@v3
id: release-venv
with:
name: captura-build-${{ github.ref_name }}
github-token: ${{ secrets.GH_PAT }}
path: ./dist
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 build twine
- name: Build and Verify.
id: release-build-and-verify
run: |
echo "## Build\n\n~~~stdout" >> $GITHUB_STEP_SUMMARY
python3 -m 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
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
Expand All @@ -39,8 +82,8 @@ jobs:
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: Version ${{ github.ref_name }}
body: ${{ env.TAG_BODY }}
release_name: v${{ github.ref_name }}
body: ${{ env.CAPTURA_RELEASE_NOTES }}
draft: false
prerelease: false

Expand Down
49 changes: 24 additions & 25 deletions .github/workflows/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,34 @@ jobs:
with:
python-version: '3.11'

- name: Cache Pip
uses: actions/cache@v3
id: bumpver-venv
with:
path: .venv
key: ${{ runner.os }}-venv-release

- name: Install Dependencies.
id: bumpver-depends
run: |
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install build twine bumpver
# NOTE: This will not be published so it is fine that it happens at this
# stage.
- name: Build and Verify.
id: bumpver-build-and-verify
run: |
source .venv/bin/activate
echo "## Build\n\n~~~stdout" >> $GITHUB_STEP_SUMMARY
python3 -m 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: Increment Version.
id: bumpver-update
run: |
Expand All @@ -75,31 +99,6 @@ jobs:
--commit
fi
echo "CAPTURA_VERSION=$( python -m bumpver --version )" >> $GITHUB_ENV
- name: Build and Verify.
id: bumpver-verify
run: |
echo "## Build\n\n~~~stdout" >> $GITHUB_STEP_SUMMARY
python3 -m 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
# NOTE: https://github.com/actions/upload-artifact
- name: Publish Artifact.
id: bumpver-artifact
uses: actions/upload-artifact@v4
with:
name: captura-build-${{ env.CAPTURA_VERSION }}
path: ./dist
retention-days: 1
if-no-files-found: error
overwrite: true

- name: Push.
id: bumpver-push
run: |
git push
git push --tags
Expand Down

0 comments on commit 95de50f

Please sign in to comment.