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

Improve CI #219

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
76 changes: 76 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Create Release

on:
create

jobs:
create-release:
if: startsWith(github.ref_name, 'version-') && endsWith(github.ref_name, '-create-release')
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Setup
id: setup
run: |
# install python dependencies
pip install typer==0.4.0

# variables
RELEASE_VERSION='${{ github.ref_name }}'
RELEASE_VERSION=${RELEASE_VERSION//version-/}
RELEASE_VERSION=${RELEASE_VERSION//-create-release/}
echo "::set-output name=RELEASE_VERSION::${RELEASE_VERSION}"


- name: Test Environment
run: |
RELEASE_VERSION='${{ steps.setup.outputs.RELEASE_VERSION }}'

# setup git
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

# switch to master
git pull origin master
git checkout master

# update version
python scripts/update_version.py $RELEASE_VERSION
git commit -am "Update version to $RELEASE_VERSION"

# create tag
git fetch --tags
git tag $RELEASE_VERSION

# push to master
git push
git push --tags

# delete branch
git push -d origin ${{ github.ref_name }}

- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v2.9.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
toTag: ${{ steps.setup.outputs.RELEASE_VERSION }}

- name: Create Release
uses: actions/create-release@v1
with:
tag_name: ${{ steps.setup.outputs.RELEASE_VERSION }}
release_name: ${{ steps.setup.outputs.RELEASE_VERSION }}
body: ${{ steps.github_release.outputs.changelog }}
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46 changes: 46 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish Package
on:
release:
types: [published]
jobs:
publish-docs-and-package:
name: Publish Docs and Package
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install Poetry 📖
uses: snok/install-poetry@v1.1.1
with:
version: 1.1.4

- name: Install Dependencies
run: |
poetry config virtualenvs.create false
pip install -U certifi
poetry install

- name: Build Docs 🔨
run: |
cp README.md docs/index.md
python scripts/update_docs.py
mkdocs build

- name: Deploy Page 🚀
uses: JamesIves/github-pages-deploy-action@4.1.6
with:
branch: gh-pages
folder: site

- name: Publish to PyPI
run: |
poetry build
poetry publish \
--username ${{ secrets.PYPI_USERNAME }} \
--password ${{ secrets.PYPI_PASSWORD }}
18 changes: 6 additions & 12 deletions .github/workflows/ci_test.yml → .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Checks that we can build and validate the Unittest
name: GitHub CI
name: Run Tests
on:
push:
# Sequence of patterns matched against refs/heads
branches:
# Push events on master branch
- master
pull_request:
jobs:
Expand All @@ -15,11 +13,11 @@ jobs:
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.3
test:
name: Run Tests
if: ${{ !contains(github.event.pull_request.title, 'WIP') }}
runs-on: ubuntu-latest
strategy:
matrix:
# python-version: [3.9]
python-version: [3.7, 3.8, 3.9]
steps:
- name: Check out the code
Expand All @@ -39,6 +37,7 @@ jobs:
- name: Install Dependencies
run: |
poetry config virtualenvs.create false
pip install -U certifi
poetry install

- name: Run Tests
Expand All @@ -47,11 +46,6 @@ jobs:
- name: Upload coverage
uses: codecov/codecov-action@v1

# test_cloudpickle is currently failing only within pytest on python 3.7.x
# so we run it independently here
- name: Test cloudpickle
run: python tests/model/model_test.py

- name: Test Examples
run: bash scripts/test-examples.sh

Expand All @@ -61,7 +55,6 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# python-version: [3.9]
python-version: [3.7, 3.8, 3.9]
steps:
- name: Check out the code
Expand All @@ -80,8 +73,9 @@ jobs:

- name: Install Dependencies
run: |
pip install -U certifi
poetry config virtualenvs.create false
poetry install --no-dev

- name: Import Elegy
- name: Test Import Elegy
run: python -c "import elegy"
35 changes: 35 additions & 0 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import re
from pathlib import Path

import typer


# NOTE: this script could be written bash using sed, but I'm not sure if it's worth it
def main(release_name: str):
release_name = release_name.replace("-create-release", "")

# Update pyproject.toml
pyproject_path = Path("pyproject.toml")
pyproject_text = pyproject_path.read_text()
pyproject_text = re.sub(
r'version = ".*"',
f'version = "{release_name}"',
pyproject_text,
count=1,
)
pyproject_path.write_text(pyproject_text)

# Update __init__.py
init_path = Path("elegy", "__init__.py")
init_text = init_path.read_text()
init_text = re.sub(
r'__version__ = "(.*?)"',
f'__version__ = "{release_name}"',
init_text,
count=1,
)
init_path.write_text(init_text)


if __name__ == "__main__":
typer.run(main)