-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 MAINTAIN: Add release workflow (#117)
- Loading branch information
1 parent
a053f2a
commit bc256ea
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
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
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}" |
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
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 }} |