Skip to content

Commit d8532ed

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

File tree

1 file changed

+55
-14
lines changed

1 file changed

+55
-14
lines changed

.github/workflows/main.yml

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,92 @@
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+
steps:
17+
- name: Get PR's branch name
18+
id: from-pr
19+
if: ${{ contains(github.event.comment.html_url, '/pull/') }}
20+
run: |
21+
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }})
22+
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
23+
echo "onPR=true" >> "$GITHUB_OUTPUT"
24+
- name: Get current branch name
25+
id: from-branch
26+
if: ${{ !contains(github.event.comment.html_url, '/pull/') }}
27+
run: |
28+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
29+
echo "onPR=false" >> "$GITHUB_OUTPUT"
30+
outputs:
31+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
32+
onPR: ${{ steps.from-pr.output.onPR || steps.from-branch.outputs.onPR }}
33+
34+
coverage:
35+
runs-on: ubuntu-latest
36+
name: Run tests on lowest supported Python version on Ubuntu
37+
needs: [get-main-ref]
1438
steps:
1539
- name: Checkout current branch
1640
uses: actions/checkout@v4
1741
with:
18-
ref: ${{ github.ref_name }}
42+
ref: ${{ needs.get-main-ref.outputs.branch }}
1943
- uses: actions/setup-python@v5
2044
with:
2145
python-version: '3.9'
2246
- run: python -m pip install --upgrade setuptools virtualenv
2347
- run: pip install -r requirements-dev.txt
2448
- run: pytest --cov=hooks --cov-fail-under=100
2549

26-
main:
50+
type-check:
51+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }}
2752
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
53+
name: Type checking
54+
needs: [get-main-ref]
3055
steps:
3156
- name: Checkout current branch
3257
uses: actions/checkout@v4
3358
with:
34-
ref: ${{ github.ref_name }}
59+
ref: ${{ needs.get-main-ref.outputs.branch }}
3560
- uses: actions/setup-python@v5
3661
with:
37-
python-version: '3.12'
62+
python-version: '3.9'
3863
- run: python -m pip install --upgrade setuptools virtualenv
3964
- run: pip install -r requirements-dev.txt
4065
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
66+
67+
mutate:
68+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/all-tests')) }}
69+
runs-on: ubuntu-latest
70+
name: Mutation tests
71+
needs: [get-main-ref, coverage]
72+
steps:
73+
- name: Checkout current branch
74+
uses: actions/checkout@v4
75+
with:
76+
ref: ${{ needs.get-main-ref.outputs.branch }}
77+
- uses: actions/setup-python@v5
78+
with:
79+
python-version: '3.12'
80+
- run: python -m pip install --upgrade setuptools virtualenv
81+
- run: pip install -r requirements-dev.txt
82+
- run: pytest --cov=hooks
4283
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
4384

4485
combos:
45-
if: github.ref == 'refs/heads/main'
86+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/all-tests')) }}
4687
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
88+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
89+
needs: [get-main-ref, coverage]
4990
strategy:
5091
matrix:
5192
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -61,7 +102,7 @@ jobs:
61102
- name: Checkout current branch
62103
uses: actions/checkout@v4
63104
with:
64-
ref: ${{ github.ref_name }}
105+
ref: ${{ needs.get-main-ref.outputs.branch }}
65106
- uses: actions/setup-python@v5
66107
with:
67108
python-version: ${{ matrix.env }}

0 commit comments

Comments
 (0)