Skip to content

Commit b061afe

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

File tree

1 file changed

+138
-25
lines changed

1 file changed

+138
-25
lines changed

.github/workflows/main.yml

Lines changed: 138 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,183 @@
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 || needs.get-command.outputs.doAll }}
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: echo "do"
116+
# - run: python -m pip install --upgrade setuptools virtualenv
117+
# - run: pip install -r requirements-dev.txt
118+
# - run: mypy hooks
119+
120+
mutate:
121+
if: ${{ github.ref == 'refs/heads/main' || needs.get-command.outputs.doMutate || needs.get-command.outputs.doAll }}
122+
runs-on: ubuntu-latest
123+
name: Mutation tests
124+
needs: [get-command, coverage]
125+
steps:
126+
- name: Checkout current branch
127+
uses: actions/checkout@v4
128+
with:
129+
ref: ${{ needs.get-command.outputs.branch }}
35130
- uses: actions/setup-python@v5
36131
with:
37132
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
133+
- run: echo "do"
134+
# - run: python -m pip install --upgrade setuptools virtualenv
135+
# - run: pip install -r requirements-dev.txt
136+
# - run: pytest --cov=hooks
137+
# - run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43138

44139
combos:
45-
if: github.ref == 'refs/heads/main'
140+
if: ${{ github.ref == 'refs/heads/main' || needs.get-command.outputs.doCombos || needs.get-command.outputs.doAll }}
46141
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
142+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
143+
needs: [get-command]
49144
strategy:
50145
matrix:
51146
os: [windows-latest, ubuntu-latest, macos-latest]
52147
env: ['3.9', '3.10', '3.11', '3.12']
53148
exclude:
54-
# exclude the sanity-run combo, no need to re-run it
149+
# exclude the coverage combo, no need to re-run it
55150
- os: ubuntu-latest
56151
env: '3.9'
57-
# exclude the main combo, no need to re-run it
152+
# exclude the mutate combo, no need to re-run it
58153
- os: ubuntu-latest
59154
env: '3.12'
60155
steps:
61156
- name: Checkout current branch
62157
uses: actions/checkout@v4
63158
with:
64-
ref: ${{ github.ref_name }}
159+
ref: ${{ needs.get-command.outputs.branch }}
65160
- uses: actions/setup-python@v5
66161
with:
67162
python-version: ${{ matrix.env }}
68-
- run: python -m pip install --upgrade setuptools virtualenv
69-
- run: pip install -r requirements-dev.txt
70-
- run: pytest
163+
- run: echo "do"
164+
# - run: python -m pip install --upgrade setuptools virtualenv
165+
# - run: pip install -r requirements-dev.txt
166+
# - run: pytest
167+
168+
update-pr:
169+
if: ${{ always() }}
170+
runs-on: ubuntu-latest
171+
name: Report back in PR when triggered by comment
172+
permissions:
173+
statuses: write
174+
needs: [get-command, type-check, mutate, combos]
175+
steps:
176+
- name: Set final commit status
177+
uses: myrotvorets/[email protected]
178+
if: ${{ needs.get-command.outputs.commentCommand }}
179+
with:
180+
token: ${{ secrets.GITHUB_TOKEN }}
181+
sha: ${{ needs.get-command.outputs.sha }}
182+
status: ${{ job.status }}
183+
context: Run based on PR comment (${{ needs.get-command.outputs.command }})

0 commit comments

Comments
 (0)