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 "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
26
+ echo "onPR=true" >> "$GITHUB_OUTPUT"
27
+ - name : Bind check in PR
28
+ id : bind-pr
29
+ if : ${{ steps.from-pr.outputs.onPR }}
30
+ uses :
myrotvorets/[email protected]
31
+ with :
32
+ token : ${{ secrets.GITHUB_TOKEN }}
33
+ sha : ${{ steps.from-pr.outputs.sha }}
34
+ status : pending
35
+ context : Run based on PR comment
36
+ - name : Get current branch name
37
+ id : from-branch
38
+ if : ${{ !contains(github.event.comment.html_url, '/pull/') }}
39
+ run : |
40
+ echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
41
+ echo "sha=..." >> "$GITHUB_OUTPUT"
42
+ echo "onPR=false" >> "$GITHUB_OUTPUT"
43
+ outputs :
44
+ branch : ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
45
+ sha : ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }}
46
+ onPR : ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }}
47
+
48
+ coverage :
49
+ runs-on : ubuntu-latest
50
+ name : Run tests on lowest supported Python version on Ubuntu
51
+ needs : [get-main-ref]
14
52
steps :
15
53
- name : Checkout current branch
16
54
uses : actions/checkout@v4
17
55
with :
18
- ref : ${{ github.ref_name }}
56
+ ref : ${{ needs.get-main-ref.outputs.branch }}
19
57
- uses : actions/setup-python@v5
20
58
with :
21
59
python-version : ' 3.9'
22
60
- run : python -m pip install --upgrade setuptools virtualenv
23
61
- run : pip install -r requirements-dev.txt
24
62
- run : pytest --cov=hooks --cov-fail-under=100
25
63
26
- main :
64
+ type-check :
65
+ if : ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }}
27
66
runs-on : ubuntu-latest
28
- name : Run all tests, run static type analysis, coverage, and mutation tests
29
- needs : sanity-run
67
+ name : Type checking
68
+ needs : [get-main-ref]
30
69
steps :
31
70
- name : Checkout current branch
32
71
uses : actions/checkout@v4
33
72
with :
34
- ref : ${{ github.ref_name }}
73
+ ref : ${{ needs.get-main-ref.outputs.branch }}
35
74
- uses : actions/setup-python@v5
36
75
with :
37
- python-version : ' 3.12 '
76
+ python-version : ' 3.9 '
38
77
- run : python -m pip install --upgrade setuptools virtualenv
39
78
- run : pip install -r requirements-dev.txt
40
79
- run : mypy hooks
41
- - run : pytest --cov=hooks --cov-fail-under=100
80
+
81
+ mutate :
82
+ if : ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/all-tests')) }}
83
+ runs-on : ubuntu-latest
84
+ name : Mutation tests
85
+ needs : [get-main-ref, coverage]
86
+ steps :
87
+ - name : Checkout current branch
88
+ uses : actions/checkout@v4
89
+ with :
90
+ ref : ${{ needs.get-main-ref.outputs.branch }}
91
+ - uses : actions/setup-python@v5
92
+ with :
93
+ python-version : ' 3.12'
94
+ - run : python -m pip install --upgrade setuptools virtualenv
95
+ - run : pip install -r requirements-dev.txt
96
+ - run : pytest --cov=hooks
42
97
- run : mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43
98
44
99
combos :
45
- if : github. ref == 'refs/heads/main'
100
+ if : ${{ !needs.get-main- ref.outputs.onPR || (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/all-tests')) }}
46
101
runs-on : ${{ matrix.os }}
47
- name : ${{ matrix.os }} / ${{ matrix.env }}
48
- needs : main
102
+ name : Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
103
+ needs : [get- main-ref, coverage]
49
104
strategy :
50
105
matrix :
51
106
os : [windows-latest, ubuntu-latest, macos-latest]
@@ -61,10 +116,27 @@ jobs:
61
116
- name : Checkout current branch
62
117
uses : actions/checkout@v4
63
118
with :
64
- ref : ${{ github.ref_name }}
119
+ ref : ${{ needs.get-main-ref.outputs.branch }}
65
120
- uses : actions/setup-python@v5
66
121
with :
67
122
python-version : ${{ matrix.env }}
68
123
- run : python -m pip install --upgrade setuptools virtualenv
69
124
- run : pip install -r requirements-dev.txt
70
125
- run : pytest
126
+
127
+ update-pr :
128
+ if : ${{ needs.get-main-ref.outputs.onPR }}
129
+ runs-on : ubuntu-latest
130
+ name : Report back in PR when triggered by comment
131
+ permissions :
132
+ statuses : write
133
+ needs : [get-main-ref, type-check, mutate, combos]
134
+ steps :
135
+ - name : Set final commit status
136
+ uses :
myrotvorets/[email protected]
137
+ if : always()
138
+ with :
139
+ token : ${{ secrets.GITHUB_TOKEN }}
140
+ sha : ${{ needs.get-main-ref.outputs.sha }}
141
+ status : ${{ job.status }}
142
+ context : Run based on PR comment
0 commit comments