Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Add more checks to release workflow (#30)
Browse files Browse the repository at this point in the history
* improve release workflow

* ensure models plugin can be found

* simplify
  • Loading branch information
epwalsh authored Apr 28, 2020
1 parent dcc9674 commit 64185b8
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 4 deletions.
86 changes: 82 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,41 @@ on:
types: [published]

jobs:
deploy:
if: github.repository == 'allenai/allennlp-models'

build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.6', '3.7']

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: ${{ matrix.python }}

- name: Install requirements
run: |
pip install --upgrade pip setuptools wheel
pip install -e .
pip install -r dev-requirements.txt
- name: Check version and release tag match
run: |
# Remove 'refs/tags/' to get the actual tag from the release.
TAG=${GITHUB_REF#refs/tags/};
VERSION=$(scripts/get_version.py current)
if [ "$TAG" != "$VERSION" ]; then
echo "Bad tag or version. Tag $TAG does not match $VERSION";
exit 1;
fi
- name: Show pip freeze
run: |
pip freeze
- name: Lint
run: |
make lint
Expand All @@ -40,6 +56,68 @@ jobs:
run: |
python setup.py bdist_wheel sdist
- name: Save package
if: matrix.python == '3.7'
uses: actions/upload-artifact@v1
with:
name: models-package
path: dist

test:
name: Test
needs: [build] # needs the package artifact created from 'build_package' job.
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.6', '3.7']

steps:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}

- name: Install requirements
run: |
pip install --upgrade pip setuptools wheel
- name: Download models package
uses: actions/download-artifact@v1
with:
name: models-package
path: dist

- name: Install models package
run: |
pip install $(ls dist/*.whl)
- name: Ensure models plugin found
run: |
python -c 'from allennlp.common.plugins import discover_plugins; assert "allennlp_plugins.allennlp_models" in list(discover_plugins())'
publish:
name: PyPI
needs: [build, test]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.7

- name: Install requirements
run: |
pip install --upgrade pip setuptools wheel twine
- name: Download models package
uses: actions/download-artifact@v1
with:
name: models-package
path: dist

- name: Upload to PyPI
env:
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
Expand Down
45 changes: 45 additions & 0 deletions scripts/get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python

import argparse
from typing import Dict

import requests


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("version_type", choices=["stable", "latest", "current"])
return parser.parse_args()


def get_current_version() -> str:
VERSION: Dict[str, str] = {}
with open("allennlp_models/version.py", "r") as version_file:
exec(version_file.read(), VERSION)
return "v" + VERSION["VERSION"]


def get_latest_version() -> str:
resp = requests.get("https://api.github.com/repos/allenai/allennlp-models/tags")
return resp.json()[0]["name"]


def get_stable_version() -> str:
resp = requests.get("https://api.github.com/repos/allenai/allennlp-models/releases/latest")
return resp.json()["tag_name"]


def main() -> None:
opts = parse_args()
if opts.version_type == "stable":
print(get_stable_version())
elif opts.version_type == "latest":
print(get_latest_version())
elif opts.version_type == "current":
print(get_current_version())
else:
raise NotImplementedError


if __name__ == "__main__":
main()

0 comments on commit 64185b8

Please sign in to comment.