1
- name : Testing pipeline
1
+ name : Typecheck & run tests
2
2
3
3
on :
4
4
push :
5
5
branches :
6
6
- ' main'
7
7
- ' feature/*'
8
8
- ' bugfix/*'
9
+ issue_comment :
10
+ types : [created]
9
11
10
12
jobs :
11
- sanity-run :
13
+ get-main-ref :
12
14
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]
14
48
steps :
15
49
- name : Checkout current branch
16
50
uses : actions/checkout@v4
17
51
with :
18
- ref : ${{ github.ref_name }}
52
+ ref : ${{ needs.get-main-ref.outputs.branch }}
19
53
- uses : actions/setup-python@v5
20
54
with :
21
55
python-version : ' 3.9'
22
56
- run : python -m pip install --upgrade setuptools virtualenv
23
57
- run : pip install -r requirements-dev.txt
24
58
- run : pytest --cov=hooks --cov-fail-under=100
25
59
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')) }}
27
62
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]
30
65
steps :
31
66
- name : Checkout current branch
32
67
uses : actions/checkout@v4
33
68
with :
34
- ref : ${{ github.ref_name }}
69
+ ref : ${{ needs.get-main-ref.outputs.branch }}
35
70
- uses : actions/setup-python@v5
36
71
with :
37
- python-version : ' 3.12 '
72
+ python-version : ' 3.9 '
38
73
- run : python -m pip install --upgrade setuptools virtualenv
39
74
- run : pip install -r requirements-dev.txt
40
75
- 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
42
93
- run : mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43
94
44
95
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')) }}
46
97
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]
49
100
strategy :
50
101
matrix :
51
102
os : [windows-latest, ubuntu-latest, macos-latest]
@@ -61,10 +112,26 @@ jobs:
61
112
- name : Checkout current branch
62
113
uses : actions/checkout@v4
63
114
with :
64
- ref : ${{ github.ref_name }}
115
+ ref : ${{ needs.get-main-ref.outputs.branch }}
65
116
- uses : actions/setup-python@v5
66
117
with :
67
118
python-version : ${{ matrix.env }}
68
119
- run : python -m pip install --upgrade setuptools virtualenv
69
120
- run : pip install -r requirements-dev.txt
70
121
- 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