Skip to content

Commit b1bad76

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

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

.github/workflows/main.yml

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,89 @@
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+
- name: Get current branch name
24+
id: from-branch
25+
if: ${{ !contains(github.event.comment.html_url, '/pull/') }}
26+
run: |
27+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
28+
outputs:
29+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
30+
31+
coverage:
32+
runs-on: ubuntu-latest
33+
name: Run tests on lowest supported Python version on Ubuntu
34+
needs: [get-main-ref]
1435
steps:
1536
- name: Checkout current branch
1637
uses: actions/checkout@v4
1738
with:
18-
ref: ${{ github.ref_name }}
39+
ref: ${{ needs.get-main-ref.outputs.branch }}
1940
- uses: actions/setup-python@v5
2041
with:
2142
python-version: '3.9'
2243
- run: python -m pip install --upgrade setuptools virtualenv
2344
- run: pip install -r requirements-dev.txt
2445
- run: pytest --cov=hooks --cov-fail-under=100
2546

26-
main:
47+
type-check:
48+
if: ${{ (github.ref == 'refs/heads/main') || (contains(github.event.comment.html_url, '/pull/') && (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/full-build'))) }}
2749
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
50+
name: Type checking
51+
needs: [get-main-ref]
3052
steps:
3153
- name: Checkout current branch
3254
uses: actions/checkout@v4
3355
with:
34-
ref: ${{ github.ref_name }}
56+
ref: ${{ needs.get-main-ref.outputs.branch }}
3557
- uses: actions/setup-python@v5
3658
with:
37-
python-version: '3.12'
59+
python-version: '3.9'
3860
- run: python -m pip install --upgrade setuptools virtualenv
3961
- run: pip install -r requirements-dev.txt
4062
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
63+
64+
mutate:
65+
if: ${{ (github.ref == 'refs/heads/main') || (contains(github.event.comment.html_url, '/pull/') && (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/full-build'))) }}
66+
runs-on: ubuntu-latest
67+
name: Mutation tests
68+
needs: [get-main-ref, coverage]
69+
steps:
70+
- name: Checkout current branch
71+
uses: actions/checkout@v4
72+
with:
73+
ref: ${{ needs.get-main-ref.outputs.branch }}
74+
- uses: actions/setup-python@v5
75+
with:
76+
python-version: '3.12'
77+
- run: python -m pip install --upgrade setuptools virtualenv
78+
- run: pip install -r requirements-dev.txt
79+
- run: pytest --cov=hooks
4280
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
4381

4482
combos:
45-
if: github.ref == 'refs/heads/main'
83+
if: ${{ (github.ref == 'refs/heads/main') || (contains(github.event.comment.html_url, '/pull/') && (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/full-build'))) }}
4684
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
85+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
86+
needs: [get-main-ref, coverage]
4987
strategy:
5088
matrix:
5189
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -61,7 +99,7 @@ jobs:
6199
- name: Checkout current branch
62100
uses: actions/checkout@v4
63101
with:
64-
ref: ${{ github.ref_name }}
102+
ref: ${{ needs.get-main-ref.outputs.branch }}
65103
- uses: actions/setup-python@v5
66104
with:
67105
python-version: ${{ matrix.env }}

0 commit comments

Comments
 (0)