Skip to content

Commit 465be9b

Browse files
committed
Refactor main pipeline
1 parent 730a8f0 commit 465be9b

File tree

1 file changed

+83
-14
lines changed

1 file changed

+83
-14
lines changed

.github/workflows/main.yml

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,103 @@
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 "onPR=true" >> "$GITHUB_OUTPUT"
26+
- name: Bind check in PR
27+
id: bind-pr
28+
if: ${{ steps.from-pr.outputs.onPR }}
29+
uses: myrotvorets/[email protected]
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
sha: ${{ steps.from-pr.outputs.branch }}
33+
status: pending
34+
context: Run based on PR comment
35+
- name: Get current branch name
36+
id: from-branch
37+
if: ${{ !contains(github.event.comment.html_url, '/pull/') }}
38+
run: |
39+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
40+
echo "onPR=false" >> "$GITHUB_OUTPUT"
41+
outputs:
42+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
43+
onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }}
44+
45+
coverage:
46+
runs-on: ubuntu-latest
47+
name: Run tests on lowest supported Python version on Ubuntu
48+
needs: [get-main-ref]
1449
steps:
1550
- name: Checkout current branch
1651
uses: actions/checkout@v4
1752
with:
18-
ref: ${{ github.ref_name }}
53+
ref: ${{ needs.get-main-ref.outputs.branch }}
1954
- uses: actions/setup-python@v5
2055
with:
2156
python-version: '3.9'
2257
- run: python -m pip install --upgrade setuptools virtualenv
2358
- run: pip install -r requirements-dev.txt
2459
- run: pytest --cov=hooks --cov-fail-under=100
2560

26-
main:
61+
type-check:
62+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }}
2763
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
64+
name: Type checking
65+
needs: [get-main-ref]
3066
steps:
3167
- name: Checkout current branch
3268
uses: actions/checkout@v4
3369
with:
34-
ref: ${{ github.ref_name }}
70+
ref: ${{ needs.get-main-ref.outputs.branch }}
3571
- uses: actions/setup-python@v5
3672
with:
37-
python-version: '3.12'
73+
python-version: '3.9'
3874
- run: python -m pip install --upgrade setuptools virtualenv
3975
- run: pip install -r requirements-dev.txt
4076
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
77+
78+
mutate:
79+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/all-tests')) }}
80+
runs-on: ubuntu-latest
81+
name: Mutation tests
82+
needs: [get-main-ref, coverage]
83+
steps:
84+
- name: Checkout current branch
85+
uses: actions/checkout@v4
86+
with:
87+
ref: ${{ needs.get-main-ref.outputs.branch }}
88+
- uses: actions/setup-python@v5
89+
with:
90+
python-version: '3.12'
91+
- run: python -m pip install --upgrade setuptools virtualenv
92+
- run: pip install -r requirements-dev.txt
93+
- run: pytest --cov=hooks
4294
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
4395

4496
combos:
45-
if: github.ref == 'refs/heads/main'
97+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/all-tests')) }}
4698
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
99+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
100+
needs: [get-main-ref, coverage]
49101
strategy:
50102
matrix:
51103
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -61,10 +113,27 @@ jobs:
61113
- name: Checkout current branch
62114
uses: actions/checkout@v4
63115
with:
64-
ref: ${{ github.ref_name }}
116+
ref: ${{ needs.get-main-ref.outputs.branch }}
65117
- uses: actions/setup-python@v5
66118
with:
67119
python-version: ${{ matrix.env }}
68120
- run: python -m pip install --upgrade setuptools virtualenv
69121
- run: pip install -r requirements-dev.txt
70122
- run: pytest
123+
124+
update-pr:
125+
if: ${{ needs.get-main-ref.outputs.onPR }}
126+
runs-on: ubuntu-latest
127+
name: Report back in PR when triggered by comment
128+
permissions:
129+
statuses: write
130+
needs: [get-main-ref, type-check, mutate, combos]
131+
steps:
132+
- name: Set final commit status
133+
uses: myrotvorets/[email protected]
134+
if: always()
135+
with:
136+
token: ${{ secrets.GITHUB_TOKEN }}
137+
sha: ${{ needs.get-main-ref.outputs.branch }}
138+
status: ${{ job.status }}
139+
context: Run based on PR comment

0 commit comments

Comments
 (0)