Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GH Action GitHub + PyPI release automation on git version tag pushes #265

Merged
merged 8 commits into from
Nov 10, 2020
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
on:
push:
tags:
- "v*" # Push events to matching `v*` version srings. e.g. v1.0, v20.15.10

name: Create and Publish Release

jobs:
build:
name: Create and Publish Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install release dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel twine

- name: Get release notes
id: release_notes
run: |
# By default, GH Actions checkout will only fetch a single commit.
# For us to extract the release notes, we need to fetch the tags
# and tag annotations as well.
# https://github.com/actions/checkout/issues/290
git fetch --tags --force
TAG_NAME=${GITHUB_REF/refs\/tags\//}
CHANGELOG=$(git tag -l --format='%(contents)' $TAG_NAME)
# we have to escape all new line characters and carriage
# returns before passing them into set-output otherwise the
# body content of the release will only contain the first line
# https://github.com/actions/create-release/issues/38#issuecomment-640072234
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
echo "::set-output name=changelog::$CHANGELOG"

- name: Create GitHub release
id: create_release
# create-release@v1 doesn't support the body arg so we use
# create-release@master instead.
uses: actions/create-release@master
m4rc1e marked this conversation as resolved.
Show resolved Hide resolved
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
# To set the body arg, we fetch the changelog variable we created
# in the previous step. Implementation is based on
# the third example in https://github.com/actions/create-release/pull/11
body: ${{ steps.release_notes.outputs.changelog }}
draft: false
prerelease: false

- name: Build and publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
m4rc1e marked this conversation as resolved.
Show resolved Hide resolved
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*