Skip to content

Commit f73f7e4

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

File tree

1 file changed

+145
-25
lines changed

1 file changed

+145
-25
lines changed

.github/workflows/main.yml

Lines changed: 145 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,190 @@
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 "onPR=true" >> "$GITHUB_OUTPUT"
59+
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
60+
echo "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
61+
- name: Bind check in PR
62+
id: bind-pr
63+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
64+
uses: myrotvorets/[email protected]
65+
with:
66+
token: ${{ secrets.GITHUB_TOKEN }}
67+
sha: ${{ steps.from-pr.outputs.sha }}
68+
status: pending
69+
context: Run based on PR comment (${{ steps.get-command.outputs.command }})
70+
- name: Get current branch name
71+
id: from-branch
72+
if: ${{ steps.get-command.outputs.commentCommand != 'true' }}
73+
run: |
74+
echo "onPR=false" >> "$GITHUB_OUTPUT"
75+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
76+
echo "sha=..." >> "$GITHUB_OUTPUT"
77+
outputs:
78+
commentCommand: ${{ steps.get-command.outputs.commentCommand }}
79+
command: ${{ steps.get-command.outputs.command }}
80+
doTypeCheck: ${{ steps.get-command.outputs.doTypeCheck }}
81+
doMutate: ${{ steps.get-command.outputs.doMutate }}
82+
doCombos: ${{ steps.get-command.outputs.doCombos }}
83+
doAll: ${{ steps.get-command.outputs.doAll }}
84+
onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }}
85+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
86+
sha: ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }}
87+
88+
coverage:
89+
runs-on: ubuntu-latest
90+
name: Check coverage
91+
needs: [get-command]
1492
steps:
1593
- name: Checkout current branch
1694
uses: actions/checkout@v4
1795
with:
18-
ref: ${{ github.ref_name }}
96+
ref: ${{ needs.get-command.outputs.branch }}
1997
- uses: actions/setup-python@v5
2098
with:
2199
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
100+
- run: echo "do"
101+
# - run: python -m pip install --upgrade setuptools virtualenv
102+
# - run: pip install -r requirements-dev.txt
103+
# - run: pytest --cov=hooks --cov-fail-under=100
25104

26-
main:
105+
type-check:
106+
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doTypeCheck == 'true' || needs.get-command.outputs.doAll == 'true' }}
27107
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
108+
name: Type checking
109+
needs: [get-command]
30110
steps:
31111
- name: Checkout current branch
32112
uses: actions/checkout@v4
33113
with:
34-
ref: ${{ github.ref_name }}
114+
ref: ${{ needs.get-command.outputs.branch }}
115+
- uses: actions/setup-python@v5
116+
with:
117+
python-version: '3.9'
118+
- run: |
119+
echo ${{ needs.get-command.outputs.onPR }}
120+
echo ${{ github.ref }}
121+
echo ${{ needs.get-command.outputs.doTypeCheck }}
122+
echo ${{ needs.get-command.outputs.doAll }}
123+
# - run: python -m pip install --upgrade setuptools virtualenv
124+
# - run: pip install -r requirements-dev.txt
125+
# - run: mypy hooks
126+
127+
mutate:
128+
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doMutate == 'true' || needs.get-command.outputs.doAll == 'true' }}
129+
runs-on: ubuntu-latest
130+
name: Mutation tests
131+
needs: [get-command, coverage]
132+
steps:
133+
- name: Checkout current branch
134+
uses: actions/checkout@v4
135+
with:
136+
ref: ${{ needs.get-command.outputs.branch }}
35137
- uses: actions/setup-python@v5
36138
with:
37139
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
140+
- run: echo "do"
141+
# - run: python -m pip install --upgrade setuptools virtualenv
142+
# - run: pip install -r requirements-dev.txt
143+
# - run: pytest --cov=hooks
144+
# - run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43145

44146
combos:
45-
if: github.ref == 'refs/heads/main'
147+
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doCombos == 'true' || needs.get-command.outputs.doAll == 'true' }}
46148
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
149+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
150+
needs: [get-command]
49151
strategy:
50152
matrix:
51153
os: [windows-latest, ubuntu-latest, macos-latest]
52154
env: ['3.9', '3.10', '3.11', '3.12']
53155
exclude:
54-
# exclude the sanity-run combo, no need to re-run it
156+
# exclude the coverage combo, no need to re-run it
55157
- os: ubuntu-latest
56158
env: '3.9'
57-
# exclude the main combo, no need to re-run it
159+
# exclude the mutate combo, no need to re-run it
58160
- os: ubuntu-latest
59161
env: '3.12'
60162
steps:
61163
- name: Checkout current branch
62164
uses: actions/checkout@v4
63165
with:
64-
ref: ${{ github.ref_name }}
166+
ref: ${{ needs.get-command.outputs.branch }}
65167
- uses: actions/setup-python@v5
66168
with:
67169
python-version: ${{ matrix.env }}
68-
- run: python -m pip install --upgrade setuptools virtualenv
69-
- run: pip install -r requirements-dev.txt
70-
- run: pytest
170+
- run: echo "do"
171+
# - run: python -m pip install --upgrade setuptools virtualenv
172+
# - run: pip install -r requirements-dev.txt
173+
# - run: pytest
174+
175+
update-pr:
176+
if: ${{ always() }}
177+
runs-on: ubuntu-latest
178+
name: Report back in PR when triggered by comment
179+
permissions:
180+
statuses: write
181+
needs: [get-command, type-check, mutate, combos]
182+
steps:
183+
- name: Set final commit status
184+
uses: myrotvorets/[email protected]
185+
if: ${{ needs.get-command.outputs.commentCommand == 'true' }}
186+
with:
187+
token: ${{ secrets.GITHUB_TOKEN }}
188+
sha: ${{ needs.get-command.outputs.sha }}
189+
status: ${{ job.status }}
190+
context: Run based on PR comment (${{ needs.get-command.outputs.command }})

0 commit comments

Comments
 (0)