-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (168 loc) · 6.57 KB
/
main.yml
File metadata and controls
175 lines (168 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Typecheck & run tests
on:
push:
branches:
- 'main'
- 'feature/*'
- 'bugfix/*'
issue_comment:
types: [created]
jobs:
get-command:
runs-on: ubuntu-latest
name: Get ref to check out (based on branch or PR)
permissions:
statuses: write
steps:
- name: Are we triggered by a known comment-command?
id: get-command
run: |
doTypeCheck=${{ contains(github.event.comment.body, '/type-check') }}
echo "doTypeCheck=$doTypeCheck" >> "$GITHUB_OUTPUT"
doMutate=${{ contains(github.event.comment.body, '/mutate') }}
echo "doMutate=$doMutate" >> "$GITHUB_OUTPUT"
doCombos=${{ contains(github.event.comment.body, '/combos') }}
echo "doCombos=$doCombos" >> "$GITHUB_OUTPUT"
doAll=${{ contains(github.event.comment.body, '/all-tests') }}
echo "doAll=$doAll" >> "$GITHUB_OUTPUT"
commentCommand=false
if [ "$doTypeCheck" = "true" ]; then
commentCommand=true
command="type-check"
elif [ "$doMutate" = "true" ]; then
commentCommand=true
command="mutate"
elif [ "$doCombos" = "true" ]; then
commentCommand=true
command="combos"
elif [ "$doAll" = "true" ]; then
commentCommand=true
command="all"
fi
echo "commentCommand=$commentCommand" >> "$GITHUB_OUTPUT"
echo "command=$command" >> "$GITHUB_OUTPUT"
- name: Get PR's branch name
id: from-pr
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
run: |
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }})
echo "onPR=true" >> "$GITHUB_OUTPUT"
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT"
echo "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT"
- name: Bind check in PR
id: bind-pr
if: ${{ steps.get-command.outputs.commentCommand == 'true' }}
uses: myrotvorets/set-commit-status-action@v2.0.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ steps.from-pr.outputs.sha }}
status: pending
context: Run based on PR comment (${{ steps.get-command.outputs.command }})
- name: Get current branch name
id: from-branch
if: ${{ steps.get-command.outputs.commentCommand != 'true' }}
run: |
echo "onPR=false" >> "$GITHUB_OUTPUT"
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
echo "sha=..." >> "$GITHUB_OUTPUT"
outputs:
commentCommand: ${{ steps.get-command.outputs.commentCommand }}
command: ${{ steps.get-command.outputs.command }}
doTypeCheck: ${{ steps.get-command.outputs.doTypeCheck }}
doMutate: ${{ steps.get-command.outputs.doMutate }}
doCombos: ${{ steps.get-command.outputs.doCombos }}
doAll: ${{ steps.get-command.outputs.doAll }}
onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }}
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
sha: ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }}
coverage:
runs-on: ubuntu-latest
name: Check coverage
needs: [get-command]
steps:
- name: Checkout current branch
uses: actions/checkout@v4
with:
ref: ${{ needs.get-command.outputs.branch }}
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- run: python -m pip install --upgrade setuptools virtualenv
- run: pip install -r requirements-dev.txt
- run: pytest --cov=hooks --cov-fail-under=100
type-check:
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doTypeCheck == 'true' || needs.get-command.outputs.doAll == 'true' }}
runs-on: ubuntu-latest
name: Type checking
needs: [get-command]
steps:
- name: Checkout current branch
uses: actions/checkout@v4
with:
ref: ${{ needs.get-command.outputs.branch }}
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- run: python -m pip install --upgrade setuptools virtualenv
- run: pip install -r requirements-dev.txt
- run: mypy hooks
mutate:
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doMutate == 'true' || needs.get-command.outputs.doAll == 'true' }}
runs-on: ubuntu-latest
name: Mutation tests
needs: [get-command, coverage]
steps:
- name: Checkout current branch
uses: actions/checkout@v4
with:
ref: ${{ needs.get-command.outputs.branch }}
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python -m pip install --upgrade setuptools virtualenv
- run: pip install -r requirements-dev.txt
- run: pytest --cov=hooks
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
combos:
if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doCombos == 'true' || needs.get-command.outputs.doAll == 'true' }}
runs-on: ${{ matrix.os }}
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }}
needs: [get-command]
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
env: ['3.9', '3.10', '3.11', '3.12']
exclude:
# exclude the coverage combo, no need to re-run it
- os: ubuntu-latest
env: '3.9'
# exclude the mutate combo, no need to re-run it
- os: ubuntu-latest
env: '3.12'
steps:
- name: Checkout current branch
uses: actions/checkout@v4
with:
ref: ${{ needs.get-command.outputs.branch }}
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.env }}
- run: python -m pip install --upgrade setuptools virtualenv
- run: pip install -r requirements-dev.txt
- run: pytest
update-pr:
if: ${{ always() }}
runs-on: ubuntu-latest
name: Report back in PR when triggered by comment
permissions:
statuses: write
needs: [get-command, type-check, mutate, combos]
steps:
- name: Set final commit status
uses: myrotvorets/set-commit-status-action@v2.0.1
if: ${{ needs.get-command.outputs.commentCommand == 'true' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ needs.get-command.outputs.sha }}
status: ${{ job.status }}
context: Run based on PR comment (${{ needs.get-command.outputs.command }})