Skip to content

Commit c1d4683

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

File tree

1 file changed

+141
-25
lines changed

1 file changed

+141
-25
lines changed

.github/workflows/main.yml

Lines changed: 141 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,186 @@
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+
47+
echo $doTypeCheck
48+
echo $doMutate
49+
echo $doCombos
50+
echo $doAll
51+
echo $commentCommand
52+
echo $command
53+
- name: Get PR's branch name
54+
id: from-pr
55+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
56+
run: |
57+
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }})
58+
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
59+
echo "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
60+
- name: Bind check in PR
61+
id: bind-pr
62+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
63+
uses: myrotvorets/[email protected]
64+
with:
65+
token: ${{ secrets.GITHUB_TOKEN }}
66+
sha: ${{ steps.from-pr.outputs.sha }}
67+
status: pending
68+
context: Run based on PR comment (${{ steps.get-command.outputs.command }})
69+
- name: Get current branch name
70+
id: from-branch
71+
if: ${{ steps.get-command.outputs.commentCommand != 'true' }}
72+
run: |
73+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
74+
echo "sha=..." >> "$GITHUB_OUTPUT"
75+
outputs:
76+
commentCommand: ${{ steps.get-command.outputs.commentCommand }}
77+
command: ${{ steps.get-command.outputs.command }}
78+
doTypeCheck: ${{ steps.get-command.outputs.doTypeCheck }}
79+
doMutate: ${{ steps.get-command.outputs.doMutate }}
80+
doCombos: ${{ steps.get-command.outputs.doCombos }}
81+
doAll: ${{ steps.get-command.outputs.doAll }}
82+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
83+
sha: ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }}
84+
85+
coverage:
86+
runs-on: ubuntu-latest
87+
name: Check coverage
88+
needs: [get-command]
1489
steps:
1590
- name: Checkout current branch
1691
uses: actions/checkout@v4
1792
with:
18-
ref: ${{ github.ref_name }}
93+
ref: ${{ needs.get-command.outputs.branch }}
1994
- uses: actions/setup-python@v5
2095
with:
2196
python-version: '3.9'
22-
- run: python -m pip install --upgrade setuptools virtualenv
23-
- run: pip install -r requirements-dev.txt
24-
- run: pytest --cov=hooks --cov-fail-under=100
97+
- run: echo "do"
98+
# - run: python -m pip install --upgrade setuptools virtualenv
99+
# - run: pip install -r requirements-dev.txt
100+
# - run: pytest --cov=hooks --cov-fail-under=100
25101

26-
main:
102+
type-check:
103+
if: ${{ github.ref == 'refs/heads/main' || needs.get-command.outputs.doTypeCheck == 'true' || needs.get-command.outputs.doAll == 'true' }}
27104
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
105+
name: Type checking
106+
needs: [get-command]
30107
steps:
31108
- name: Checkout current branch
32109
uses: actions/checkout@v4
33110
with:
34-
ref: ${{ github.ref_name }}
111+
ref: ${{ needs.get-command.outputs.branch }}
112+
- uses: actions/setup-python@v5
113+
with:
114+
python-version: '3.9'
115+
- run: |
116+
echo ${{ github.ref }}
117+
echo ${{ needs.get-command.outputs.doTypeCheck }}
118+
echo ${{ needs.get-command.outputs.doAll }}
119+
# - run: python -m pip install --upgrade setuptools virtualenv
120+
# - run: pip install -r requirements-dev.txt
121+
# - run: mypy hooks
122+
123+
mutate:
124+
if: ${{ github.ref == 'refs/heads/main' || needs.get-command.outputs.doMutate == 'true' || needs.get-command.outputs.doAll == 'true' }}
125+
runs-on: ubuntu-latest
126+
name: Mutation tests
127+
needs: [get-command, coverage]
128+
steps:
129+
- name: Checkout current branch
130+
uses: actions/checkout@v4
131+
with:
132+
ref: ${{ needs.get-command.outputs.branch }}
35133
- uses: actions/setup-python@v5
36134
with:
37135
python-version: '3.12'
38-
- run: python -m pip install --upgrade setuptools virtualenv
39-
- run: pip install -r requirements-dev.txt
40-
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
42-
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
136+
- run: echo "do"
137+
# - run: python -m pip install --upgrade setuptools virtualenv
138+
# - run: pip install -r requirements-dev.txt
139+
# - run: pytest --cov=hooks
140+
# - run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43141

44142
combos:
45-
if: github.ref == 'refs/heads/main'
143+
if: ${{ github.ref == 'refs/heads/main' || needs.get-command.outputs.doCombos == 'true' || needs.get-command.outputs.doAll == 'true' }}
46144
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
145+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
146+
needs: [get-command]
49147
strategy:
50148
matrix:
51149
os: [windows-latest, ubuntu-latest, macos-latest]
52150
env: ['3.9', '3.10', '3.11', '3.12']
53151
exclude:
54-
# exclude the sanity-run combo, no need to re-run it
152+
# exclude the coverage combo, no need to re-run it
55153
- os: ubuntu-latest
56154
env: '3.9'
57-
# exclude the main combo, no need to re-run it
155+
# exclude the mutate combo, no need to re-run it
58156
- os: ubuntu-latest
59157
env: '3.12'
60158
steps:
61159
- name: Checkout current branch
62160
uses: actions/checkout@v4
63161
with:
64-
ref: ${{ github.ref_name }}
162+
ref: ${{ needs.get-command.outputs.branch }}
65163
- uses: actions/setup-python@v5
66164
with:
67165
python-version: ${{ matrix.env }}
68-
- run: python -m pip install --upgrade setuptools virtualenv
69-
- run: pip install -r requirements-dev.txt
70-
- run: pytest
166+
- run: echo "do"
167+
# - run: python -m pip install --upgrade setuptools virtualenv
168+
# - run: pip install -r requirements-dev.txt
169+
# - run: pytest
170+
171+
update-pr:
172+
if: ${{ always() }}
173+
runs-on: ubuntu-latest
174+
name: Report back in PR when triggered by comment
175+
permissions:
176+
statuses: write
177+
needs: [get-command, type-check, mutate, combos]
178+
steps:
179+
- name: Set final commit status
180+
uses: myrotvorets/[email protected]
181+
if: ${{ needs.get-command.outputs.commentCommand == 'true' }}
182+
with:
183+
token: ${{ secrets.GITHUB_TOKEN }}
184+
sha: ${{ needs.get-command.outputs.sha }}
185+
status: ${{ job.status }}
186+
context: Run based on PR comment (${{ needs.get-command.outputs.command }})

0 commit comments

Comments
 (0)