Skip to content

Commit ec4a841

Browse files
committed
Refactor main pipeline
1 parent 730a8f0 commit ec4a841

File tree

1 file changed

+86
-14
lines changed

1 file changed

+86
-14
lines changed

.github/workflows/main.yml

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,106 @@
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: Get PR's branch name
20+
id: from-pr
21+
if: ${{ contains(github.event.comment.html_url, '/pull/') }}
22+
run: |
23+
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }})
24+
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
25+
echo "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
26+
echo "onPR=true" >> "$GITHUB_OUTPUT"
27+
- name: Bind check in PR
28+
id: bind-pr
29+
if: ${{ steps.from-pr.outputs.onPR }}
30+
uses: myrotvorets/[email protected]
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
sha: ${{ steps.from-pr.outputs.sha }}
34+
status: pending
35+
context: Run based on PR comment
36+
- name: Get current branch name
37+
id: from-branch
38+
if: ${{ !contains(github.event.comment.html_url, '/pull/') }}
39+
run: |
40+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
41+
echo "sha=..." >> "$GITHUB_OUTPUT"
42+
echo "onPR=false" >> "$GITHUB_OUTPUT"
43+
outputs:
44+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
45+
sha: ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }}
46+
onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }}
47+
48+
coverage:
49+
runs-on: ubuntu-latest
50+
name: Run tests on lowest supported Python version on Ubuntu
51+
needs: [get-main-ref]
1452
steps:
1553
- name: Checkout current branch
1654
uses: actions/checkout@v4
1755
with:
18-
ref: ${{ github.ref_name }}
56+
ref: ${{ needs.get-main-ref.outputs.branch }}
1957
- uses: actions/setup-python@v5
2058
with:
2159
python-version: '3.9'
2260
- run: python -m pip install --upgrade setuptools virtualenv
2361
- run: pip install -r requirements-dev.txt
2462
- run: pytest --cov=hooks --cov-fail-under=100
2563

26-
main:
64+
type-check:
65+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }}
2766
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
67+
name: Type checking
68+
needs: [get-main-ref]
3069
steps:
3170
- name: Checkout current branch
3271
uses: actions/checkout@v4
3372
with:
34-
ref: ${{ github.ref_name }}
73+
ref: ${{ needs.get-main-ref.outputs.branch }}
3574
- uses: actions/setup-python@v5
3675
with:
37-
python-version: '3.12'
76+
python-version: '3.9'
3877
- run: python -m pip install --upgrade setuptools virtualenv
3978
- run: pip install -r requirements-dev.txt
4079
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
80+
81+
mutate:
82+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/all-tests')) }}
83+
runs-on: ubuntu-latest
84+
name: Mutation tests
85+
needs: [get-main-ref, coverage]
86+
steps:
87+
- name: Checkout current branch
88+
uses: actions/checkout@v4
89+
with:
90+
ref: ${{ needs.get-main-ref.outputs.branch }}
91+
- uses: actions/setup-python@v5
92+
with:
93+
python-version: '3.12'
94+
- run: python -m pip install --upgrade setuptools virtualenv
95+
- run: pip install -r requirements-dev.txt
96+
- run: pytest --cov=hooks
4297
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
4398

4499
combos:
45-
if: github.ref == 'refs/heads/main'
100+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/all-tests')) }}
46101
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
102+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
103+
needs: [get-main-ref, coverage]
49104
strategy:
50105
matrix:
51106
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -61,10 +116,27 @@ jobs:
61116
- name: Checkout current branch
62117
uses: actions/checkout@v4
63118
with:
64-
ref: ${{ github.ref_name }}
119+
ref: ${{ needs.get-main-ref.outputs.branch }}
65120
- uses: actions/setup-python@v5
66121
with:
67122
python-version: ${{ matrix.env }}
68123
- run: python -m pip install --upgrade setuptools virtualenv
69124
- run: pip install -r requirements-dev.txt
70125
- run: pytest
126+
127+
update-pr:
128+
if: ${{ needs.get-main-ref.outputs.onPR }}
129+
runs-on: ubuntu-latest
130+
name: Report back in PR when triggered by comment
131+
permissions:
132+
statuses: write
133+
needs: [get-main-ref, type-check, mutate, combos]
134+
steps:
135+
- name: Set final commit status
136+
uses: myrotvorets/[email protected]
137+
if: always()
138+
with:
139+
token: ${{ secrets.GITHUB_TOKEN }}
140+
sha: ${{ needs.get-main-ref.outputs.sha }}
141+
status: ${{ job.status }}
142+
context: Run based on PR comment

0 commit comments

Comments
 (0)