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