Skip to content

Commit 1ee1fd9

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

File tree

1 file changed

+114
-16
lines changed

1 file changed

+114
-16
lines changed

.github/workflows/main.yml

Lines changed: 114 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,168 @@
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-main-ref:
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+
echo "onPR=${{ contains(github.event.comment.html_url, '/pull/') }}" >> "$GITHUB_OUTPUT"
23+
echo "doTypeCheck=${{ contains(github.event.comment.body, '/type-check') }}" >> "$GITHUB_OUTPUT"
24+
echo "doMutate=${{ contains(github.event.comment.body, '/mutate') }}" >> "$GITHUB_OUTPUT"
25+
echo "doCombos=${{ contains(github.event.comment.body, '/combos') }}" >> "$GITHUB_OUTPUT"
26+
echo "doAll=${{ contains(github.event.comment.body, '/all-tests') }}" >> "$GITHUB_OUTPUT"
27+
echo "commentCommand=false" >> "$GITHUB_OUTPUT"
28+
if [ "$doTypeCheck" = "true" ]; then
29+
echo "commentCommand=true" >> "$GITHUB_OUTPUT"
30+
echo "command=type-check" >> $GITHUB_OUTPUT"
31+
elif [ "$doMutate" = "true" ]; then
32+
echo "commentCommand=true" >> "$GITHUB_OUTPUT"
33+
echo "command=mutate" >> $GITHUB_OUTPUT"
34+
elif [ "$doCombos" = "true" ]; then
35+
echo "commentCommand=true" >> "$GITHUB_OUTPUT"
36+
echo "command=combos" >> $GITHUB_OUTPUT"
37+
elif [ "$doAll" = "true" ]; then
38+
echo "commentCommand=true" >> "$GITHUB_OUTPUT"
39+
echo "command=all" >> $GITHUB_OUTPUT"
40+
fi
41+
- name: Get PR's branch name
42+
id: from-pr
43+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
44+
run: |
45+
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }})
46+
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
47+
echo "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
48+
- name: Bind check in PR
49+
id: bind-pr
50+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
51+
uses: myrotvorets/[email protected]
52+
with:
53+
token: ${{ secrets.GITHUB_TOKEN }}
54+
sha: ${{ steps.from-pr.outputs.sha }}
55+
status: pending
56+
context: Run based on PR comment (${{ steps.get-command.outputs.command }})
57+
- name: Get current branch name
58+
id: from-branch
59+
if: ${{ steps.get-command.outputs.commentCommand != 'true' }}
60+
run: |
61+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
62+
echo "sha=..." >> "$GITHUB_OUTPUT"
63+
outputs:
64+
commentCommand: ${{ steps.get-command.outputs.commentCommand }}
65+
command: ${{ steps.get-command.outputs.command }}
66+
onPR: ${{ steps.get-command.outputs.onPR }}
67+
doTypeCheck: ${{ steps.get-command.outputs.doTypeCheck }}
68+
doMutate: ${{ steps.get-command.outputs.doMutate }}
69+
doCombos: ${{ steps.get-command.outputs.doCombos }}
70+
doAll: ${{ steps.get-command.outputs.doAll }}
71+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
72+
sha: ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }}
73+
74+
coverage:
75+
runs-on: ubuntu-latest
76+
name: Check coverage
77+
needs: [get-main-ref]
1478
steps:
1579
- name: Checkout current branch
1680
uses: actions/checkout@v4
1781
with:
18-
ref: ${{ github.ref_name }}
82+
ref: ${{ needs.get-main-ref.outputs.branch }}
1983
- uses: actions/setup-python@v5
2084
with:
2185
python-version: '3.9'
2286
- run: python -m pip install --upgrade setuptools virtualenv
2387
- run: pip install -r requirements-dev.txt
2488
- run: pytest --cov=hooks --cov-fail-under=100
2589

26-
main:
90+
type-check:
91+
if: ${{ needs.get-main-ref.outputs.onPR == 'false' || needs.get-main-ref.outputs.doTypeCheck == 'true' || needs.get-main-ref.outputs.doAll == 'true' }}
2792
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
93+
name: Type checking
94+
needs: [get-main-ref]
3095
steps:
3196
- name: Checkout current branch
3297
uses: actions/checkout@v4
3398
with:
34-
ref: ${{ github.ref_name }}
99+
ref: ${{ needs.get-main-ref.outputs.branch }}
35100
- uses: actions/setup-python@v5
36101
with:
37-
python-version: '3.12'
102+
python-version: '3.9'
38103
- run: python -m pip install --upgrade setuptools virtualenv
39104
- run: pip install -r requirements-dev.txt
40105
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
106+
107+
mutate:
108+
if: ${{ needs.get-main-ref.outputs.onPR == 'false' || needs.get-main-ref.outputs.doMutate == 'true' || needs.get-main-ref.outputs.doAll == 'true' }}
109+
runs-on: ubuntu-latest
110+
name: Mutation tests
111+
needs: [get-main-ref, coverage]
112+
steps:
113+
- name: Checkout current branch
114+
uses: actions/checkout@v4
115+
with:
116+
ref: ${{ needs.get-main-ref.outputs.branch }}
117+
- uses: actions/setup-python@v5
118+
with:
119+
python-version: '3.12'
120+
- run: python -m pip install --upgrade setuptools virtualenv
121+
- run: pip install -r requirements-dev.txt
122+
- run: pytest --cov=hooks
42123
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43124

44125
combos:
45-
if: github.ref == 'refs/heads/main'
126+
if: ${{ needs.get-main-ref.outputs.onPR == 'false' || needs.get-main-ref.outputs.doCombos == 'true' || needs.get-main-ref.outputs.doAll == 'true' }}
46127
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
128+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
129+
needs: [get-main-ref]
49130
strategy:
50131
matrix:
51132
os: [windows-latest, ubuntu-latest, macos-latest]
52133
env: ['3.9', '3.10', '3.11', '3.12']
53134
exclude:
54-
# exclude the sanity-run combo, no need to re-run it
135+
# exclude the coverage combo, no need to re-run it
55136
- os: ubuntu-latest
56137
env: '3.9'
57-
# exclude the main combo, no need to re-run it
138+
# exclude the mutate combo, no need to re-run it
58139
- os: ubuntu-latest
59140
env: '3.12'
60141
steps:
61142
- name: Checkout current branch
62143
uses: actions/checkout@v4
63144
with:
64-
ref: ${{ github.ref_name }}
145+
ref: ${{ needs.get-main-ref.outputs.branch }}
65146
- uses: actions/setup-python@v5
66147
with:
67148
python-version: ${{ matrix.env }}
68149
- run: python -m pip install --upgrade setuptools virtualenv
69150
- run: pip install -r requirements-dev.txt
70151
- run: pytest
152+
153+
update-pr:
154+
if: ${{ always() }}
155+
runs-on: ubuntu-latest
156+
name: Report back in PR when triggered by comment
157+
permissions:
158+
statuses: write
159+
needs: [get-main-ref, type-check, mutate, combos]
160+
steps:
161+
- name: Set final commit status
162+
uses: myrotvorets/[email protected]
163+
if: ${{ needs.get-main-ref.outputs.onPR == 'true' }}
164+
with:
165+
token: ${{ secrets.GITHUB_TOKEN }}
166+
sha: ${{ needs.get-main-ref.outputs.sha }}
167+
status: ${{ job.status }}
168+
context: Run based on PR comment (${{ needs.get-main-ref.outputs.command }})

0 commit comments

Comments
 (0)