Skip to content

Commit 4132a49

Browse files
committed
Refactor main pipeline
1 parent 730a8f0 commit 4132a49

File tree

1 file changed

+76
-14
lines changed

1 file changed

+76
-14
lines changed

.github/workflows/main.yml

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,113 @@
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+
checks: 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: Get current branch name
27+
id: from-branch
28+
if: ${{ !contains(github.event.comment.html_url, '/pull/') }}
29+
run: |
30+
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
31+
echo "onPR=false" >> "$GITHUB_OUTPUT"
32+
outputs:
33+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
34+
onPR: ${{ steps.from-pr.output.onPR || steps.from-branch.outputs.onPR }}
35+
36+
wip:
37+
runs-on: ubuntu-latest
38+
name: WIP
39+
needs: [get-main-ref]
40+
steps:
41+
- name: print body
42+
env:
43+
BODY: ${{ github.event.comment.body }}
44+
IN_PR: ${{ !needs.get-main-ref.outputs.onPR }}
45+
RESULT: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }}
46+
run: |
47+
echo "body:" "${{ github.event.comment.body }}"
48+
echo "branch:" "${{ needs.get-main-ref.outputs.branch }}"
49+
echo "onPR:" "${{ needs.get-main-ref.outputs.onPR }}"
50+
echo "type-check:" "${{ contains(github.event.comment.body, '/type-check') }}"
51+
echo "mutate:" "${{ contains(github.event.comment.body, '/mutate') }}"
52+
echo "combos:" "${{ contains(github.event.comment.body, '/combos') }}"
53+
echo "all-tests:" "${{ contains(github.event.comment.body, '/all-tests') }}"
54+
55+
coverage:
56+
runs-on: ubuntu-latest
57+
name: Run tests on lowest supported Python version on Ubuntu
58+
needs: [get-main-ref]
1459
steps:
1560
- name: Checkout current branch
1661
uses: actions/checkout@v4
1762
with:
18-
ref: ${{ github.ref_name }}
63+
ref: ${{ needs.get-main-ref.outputs.branch }}
1964
- uses: actions/setup-python@v5
2065
with:
2166
python-version: '3.9'
2267
- run: python -m pip install --upgrade setuptools virtualenv
2368
- run: pip install -r requirements-dev.txt
2469
- run: pytest --cov=hooks --cov-fail-under=100
2570

26-
main:
71+
type-check:
72+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }}
2773
runs-on: ubuntu-latest
28-
name: Run all tests, run static type analysis, coverage, and mutation tests
29-
needs: sanity-run
74+
name: Type checking
75+
needs: [get-main-ref]
3076
steps:
3177
- name: Checkout current branch
3278
uses: actions/checkout@v4
3379
with:
34-
ref: ${{ github.ref_name }}
80+
ref: ${{ needs.get-main-ref.outputs.branch }}
3581
- uses: actions/setup-python@v5
3682
with:
37-
python-version: '3.12'
83+
python-version: '3.9'
3884
- run: python -m pip install --upgrade setuptools virtualenv
3985
- run: pip install -r requirements-dev.txt
4086
- run: mypy hooks
41-
- run: pytest --cov=hooks --cov-fail-under=100
87+
88+
mutate:
89+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/all-tests')) }}
90+
runs-on: ubuntu-latest
91+
name: Mutation tests
92+
needs: [get-main-ref, coverage]
93+
steps:
94+
- name: Checkout current branch
95+
uses: actions/checkout@v4
96+
with:
97+
ref: ${{ needs.get-main-ref.outputs.branch }}
98+
- uses: actions/setup-python@v5
99+
with:
100+
python-version: '3.12'
101+
- run: python -m pip install --upgrade setuptools virtualenv
102+
- run: pip install -r requirements-dev.txt
103+
- run: pytest --cov=hooks
42104
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43105

44106
combos:
45-
if: github.ref == 'refs/heads/main'
107+
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/all-tests')) }}
46108
runs-on: ${{ matrix.os }}
47-
name: ${{ matrix.os }} / ${{ matrix.env }}
48-
needs: main
109+
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
110+
needs: [get-main-ref, coverage]
49111
strategy:
50112
matrix:
51113
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -61,7 +123,7 @@ jobs:
61123
- name: Checkout current branch
62124
uses: actions/checkout@v4
63125
with:
64-
ref: ${{ github.ref_name }}
126+
ref: ${{ needs.get-main-ref.outputs.branch }}
65127
- uses: actions/setup-python@v5
66128
with:
67129
python-version: ${{ matrix.env }}

0 commit comments

Comments
 (0)