-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (115 loc) · 4.64 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Pull Request Tests
on: [pull_request]
jobs:
test:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
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: Cache pip environment
id: cache-pip-env
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-${{ hashFiles('pyproject.toml') }}
restore-keys: pip-
- name: Install dependencies
id: install-dependencies
run: |
pip install .[tests,dev]
pip uninstall dagrunner -y
# TESTS (inc. test coverage)
- name: Run pytest + coverage report gen
run: pytest --cov=dagrunner --cov-report=term | tee coverage_output.txt
# TESTS (main branch)
- name: Cache ref branch coverage report
id: cache-ref-coverage
uses: actions/cache@v4
with:
path: ref/coverage_output.txt
key: ref-${{ github.event.pull_request.base.sha }}
- name: Checkout ref branch
if: steps.cache-ref-coverage.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
path: ref
ref: ${{ github.base_ref }}
- 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 | tee coverage_output.txt
# TESTS (compare coverage)
- name: Compare coverage
run: |
echo "pr_coverage_total=$(grep TOTAL coverage_output.txt | awk '{print $NF}' | awk '{print substr($0, 1, length($0)-1)}')" | tee -a $GITHUB_ENV
echo "ref_coverage_total=$(grep TOTAL ref/coverage_output.txt | awk '{print $NF}' | awk '{print substr($0, 1, length($0)-1)}')" | tee -a $GITHUB_ENV
if (( $pr_coverage_total < $ref_coverage_total )); then
echo "COVERAGE_DECREASED=true" | tee -a $GITHUB_ENV
else
echo "COVERAGE_DECREASED=false" | tee -a $GITHUB_ENV
fi
- name: Comment coverage report
if: env.COVERAGE_DECREASED == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comment = "The test coverage has decreased from '${{ env.main_coverage_total }}%' to '${{ env.pr_coverage_total }}%'.\nPlease review test coverage. Summary report uploaded as artifact.";
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Upload coverage report
if: env.COVERAGE_DECREASED == 'true'
uses: actions/upload-artifact@v4
with:
name: coverage-report-pr
path: coverage_output.txt
# PRE-COMMIT
- name: Python interpreter version sha (PYSHA)
run: echo "PYSHA=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- name: Cache pre-commit
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
run: |
pre-commit install
- name: pre-commit run
run: |
pre-commit run --all-files
# DOCUMENTATION
- name: Build documentation
run: |
./docs/gen_docs dagrunner ./docs
- name: Check if documentation has changed
id: check-docs
run: |
git diff --quiet --exit-code || echo "::set-output name=changed::true"
# https://github.com/orgs/community/discussions/26560#discussioncomment-3531273
- name: Commit and push documentation changes
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
git commit -am "Automated reference documentation update for PR ${{ github.event.number }} [skip ci]"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}