Skip to content

Commit

Permalink
Better CI/CD (#177)
Browse files Browse the repository at this point in the history
* Remove get_version

* Update CI with build, test, and publish
  • Loading branch information
marcosfelt authored Apr 25, 2022
1 parent 51f34d2 commit 8603fbd
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 61 deletions.
177 changes: 124 additions & 53 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test & Publish
name: Test and Publish
on:
push:
pull_request:
Expand All @@ -10,8 +10,8 @@ on:
- '**:**'

jobs:
#Run pytest and build package
test_build:
# Build the package
build:
runs-on: ubuntu-latest

steps:
Expand All @@ -21,62 +21,133 @@ jobs:
- name: Install python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.9'

- name: Install poetry
uses: Gr1N/setup-poetry@v4
uses: Gr1N/setup-poetry@v7

- name: Cache poetry dependencies
uses: actions/cache@v2
- name: Build package
run: poetry build

- name: Upload built package
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
retention-days: 1

# Run pytest using built package
test:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9"]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install python
uses: actions/setup-python@v2
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
python-version: ${{ matrix.python }}
cache: 'pip'
cache-dependency-path: "poetry.lock"

- name: Download built package
uses: actions/download-artifact@v3
with:
name: dist

- name: Install dependencies
run: poetry install -E experiments -E entmoot
- name: Install summit and pytest
shell: bash
run: |
WHL_NAME=$(ls summit-*.whl)
pip install ${WHL_NAME}[experiments,entmoot] pytest
- name: Run pytest
run: poetry run pytest --doctest-modules --ignore=experiments --disable-warnings
- name: Run tests
shell: bash
run: summit-tests

# Check that the build process works correctly
- name: Build package
run: poetry build

# Publish to pypi on version change
# This is based on https://github.com/coveooss/pypi-publish-with-poetry
publish:
needs: test_build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
# Make sure to fetch the last two commits
# Needed forthe version bump and tag
fetch-depth: 2

- name: Install python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install poetry
uses: Gr1N/setup-poetry@v4

- name: Install toml
run: pip install toml

- name: Check for version bump and tag
id: version_check
uses: salsify/action-detect-and-tag-new-version@v2
with:
tag-template: "{VERSION}"
create-tag: ${{ github.ref == 'refs/heads/master' }} # only create new tag on master
version-command: |
python get_version.py
- name: Publish
# Only publish if there is a new tag
if: ${{ steps.version_check.tag }}
run: poetry publish --build -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }}
needs: test
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Download built package
uses: actions/download-artifact@v3
with:
name: dist
path: dist/

- name: Install poetry
uses: Gr1N/setup-poetry@v7

- name: Install coveo-pypi-cli
run: pip install coveo-pypi-cli

- name: Determine the version for this release from the build
id: current
run: |
BUILD_VER="$(ls dist/summit-*.tar.gz)"
echo "Path: $BUILD_VER"
if [[ $BUILD_VER =~ (summit-)([^,][0-9.]{4}) ]]; then
echo "::set-output name=version::${BASH_REMATCH[2]}"
echo "Version of build: ${BASH_REMATCH[2]}"
else
echo "No version found found"
fi
- name: Get latest published version
id: published
run: |
PUB_VER="$(pypi current-version summit)"
echo "::set-output name=version::$PUB_VER"
echo "Latest published version: $PUB_VER"

- name: Publish to pypi if new version
if: (steps.current.outputs.version != steps.published.outputs.version)
shell: bash
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
if [[ '${{ github.ref_name }}' == 'master' ]]; then
poetry publish
else
echo "Dry run of publishing the package"
poetry publish --dry-run
fi
- name: Tag repository
shell: bash
id: get-next-tag
if: (steps.current.outputs.version != steps.published.outputs.version)
run: |
TAG_NAME=${{ steps.current.outputs.version }}
echo "::set-output name=tag-name::$TAG_NAME"
echo "This release will be tagged as $TAG_NAME"
git config user.name "github-actions"
git config user.email "actions@users.noreply.github.com"
git tag --annotate --message="Automated tagging system" $TAG_NAME ${{ github.sha }}
- name: Push the tag
if: (steps.current.outputs.version != steps.published.outputs.version)
env:
TAG_NAME: ${{ steps.current.outputs.version }}
run: |
if [[ ${{ github.ref_name }} == 'master' ]]; then
git push origin $TAG_NAME
else
echo "If this was the master branch, I would push a new tag named $TAG_NAME"
fi
8 changes: 0 additions & 8 deletions get_version.py

This file was deleted.

12 changes: 12 additions & 0 deletions summit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ def clean_house(config_dir_name=".summit"):
from summit.benchmarks import *
from summit.utils.dataset import DataSet
from summit.utils.multiobjective import pareto_efficient, hypervolume


def run_tests():
"""Run tests using pytest"""
import pytest
from pytest import ExitCode
import sys

retcode = pytest.main(
["--doctest-modules", "--disable-warnings", "--pyargs", "summit"]
)
sys.exit(retcode)

0 comments on commit 8603fbd

Please sign in to comment.