CI #766
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
name: CI | |
# the "Generate comparison results" workflow will trigger | |
# push / pull request events on `main` or `develop`. | |
on: | |
workflow_run: | |
workflows: [Generate comparison results] | |
types: | |
- completed | |
jobs: | |
package: | |
name: Test package (${{ matrix.py }} on ${{ matrix.os }}) | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
py: | |
- "3.11" | |
- "3.10" | |
- "3.9" | |
- "3.8" | |
os: | |
- ubuntu-latest | |
- macos-latest | |
- windows-latest | |
exclude: | |
# Issue with python build | |
- os: windows-latest | |
py: "3.8" | |
# Intermittent CI test failures | |
- os: windows-latest | |
py: "3.11" | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up latest Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.py }} | |
cache: 'pip' | |
- name: Build and install package | |
shell: bash | |
run: | | |
python3 -m pip install --upgrade pip | |
python3 -m pip install build | |
python3 -m build | |
python3 -m pip install dist/curvesim*.whl | |
# ensure tests hit installed package | |
rm -r curvesim | |
- name: Download comparison results | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-data-${{ github.event.workflow_run.head_sha }} | |
path: test/data/ | |
- name: End-to-end tests | |
run: | | |
python3 -m test.simple_ci | |
source: | |
name: Test source with coverage | |
runs-on: ubuntu-latest | |
permissions: | |
# Gives the action the necessary permissions for publishing new | |
# comments in pull requests. | |
pull-requests: write | |
# Gives the action the necessary permissions for pushing data to the | |
# python-coverage-comment-action branch, and for editing existing | |
# comments (to avoid publishing multiple comments in the same PR) | |
contents: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up latest Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Format | |
run: | | |
black --version | |
black . --check | |
- name: Lint | |
run: | | |
make lint | |
- name: Unit tests | |
run: | | |
# coverage run -m pytest | |
pytest --cov -n auto --cov-report= | |
- name: Download comparison results | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-data-${{ github.event.workflow_run.head_sha }} | |
path: test/data/ | |
- name: End-to-end tests | |
run: | | |
# coverage run -m test.ci | |
coverage run -m test.simple_ci | |
- name: Download coverage badge | |
uses: chanhosuh/get-gist-action@master | |
id: covbadge | |
with: | |
gistURL: "https://gist.github.com/chanhosuh/3da3c072e081f4509ebdd09c63e6ede5" | |
- name: Coverage report | |
run: | | |
# combine coverage results from the previous steps | |
# and checks if score decreased since last CI run | |
coverage combine --append | |
BADGE_JSON=`cat ${{ steps.covbadge.outputs.file }}` | |
COVERAGE_SCORE=$(python3 -c "import json; score=json.loads('${BADGE_JSON}')['message'].rstrip('%'); print(score)") | |
coverage report --fail-under="${COVERAGE_SCORE:-0}" | |
echo "COVERAGE_SCORE=`coverage report --format=total`" >> $GITHUB_ENV | |
- name: Upload coverage badge | |
uses: schneegans/dynamic-badges-action@v1.6.0 | |
if: github.ref == 'refs/heads/main' | |
with: | |
auth: ${{ secrets.GIST_TOKEN }} # personal access token with scope "gist" | |
gistID: 3da3c072e081f4509ebdd09c63e6ede5 # id of previously created gist | |
filename: curvesim_coverage_badge.json | |
label: Coverage | |
message: ${{ env.COVERAGE_SCORE }}% | |
minColorRange: 50 | |
maxColorRange: 90 | |
valColorRange: ${{ env.COVERAGE_SCORE }}% | |
- name: Commit coverage report | |
id: coverage_comment | |
uses: py-cov-action/python-coverage-comment-action@v3 | |
with: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Store PR comment for posting | |
uses: actions/upload-artifact@v3 | |
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' | |
with: | |
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly | |
name: python-coverage-comment-action | |
# If you use a different name, update COMMENT_FILENAME accordingly | |
path: python-coverage-comment-action.txt |