Skip to content

Commit 70bd0b6

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

File tree

1 file changed

+125
-25
lines changed

1 file changed

+125
-25
lines changed

.github/workflows/main.yml

Lines changed: 125 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,170 @@
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 "doTypeCheck=${{ contains(github.event.comment.body, '/type-check') }}" >> "$GITHUB_OUTPUT"
23+
echo "doMutate=${{ contains(github.event.comment.body, '/mutate') }}" >> "$GITHUB_OUTPUT"
24+
echo "doCombos=${{ contains(github.event.comment.body, '/combos') }}" >> "$GITHUB_OUTPUT"
25+
echo "doAll=${{ contains(github.event.comment.body, '/all-tests') }}" >> "$GITHUB_OUTPUT"
26+
echo "commentCommand=false" >> "$GITHUB_OUTPUT"
27+
if [ "$doTypeCheck" = "true" ]; then
28+
echo "commentCommand=true" >> "$GITHUB_OUTPUT"
29+
echo "command=type-check" >> $GITHUB_OUTPUT"
30+
elif [ "$doMutate" = "true" ]; then
31+
echo "commentCommand=true" >> "$GITHUB_OUTPUT"
32+
echo "command=mutate" >> $GITHUB_OUTPUT"
33+
elif [ "$doCombos" = "true" ]; then
34+
echo "commentCommand=true" >> "$GITHUB_OUTPUT"
35+
echo "command=combos" >> $GITHUB_OUTPUT"
36+
elif [ "$doAll" = "true" ]; then
37+
echo "commentCommand=true" >> "$GITHUB_OUTPUT"
38+
echo "command=all" >> $GITHUB_OUTPUT"
39+
fi
40+
- name: Get PR's branch name
41+
id: from-pr
42+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
43+
run: |
44+
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }})
45+
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
46+
echo "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
47+
- name: Bind check in PR
48+
id: bind-pr
49+
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
50+
uses: myrotvorets/[email protected]
51+
with:
52+
token: ${{ secrets.GITHUB_TOKEN }}
53+
sha: ${{ steps.from-pr.outputs.sha }}
54+
status: pending
55+
context: Run based on PR comment (${{ steps.get-command.outputs.command }})
56+
- name: Get current branch name
57+
id: from-branch
58+
if: ${{ steps.get-command.outputs.commentCommand != 'true' }}
59+
run: |
60+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
61+
echo "sha=..." >> "$GITHUB_OUTPUT"
62+
outputs:
63+
commentCommand: ${{ steps.get-command.outputs.commentCommand }}
64+
command: ${{ steps.get-command.outputs.command }}
65+
doTypeCheck: ${{ steps.get-command.outputs.doTypeCheck }}
66+
doMutate: ${{ steps.get-command.outputs.doMutate }}
67+
doCombos: ${{ steps.get-command.outputs.doCombos }}
68+
doAll: ${{ steps.get-command.outputs.doAll }}
69+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
70+
sha: ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }}
71+
72+
coverage:
73+
runs-on: ubuntu-latest
74+
name: Check coverage
75+
needs: [get-main-ref]
76+
steps:
77+
- name: Checkout current branch
78+
uses: actions/checkout@v4
79+
with:
80+
ref: ${{ needs.get-main-ref.outputs.branch }}
81+
- uses: actions/setup-python@v5
82+
with:
83+
python-version: '3.9'
84+
- run: echo "do"
85+
# - run: python -m pip install --upgrade setuptools virtualenv
86+
# - run: pip install -r requirements-dev.txt
87+
# - run: pytest --cov=hooks --cov-fail-under=100
88+
89+
type-check:
90+
if: ${{ github.ref == 'refs/heads/main' || needs.get-main-ref.outputs.doTypeCheck == 'true' || needs.get-main-ref.outputs.doAll == 'true' }}
91+
runs-on: ubuntu-latest
92+
name: Type checking
93+
needs: [get-main-ref]
1494
steps:
1595
- name: Checkout current branch
1696
uses: actions/checkout@v4
1797
with:
18-
ref: ${{ github.ref_name }}
98+
ref: ${{ needs.get-main-ref.outputs.branch }}
1999
- uses: actions/setup-python@v5
20100
with:
21101
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
102+
- run: echo "do"
103+
# - run: python -m pip install --upgrade setuptools virtualenv
104+
# - run: pip install -r requirements-dev.txt
105+
# - run: mypy hooks
25106

26-
main:
107+
mutate:
108+
if: ${{ github.ref == 'refs/heads/main' || needs.get-main-ref.outputs.doMutate == 'true' || needs.get-main-ref.outputs.doAll == 'true' }}
27109
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
110+
name: Mutation tests
111+
needs: [get-main-ref, coverage]
30112
steps:
31113
- name: Checkout current branch
32114
uses: actions/checkout@v4
33115
with:
34-
ref: ${{ github.ref_name }}
116+
ref: ${{ needs.get-main-ref.outputs.branch }}
35117
- uses: actions/setup-python@v5
36118
with:
37119
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
120+
- run: echo "do"
121+
# - run: python -m pip install --upgrade setuptools virtualenv
122+
# - run: pip install -r requirements-dev.txt
123+
# - run: pytest --cov=hooks
124+
# - run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43125

44126
combos:
45-
if: github.ref == 'refs/heads/main'
127+
if: ${{ github.ref == 'refs/heads/main' || needs.get-main-ref.outputs.doCombos == 'true' || needs.get-main-ref.outputs.doAll == 'true' }}
46128
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
129+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
130+
needs: [get-main-ref]
49131
strategy:
50132
matrix:
51133
os: [windows-latest, ubuntu-latest, macos-latest]
52134
env: ['3.9', '3.10', '3.11', '3.12']
53135
exclude:
54-
# exclude the sanity-run combo, no need to re-run it
136+
# exclude the coverage combo, no need to re-run it
55137
- os: ubuntu-latest
56138
env: '3.9'
57-
# exclude the main combo, no need to re-run it
139+
# exclude the mutate combo, no need to re-run it
58140
- os: ubuntu-latest
59141
env: '3.12'
60142
steps:
61143
- name: Checkout current branch
62144
uses: actions/checkout@v4
63145
with:
64-
ref: ${{ github.ref_name }}
146+
ref: ${{ needs.get-main-ref.outputs.branch }}
65147
- uses: actions/setup-python@v5
66148
with:
67149
python-version: ${{ matrix.env }}
68-
- run: python -m pip install --upgrade setuptools virtualenv
69-
- run: pip install -r requirements-dev.txt
70-
- run: pytest
150+
- run: echo "do"
151+
# - run: python -m pip install --upgrade setuptools virtualenv
152+
# - run: pip install -r requirements-dev.txt
153+
# - run: pytest
154+
155+
update-pr:
156+
if: ${{ always() }}
157+
runs-on: ubuntu-latest
158+
name: Report back in PR when triggered by comment
159+
permissions:
160+
statuses: write
161+
needs: [get-main-ref, type-check, mutate, combos]
162+
steps:
163+
- name: Set final commit status
164+
uses: myrotvorets/[email protected]
165+
if: ${{ needs.get-main-ref.outputs.onPR == 'true' }}
166+
with:
167+
token: ${{ secrets.GITHUB_TOKEN }}
168+
sha: ${{ needs.get-main-ref.outputs.sha }}
169+
status: ${{ job.status }}
170+
context: Run based on PR comment (${{ needs.get-main-ref.outputs.command }})

0 commit comments

Comments
 (0)