Auto-release #54
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
# Good example resources | |
# https://riggaroo.dev/using-github-actions-to-automate-our-release-process/ | |
# https://blog.eizinger.io/12274/using-github-actions-to-automate-gitflow-style-releases | |
name: Auto-release | |
on: | |
# The below workflow_dispatch section is for a "manual" kick off of the | |
# auto-release script. To cut a new release, navigate to the Actions section | |
# of the repo and select this workflow (Auto-release) on the right hand side. | |
# Then, click "Run workflow" and you will be prompted to input the new | |
# version (which should be major, minor, or patch). | |
workflow_dispatch: | |
inputs: | |
version_name: | |
description: "One of major, minor, or patch" | |
required: true | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
jobs: | |
release: | |
name: Create a new release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Pull latest commits of dev branch | |
run: | | |
git checkout dev | |
git pull | |
# See https://github.com/marketplace/actions/wait-on-check | |
# TODO: Fix this later (have every push to dev trigger a test suite run) | |
# - name: Ensure all tests are passing on dev | |
# uses: lewagon/[email protected] | |
# with: | |
# ref: dev # can be commit SHA or tag | |
# check-name: pyjanitor tests | |
# repo-token: ${{ secrets.GITHUB_TOKEN }} | |
# wait-interval: 60 # seconds | |
- name: Setup Python | |
uses: actions/setup-python@v2 | |
- name: Install bump2version and wheel | |
run: python -m pip install bumpversion wheel # "bumpversion" installs bump2version | |
- name: Dry run bumpversion | |
run: | | |
bumpversion --dry-run ${{ github.event.inputs.version_name }} --allow-dirty --verbose | |
# This is lifted directly from the bump2version docs. | |
# Version number will be saved in `env` section of each consecutive stage | |
- name: Store new version number | |
run: echo "version_number=`bumpversion --dry-run --list ${{ github.event.inputs.version_name }} | grep new_version | sed -r s,"^.*=",,`" >> $GITHUB_ENV | |
- name: Display new version number | |
run: | | |
echo "version_name: ${{ github.event.inputs.version_name }}" | |
echo "version_number: v${{ env.version_number }}" | |
# See https://github.com/thomaseizinger/keep-a-changelog-new-release | |
- name: Update Changelog | |
uses: thomaseizinger/keep-a-changelog-new-release@v1 | |
with: | |
version: v${{ env.version_number }} | |
- name: Commit CHANGELOG updates | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Bot" | |
git add . | |
git commit -m "Update CHANGELOG for auto-release v${{ env.version_number }}" | |
- name: Ensure repo status is clean | |
run: git status | |
- name: Run bumpversion | |
run: bumpversion ${{ github.event.inputs.version_name }} --verbose | |
- name: Ensure tag creation | |
run: git tag | grep ${{ env.version_number }} | |
- name: Build package | |
run: | | |
rm -f dist/* | |
pip install build | |
python -m build | |
- name: Publish package | |
uses: pypa/gh-action-pypi-publish@master | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
- name: Push changes with tags | |
run: git push && git push --tags | |
# This will create an actual pointer in the "Release" section of the GitHub repo | |
# The intent is to always have "latest" point to <this> release | |
- name: Create release in GitHub repo | |
uses: ncipollo/release-action@v1 | |
with: | |
body: "Contribution details can be found in CHANGELOG.md" | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: v${{ env.version_number}} | |
- name: Ensure complete | |
run: echo "Auto-release complete!" |