Skip to content

Commit

Permalink
🔧 MAINTAIN: Add release workflow (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Sep 7, 2021
1 parent a053f2a commit bc256ea
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/check_release_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Check that the GitHub release tag matches the package version."""
import argparse
import pathlib
import re

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("GITHUB_REF", help="The GITHUB_REF environmental variable")
parser.add_argument("INIT_PATH", help="Path to the init file")
args = parser.parse_args()
assert args.GITHUB_REF.startswith(
"refs/tags/v"
), f'GITHUB_REF should start with "refs/tags/v": {args.GITHUB_REF}'
tag_version = args.GITHUB_REF[11:]
data = pathlib.Path(args.INIT_PATH).read_text("utf8")
pypi_version = re.search(r"__version__ = ['\"](.*?)['\"]", data).group(1)
assert (
tag_version == pypi_version
), f"The tag version {tag_version} != {pypi_version} specified in {args.INIT_PATH}"
62 changes: 62 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: release

# Automate deployment to PyPI when creating a release tag vX.Y.Z
# will only be published to PyPI if the git tag matches the release version
# and the pre-commit and tests pass

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"

jobs:

check-release-tag:

# Only run this job on the main repository and not on forks
if: github.repository == 'aiidateam/disk-objectstore'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- run: python .github/workflows/check_release_tag.py $GITHUB_REF disk_objectstore/__init__.py

pre-commit:

runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: pre-commit/[email protected]

publish:

name: Publish to PyPI
needs: [check-release-tag, pre-commit]
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Build package
run: |
pip install wheel
python setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_KEY }}

0 comments on commit bc256ea

Please sign in to comment.