Skip to content

Commit

Permalink
separate jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
cpelley committed Aug 29, 2024
1 parent 2ce22cc commit a88e89d
Showing 1 changed file with 53 additions and 32 deletions.
85 changes: 53 additions & 32 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,54 @@ on: [pull_request]


jobs:
test:
lower-bound-packages:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
strategy:
matrix:
include:
# lower bound version of packages
- python-version: '3.9'
pip-args: '.[tests,dev,minver]'
label: 'lower-bound'
# upper bound version of packages (unpinned)
- python-version: '3.x'
pip-args: '.[tests,dev]'
label: 'unpinned'

steps:
# SETUP
############################
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Ensure branch is checked out, not detached state (so we can push a commit later)
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
cache: 'pip'

- name: Add checkout directory to PYTHONPATH
run: echo "PYTHONPATH=$(pwd):$PYTHONPATH" >> $GITHUB_ENV

- name: Install dependencies
id: install-dependencies
run: |
pip install .[tests,minver]
pip uninstall dagrunner -y
- name: Set up SSH for localhost
run: |
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh-keyscan -H $(hostname) >> ~/.ssh/known_hosts
chmod 600 ~/.ssh/authorized_keys
# TESTS
############################
- name: Run pytest
run: pytest .


unpinned-packages:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest

steps:
# SETUP
############################
- name: Checkout code
uses: actions/checkout@v4
with:
Expand All @@ -31,7 +61,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: 3.x
cache: 'pip'

- name: Add checkout directory to PYTHONPATH
Expand All @@ -40,7 +70,7 @@ jobs:
- name: Install dependencies
id: install-dependencies
run: |
pip install ${{ matrix.pip-args }}
pip install .[tests,dev]
pip uninstall dagrunner -y
- name: Set up SSH for localhost
Expand All @@ -51,13 +81,12 @@ jobs:
chmod 600 ~/.ssh/authorized_keys
# TESTS (inc. test coverage)

# excluded logging as per https://github.com/MetOffice/dagrunner/issues/39
############################
- name: Run pytest + coverage report gen
run: pytest --cov=dagrunner --cov-report=term --cov-report=html | tee coverage_output.txt; test ${PIPESTATUS[0]} -eq 0

# TESTS (main branch)

# TESTS ('main' branch)
############################
- name: Cache ref branch coverage report
id: cache-ref-coverage
uses: actions/cache@v4
Expand All @@ -72,18 +101,16 @@ jobs:
path: ref
ref: ${{ github.base_ref }}

# excluded logging as per https://github.com/MetOffice/dagrunner/issues/39
- name: Run tests with coverage for ref branch
if: steps.cache-ref-coverage.outputs.cache-hit != 'true'
run: |
cd ref
pytest --cov=dagrunner --cov-report=term --cov-report=html | tee coverage_output.txt; test ${PIPESTATUS[0]} -eq 0
# TESTS (compare coverage)

############################
- name: Compare coverage
id: comp-coverage
if: ${{ matrix.label == 'unpinned' }}
run: |
pr_coverage_total=$(grep TOTAL coverage_output.txt | awk '{print $NF}' | awk '{print substr($0, 1, length($0)-1)}')
echo "pr_coverage_total=$pr_coverage_total" | tee -a $GITHUB_OUTPUT
Expand All @@ -96,7 +123,7 @@ jobs:
fi
- name: Comment coverage report
if: ${{ matrix.label == 'unpinned' && steps.comp-coverage.outputs.coverage_decreased == 'true' }}
if: steps.comp-coverage.outputs.coverage_decreased == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -113,7 +140,7 @@ jobs:
});
- name: Upload coverage report
if: ${{ matrix.label == 'unpinned' && steps.comp-coverage.outputs.coverage_decreased == 'true' }}
if: steps.comp-coverage.outputs.coverage_decreased == 'true'
uses: actions/upload-artifact@v4
with:
name: coverage-report-pr
Expand All @@ -122,39 +149,33 @@ jobs:
htmlcov/
# PRE-COMMIT

############################
- name: Python interpreter version sha (PYSHA)
if: ${{ matrix.label == 'unpinned' }}
run: echo "PYSHA=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV

- name: Cache pre-commit
if: ${{ matrix.label == 'unpinned' }}
uses: actions/cache@v3
id: pre-commit-cache
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PYSHA }}|${{ hashFiles('.pre-commit-config.yaml') }}

- name: pre-commit install
if: ${{ matrix.label == 'unpinned' }}
run: |
pre-commit install
- name: pre-commit run
if: ${{ matrix.label == 'unpinned' }}
run: |
pre-commit run --all-files
# DOCUMENTATION

############################
- name: Build documentation
if: ${{ matrix.label == 'unpinned' }}
run: |
./docs/gen_docs dagrunner ./docs
- name: Check if documentation has changed
id: check-docs
if: ${{ matrix.label == 'unpinned' }}
run: |
echo "changed=$(git diff --quiet --exit-code || echo true)" | tee -a $GITHUB_OUTPUT
Expand All @@ -163,7 +184,7 @@ jobs:
# success of all previous steps. A pushed commit will not trigger the re-running
# of this workflow.
- name: Commit and push documentation changes
if: ${{ matrix.label == 'unpinned' && steps.check-docs.outputs.changed == 'true' }}
if: steps.check-docs.outputs.changed == 'true'
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
Expand Down

0 comments on commit a88e89d

Please sign in to comment.