Skip to content

Commit 5d7a417

Browse files
committed
ISSUE-25: Refactor main pipeline
1 parent 730a8f0 commit 5d7a417

File tree

1 file changed

+121
-16
lines changed

1 file changed

+121
-16
lines changed

.github/workflows/main.yml

Lines changed: 121 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,175 @@
1-
name: Testing pipeline
1+
name: Typecheck & run tests
22

33
on:
44
push:
55
branches:
66
- 'main'
77
- 'feature/*'
88
- 'bugfix/*'
9+
issue_comment:
10+
types: [created]
911

1012
jobs:
11-
sanity-run:
13+
get-command:
1214
runs-on: ubuntu-latest
13-
name: Run tests on lowest supported Python version on Ubuntu as a sanity-check before doing anything else
15+
name: Get ref to check out (based on branch or PR)
16+
permissions:
17+
statuses: write
18+
steps:
19+
- name: Are we triggered by a known comment-command?
20+
id: get-command
21+
run: |
22+
doTypeCheck=${{ contains(github.event.comment.body, '/type-check') }}
23+
echo "doTypeCheck=$doTypeCheck" >> "$GITHUB_OUTPUT"
24+
doMutate=${{ contains(github.event.comment.body, '/mutate') }}
25+
echo "doMutate=$doMutate" >> "$GITHUB_OUTPUT"
26+
doCombos=${{ contains(github.event.comment.body, '/combos') }}
27+
echo "doCombos=$doCombos" >> "$GITHUB_OUTPUT"
28+
doAll=${{ contains(github.event.comment.body, '/all-tests') }}
29+
echo "doAll=$doAll" >> "$GITHUB_OUTPUT"
30+
commentCommand=false
31+
if [ "$doTypeCheck" = "true" ]; then
32+
commentCommand=true
33+
command="type-check"
34+
elif [ "$doMutate" = "true" ]; then
35+
commentCommand=true
36+
command="mutate"
37+
elif [ "$doCombos" = "true" ]; then
38+
commentCommand=true
39+
command="combos"
40+
elif [ "$doAll" = "true" ]; then
41+
commentCommand=true
42+
command="all"
43+
fi
44+
echo "commentCommand=$commentCommand" >> "$GITHUB_OUTPUT"
45+
echo "command=$command" >> "$GITHUB_OUTPUT"
46+
- name: Get PR's branch name
47+
id: from-pr
48+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
49+
run: |
50+
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }})
51+
echo "onPR=true" >> "$GITHUB_OUTPUT"
52+
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
53+
echo "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
54+
- name: Bind check in PR
55+
id: bind-pr
56+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
57+
uses: myrotvorets/[email protected]
58+
with:
59+
token: ${{ secrets.GITHUB_TOKEN }}
60+
sha: ${{ steps.from-pr.outputs.sha }}
61+
status: pending
62+
context: Run based on PR comment (${{ steps.get-command.outputs.command }})
63+
- name: Get current branch name
64+
id: from-branch
65+
if: ${{ steps.get-command.outputs.commentCommand != 'true' }}
66+
run: |
67+
echo "onPR=false" >> "$GITHUB_OUTPUT"
68+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
69+
echo "sha=..." >> "$GITHUB_OUTPUT"
70+
outputs:
71+
commentCommand: ${{ steps.get-command.outputs.commentCommand }}
72+
command: ${{ steps.get-command.outputs.command }}
73+
doTypeCheck: ${{ steps.get-command.outputs.doTypeCheck }}
74+
doMutate: ${{ steps.get-command.outputs.doMutate }}
75+
doCombos: ${{ steps.get-command.outputs.doCombos }}
76+
doAll: ${{ steps.get-command.outputs.doAll }}
77+
onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }}
78+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
79+
sha: ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }}
80+
81+
coverage:
82+
runs-on: ubuntu-latest
83+
name: Check coverage
84+
needs: [get-command]
1485
steps:
1586
- name: Checkout current branch
1687
uses: actions/checkout@v4
1788
with:
18-
ref: ${{ github.ref_name }}
89+
ref: ${{ needs.get-command.outputs.branch }}
1990
- uses: actions/setup-python@v5
2091
with:
2192
python-version: '3.9'
2293
- run: python -m pip install --upgrade setuptools virtualenv
2394
- run: pip install -r requirements-dev.txt
2495
- run: pytest --cov=hooks --cov-fail-under=100
2596

26-
main:
97+
type-check:
98+
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doTypeCheck == 'true' || needs.get-command.outputs.doAll == 'true' }}
2799
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
100+
name: Type checking
101+
needs: [get-command]
30102
steps:
31103
- name: Checkout current branch
32104
uses: actions/checkout@v4
33105
with:
34-
ref: ${{ github.ref_name }}
106+
ref: ${{ needs.get-command.outputs.branch }}
35107
- uses: actions/setup-python@v5
36108
with:
37-
python-version: '3.12'
109+
python-version: '3.9'
38110
- run: python -m pip install --upgrade setuptools virtualenv
39111
- run: pip install -r requirements-dev.txt
40112
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
113+
114+
mutate:
115+
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doMutate == 'true' || needs.get-command.outputs.doAll == 'true' }}
116+
runs-on: ubuntu-latest
117+
name: Mutation tests
118+
needs: [get-command, coverage]
119+
steps:
120+
- name: Checkout current branch
121+
uses: actions/checkout@v4
122+
with:
123+
ref: ${{ needs.get-command.outputs.branch }}
124+
- uses: actions/setup-python@v5
125+
with:
126+
python-version: '3.12'
127+
- run: python -m pip install --upgrade setuptools virtualenv
128+
- run: pip install -r requirements-dev.txt
129+
- run: pytest --cov=hooks
42130
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43131

44132
combos:
45-
if: github.ref == 'refs/heads/main'
133+
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doCombos == 'true' || needs.get-command.outputs.doAll == 'true' }}
46134
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
135+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
136+
needs: [get-command]
49137
strategy:
50138
matrix:
51139
os: [windows-latest, ubuntu-latest, macos-latest]
52140
env: ['3.9', '3.10', '3.11', '3.12']
53141
exclude:
54-
# exclude the sanity-run combo, no need to re-run it
142+
# exclude the coverage combo, no need to re-run it
55143
- os: ubuntu-latest
56144
env: '3.9'
57-
# exclude the main combo, no need to re-run it
145+
# exclude the mutate combo, no need to re-run it
58146
- os: ubuntu-latest
59147
env: '3.12'
60148
steps:
61149
- name: Checkout current branch
62150
uses: actions/checkout@v4
63151
with:
64-
ref: ${{ github.ref_name }}
152+
ref: ${{ needs.get-command.outputs.branch }}
65153
- uses: actions/setup-python@v5
66154
with:
67155
python-version: ${{ matrix.env }}
68156
- run: python -m pip install --upgrade setuptools virtualenv
69157
- run: pip install -r requirements-dev.txt
70158
- run: pytest
159+
160+
update-pr:
161+
if: ${{ always() }}
162+
runs-on: ubuntu-latest
163+
name: Report back in PR when triggered by comment
164+
permissions:
165+
statuses: write
166+
needs: [get-command, type-check, mutate, combos]
167+
steps:
168+
- name: Set final commit status
169+
uses: myrotvorets/[email protected]
170+
if: ${{ needs.get-command.outputs.commentCommand == 'true' }}
171+
with:
172+
token: ${{ secrets.GITHUB_TOKEN }}
173+
sha: ${{ needs.get-command.outputs.sha }}
174+
status: ${{ job.status }}
175+
context: Run based on PR comment (${{ needs.get-command.outputs.command }})

0 commit comments

Comments
 (0)