Skip to content

Commit a24da09

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

File tree

1 file changed

+81
-14
lines changed

1 file changed

+81
-14
lines changed

.github/workflows/main.yml

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,102 @@
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/set-commit-status-action@master
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
status: pending
33+
context: Run based on PR comment
34+
- name: Get current branch name
35+
id: from-branch
36+
if: ${{ !contains(github.event.comment.html_url, '/pull/') }}
37+
run: |
38+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
39+
echo "onPR=false" >> "$GITHUB_OUTPUT"
40+
outputs:
41+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
42+
onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }}
43+
44+
coverage:
45+
runs-on: ubuntu-latest
46+
name: Run tests on lowest supported Python version on Ubuntu
47+
needs: [get-main-ref]
1448
steps:
1549
- name: Checkout current branch
1650
uses: actions/checkout@v4
1751
with:
18-
ref: ${{ github.ref_name }}
52+
ref: ${{ needs.get-main-ref.outputs.branch }}
1953
- uses: actions/setup-python@v5
2054
with:
2155
python-version: '3.9'
2256
- run: python -m pip install --upgrade setuptools virtualenv
2357
- run: pip install -r requirements-dev.txt
2458
- run: pytest --cov=hooks --cov-fail-under=100
2559

26-
main:
60+
type-check:
61+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }}
2762
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
63+
name: Type checking
64+
needs: [get-main-ref]
3065
steps:
3166
- name: Checkout current branch
3267
uses: actions/checkout@v4
3368
with:
34-
ref: ${{ github.ref_name }}
69+
ref: ${{ needs.get-main-ref.outputs.branch }}
3570
- uses: actions/setup-python@v5
3671
with:
37-
python-version: '3.12'
72+
python-version: '3.9'
3873
- run: python -m pip install --upgrade setuptools virtualenv
3974
- run: pip install -r requirements-dev.txt
4075
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
76+
77+
mutate:
78+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/all-tests')) }}
79+
runs-on: ubuntu-latest
80+
name: Mutation tests
81+
needs: [get-main-ref, coverage]
82+
steps:
83+
- name: Checkout current branch
84+
uses: actions/checkout@v4
85+
with:
86+
ref: ${{ needs.get-main-ref.outputs.branch }}
87+
- uses: actions/setup-python@v5
88+
with:
89+
python-version: '3.12'
90+
- run: python -m pip install --upgrade setuptools virtualenv
91+
- run: pip install -r requirements-dev.txt
92+
- run: pytest --cov=hooks
4293
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
4394

4495
combos:
45-
if: github.ref == 'refs/heads/main'
96+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/all-tests')) }}
4697
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
98+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
99+
needs: [get-main-ref, coverage]
49100
strategy:
50101
matrix:
51102
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -61,10 +112,26 @@ jobs:
61112
- name: Checkout current branch
62113
uses: actions/checkout@v4
63114
with:
64-
ref: ${{ github.ref_name }}
115+
ref: ${{ needs.get-main-ref.outputs.branch }}
65116
- uses: actions/setup-python@v5
66117
with:
67118
python-version: ${{ matrix.env }}
68119
- run: python -m pip install --upgrade setuptools virtualenv
69120
- run: pip install -r requirements-dev.txt
70121
- run: pytest
122+
123+
update-pr:
124+
if: ${{ needs.get-main-ref.outputs.onPR }}
125+
runs-on: ubuntu-latest
126+
name: Report back in PR when triggered by comment
127+
permissions:
128+
statuses: write
129+
needs: [type-check, mutate, combos]
130+
steps:
131+
- name: Set final commit status
132+
uses: myrotvorets/set-commit-status-action@master
133+
if: always()
134+
with:
135+
token: ${{ secrets.GITHUB_TOKEN }}
136+
status: ${{ job.status }}
137+
context: Run based on PR comment

0 commit comments

Comments
 (0)