-
Notifications
You must be signed in to change notification settings - Fork 6
248 lines (214 loc) · 8.64 KB
/
tests.yml
File metadata and controls
248 lines (214 loc) · 8.64 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
name: Tests
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
schedule:
# https://crontab.guru/#15_14_*_*_*
- cron: 15 14 * * *
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
pytest:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Cache Pip
uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2
with:
path: ~/.cache/pip
# invalidate the cache anytime a requirements.txt changes
key: ${{ github.workflow }}-${{ hashFiles('**/requirements.txt') }}
- name: Setup Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: '>=3.9'
- name: Install Dependencies
run: pip install --quiet -r requirements.txt -r combine-durations/requirements.txt -r template-files/requirements.txt
- name: Run Tests
run: pytest
- name: Upload Coverage
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
read-file:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Read Remote JSON
id: json
uses: ./read-file
env:
# `full_name` is the org/repo slug, extracting from `head` in case PR was opened via a fork
FULL_NAME: ${{ github.event.pull_request.head.repo.full_name || github.event.repository.full_name }}
# `head_ref` is the pull_request branch
# `ref_name` is the push/workflow_dispatch/schedule branch
REF: ${{ github.head_ref || github.ref_name }}
with:
path: https://raw.githubusercontent.com/${{ env.FULL_NAME }}/refs/heads/${{ env.REF }}/read-file/data/json.json
parser: json
- name: Read Local YAML
id: yaml
uses: ./read-file
with:
path: ./read-file/data/yaml.yaml
parser: yaml
- name: Setup Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: '>=3.9'
- name: Run Tests
shell: python
run: |
assert '''${{ steps.json.outputs.content }}''' == '''${{ steps.yaml.outputs.content }}'''
assert '''${{ fromJSON(steps.json.outputs.content)['foo'] }}''' == '''${{ fromJSON(steps.yaml.outputs.content)['foo'] }}'''
template-files:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Template Success
id: templates-success
uses: ./template-files
with:
config: ./template-files/data/success.yml
stubs: ./template-files/data/templates
- name: Template Error
id: templates-error
continue-on-error: true
uses: ./template-files
with:
config: ./template-files/data/error.yml
stubs: ./template-files/data/templates
- name: Run Tests
run: diff --recursive .github_cache/template-files template-files/data/expected
- name: Filter Changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
code:
- 'template-files/**'
- name: Comment on PR
if: github.event_name == 'pull_request' && steps.filter.outputs.code == 'true'
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
with:
message: |
### Template Success
> [!WARNING]
> This is what the audit looks like when the templating has no errors.
${{ steps.templates-success.outputs.summary }}
### Template Error
> [!WARNING]
> This is what the audit looks like when templating results in errors.
${{ steps.templates-error.outputs.summary }}
GITHUB_TOKEN: ${{ secrets.SANDBOX_TEMPLATE_TOKEN }}
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Filter Changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
lint:
- 'lint/**'
# Test 1: Success case - clean code should pass lint
- name: Run lint on success test data
id: lint-success
continue-on-error: true
uses: ./lint
env:
WORKING_DIRECTORY: lint/data/success
with:
token: ${{ secrets.SANDBOX_TEMPLATE_TOKEN }}
checkout: false
working-directory: ${{ env.WORKING_DIRECTORY }}
config: pre-commit-config.yaml
# Only comment on PR if lint code changed
pr-number: ${{ steps.filter.outputs.lint == 'true' && github.event.pull_request.number || '' }}
comment-anchor: lint-comment-test-success
comment-on-success: ${{ steps.filter.outputs.lint == 'true' }}
comment-header: |
> [!WARNING]
> **Working directory:** `${{ env.WORKING_DIRECTORY }}`
> This is what the lint comment looks like when there are no lint issues.
# Test 2: Error case - code with issues should fail lint
- name: Run lint on error test data
id: lint-error
continue-on-error: true
uses: ./lint
env:
WORKING_DIRECTORY: lint/data/error
with:
token: ${{ secrets.SANDBOX_TEMPLATE_TOKEN }}
checkout: false
working-directory: ${{ env.WORKING_DIRECTORY }}
config: pre-commit-config.yaml
# Only comment on PR if lint code changed
pr-number: ${{ steps.filter.outputs.lint == 'true' && github.event.pull_request.number || '' }}
comment-anchor: lint-comment-test-error
comment-header: |
> [!WARNING]
> **Working directory:** `${{ env.WORKING_DIRECTORY }}`
> This is what the lint comment looks like when there are lint issues.
- name: Reset test data changes
run: git checkout -- lint/data/
# Verify all test outcomes
- name: Verify test outcomes
run: |
failed=0
# Test 1: Success case should pass
if [[ "${{ steps.lint-success.outputs.outcome }}" != "success" ]]; then
echo "::error::Test 1 (success): Expected outcome=success, got ${{ steps.lint-success.outputs.outcome }}"
failed=1
fi
if [[ -z "${{ steps.lint-success.outputs.output }}" ]]; then
echo "::error::Test 1 (success): Expected output to be non-empty"
failed=1
fi
# Test 2: Error case should fail
if [[ "${{ steps.lint-error.outputs.outcome }}" != "failure" ]]; then
echo "::error::Test 2 (error): Expected outcome=failure, got ${{ steps.lint-error.outputs.outcome }}"
failed=1
fi
if ! echo "${{ steps.lint-error.outputs.output }}" | grep -q "F401"; then
echo "::error::Test 2 (error): Expected output to contain F401 (unused import)"
failed=1
fi
if [[ -z "${{ steps.lint-error.outputs.diff }}" ]]; then
echo "::error::Test 2 (error): Expected diff output to be non-empty"
failed=1
fi
exit $failed
# required check
analyze:
needs: [pytest, read-file, template-files, lint]
if: '!cancelled()'
runs-on: ubuntu-latest
steps:
- name: Determine Success
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
id: alls-green
with:
jobs: ${{ toJSON(needs) }}
- name: Checkout our source
if: always() && github.event_name != 'pull_request' && steps.alls-green.outputs.result == 'failure'
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Report failures
if: always() && github.event_name != 'pull_request' && steps.alls-green.outputs.result == 'failure'
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
env:
GITHUB_TOKEN: ${{ secrets.AUTO_REPORT_TEST_FAILURE }}
RUN_ID: ${{ github.run_id }}
TITLE: 🤖 Tests Failed
with:
filename: .github/TEST_FAILURE_REPORT_TEMPLATE.md
update_existing: true