Skip to content

Commit b60ca1c

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

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

.github/workflows/main.yml

Lines changed: 49 additions & 11 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:
14+
runs-on: ubuntu-latest
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:
1232
runs-on: ubuntu-latest
1333
name: Run tests on lowest supported Python version on Ubuntu as a sanity-check before doing anything else
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'))) }}
49+
runs-on: ubuntu-latest
50+
name: Run tests on lowest supported Python version on Ubuntu as a sanity-check before doing anything else
51+
needs: [get-main-ref]
52+
steps:
53+
- name: Checkout current branch
54+
uses: actions/checkout@v4
55+
with:
56+
ref: ${{ needs.get-main-ref.outputs.branch }}
57+
- uses: actions/setup-python@v5
58+
with:
59+
python-version: '3.9'
60+
- run: python -m pip install --upgrade setuptools virtualenv
61+
- run: pip install -r requirements-dev.txt
62+
- run: mypy hooks
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'))) }}
2766
runs-on: ubuntu-latest
2867
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
68+
needs: [get-main-ref, coverage]
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:
3776
python-version: '3.12'
3877
- run: python -m pip install --upgrade setuptools virtualenv
3978
- run: pip install -r requirements-dev.txt
40-
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
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 }}
4785
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
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)