-
Notifications
You must be signed in to change notification settings - Fork 0
236 lines (216 loc) · 8.51 KB
/
_scheduled-test-daily.yml
File metadata and controls
236 lines (216 loc) · 8.51 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
name: "> Scheduled Test (Daily)"
on:
workflow_call:
inputs:
deploy_env:
description: 'Deployment environment (dev, test, staging, production)'
required: true
type: string
secrets:
BETTERSTACK_HEARTBEAT_URL_DAILY:
required: false
CODECOV_TOKEN:
required: false
SONAR_TOKEN:
required: false
jobs:
test-scheduled-daily:
runs-on: ubuntu-latest
permissions:
attestations: write
contents: read
id-token: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Setup Dev Environment
uses: ./.github/actions/setup-dev-env
- name: Print development version info
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
TOML_VERSION=$(uv run python -c "import tomli; print(tomli.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "Development build - Current version in pyproject.toml: $TOML_VERSION"
- name: Validate and set environment suffix
id: env_suffix
env:
DEPLOY_ENV: ${{ inputs.deploy_env }}
shell: bash
run: |
# Validate deploy_env is one of the allowed values
case "$DEPLOY_ENV" in
dev|test|staging|production)
# Convert to uppercase
SUFFIX=$(echo "$DEPLOY_ENV" | tr '[:lower:]' '[:upper:]')
echo "suffix=${SUFFIX}" >> $GITHUB_OUTPUT
;;
*)
echo "Error: Invalid deploy_env value '$DEPLOY_ENV'. Must be one of: dev, test, staging, production"
exit 1
;;
esac
- name: Test / Unit
id: unit
continue-on-error: true
uses: ./.github/actions/run-tests
with:
test-type: unit
mise-task: test_unit
skip-marker: skip:test:unit
summary-title: All unit tests passed
commit-message: ${{ github.event.head_commit.message }}
- name: Test / Integration
id: integration
continue-on-error: true
uses: ./.github/actions/run-tests
with:
test-type: integration
mise-task: test_integration
skip-marker: skip:test:integration
summary-title: All integration tests passed
commit-message: ${{ github.event.head_commit.message }}
- name: Test / E2E
id: e2e
continue-on-error: true
uses: ./.github/actions/run-tests
with:
test-type: e2e
mise-task: test_e2e
skip-marker: skip:test:e2e
summary-title: All e2e tests passed
commit-message: ${{ github.event.head_commit.message }}
- name: Upload test artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: ${{ always() && (env.GITHUB_WORKFLOW_RUNTIME != 'ACT') }}
with:
name: test-results-scheduled-daily-${{ inputs.deploy_env }}
path: |
reports/junit_*.xml
reports/coverage.xml
reports/coverage.md
reports/coverage_html
aignostics_foundry_core.log
retention-days: 7
- name: Determine overall test status
id: test-status
if: always()
shell: bash
run: |
# Track which test types failed
FAILED_TESTS=()
EXIT_CODE=0
if [ "${{ steps.unit.outcome }}" == "failure" ]; then
FAILED_TESTS+=("unit")
EXIT_CODE=1
fi
if [ "${{ steps.integration.outcome }}" == "failure" ]; then
FAILED_TESTS+=("integration")
EXIT_CODE=1
fi
if [ "${{ steps.e2e.outcome }}" == "failure" ]; then
FAILED_TESTS+=("e2e")
EXIT_CODE=1
fi
# Export for next steps
echo "exit_code=${EXIT_CODE}" >> $GITHUB_OUTPUT
if [ ${#FAILED_TESTS[@]} -eq 0 ]; then
echo "failed_tests=none" >> $GITHUB_OUTPUT
echo "All test types passed" >> $GITHUB_STEP_SUMMARY
else
FAILED_LIST=$(IFS=,; echo "${FAILED_TESTS[*]}")
echo "failed_tests=${FAILED_LIST}" >> $GITHUB_OUTPUT
echo "Failed test types: ${FAILED_LIST}" >> $GITHUB_STEP_SUMMARY
fi
- name: Heartbeat
if: always()
env:
BETTERSTACK_HEARTBEAT_URL: "${{ secrets.BETTERSTACK_HEARTBEAT_URL_DAILY }}"
DEPLOY_ENV: ${{ inputs.deploy_env }}
TEST_EXIT_CODE: ${{ steps.test-status.outputs.exit_code }}
TEST_FAILED_TESTS: ${{ steps.test-status.outputs.failed_tests }}
shell: bash
run: |
EXIT_CODE="${TEST_EXIT_CODE}"
FAILED_TESTS="${TEST_FAILED_TESTS}"
# Provide heartbeat to BetterStack for monitoring/alerting if heartbeat url is configured as secret
if [ -n "$BETTERSTACK_HEARTBEAT_URL" ]; then
BETTERSTACK_METADATA_PAYLOAD=$(jq -n \
--arg github_workflow "${{ github.workflow }}" \
--arg github_run_url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
--arg github_run_id "${{ github.run_id }}" \
--arg github_job "${{ github.job }}" \
--arg github_sha "${{ github.sha }}" \
--arg github_actor "${{ github.actor }}" \
--arg github_repository "${{ github.repository }}" \
--arg github_ref "${{ github.ref }}" \
--arg job_status "${{ job.status }}" \
--arg github_event_name "${{ github.event_name }}" \
--arg timestamp "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--arg failed_tests "${FAILED_TESTS}" \
--arg unit_status "${{ steps.unit.outcome }}" \
--arg integration_status "${{ steps.integration.outcome }}" \
--arg e2e_status "${{ steps.e2e.outcome }}" \
'{
github: {
workflow: $github_workflow,
run_url: $github_run_url,
run_id: $github_run_id,
job: $github_job,
sha: $github_sha,
actor: $github_actor,
repository: $github_repository,
ref: $github_ref,
event_name: $github_event_name
},
job: {
status: $job_status,
},
tests: {
failed: $failed_tests,
unit: $unit_status,
integration: $integration_status,
e2e: $e2e_status
},
timestamp: $timestamp,
}'
)
curl \
--fail-with-body \
--silent \
--request POST \
--header "Content-Type: application/json" \
--data-binary "${BETTERSTACK_METADATA_PAYLOAD}" \
"${BETTERSTACK_HEARTBEAT_URL}/${EXIT_CODE}"
echo "INFO: Sent heartbeat to BetterStack with exit code '${EXIT_CODE}' and failed tests: '${FAILED_TESTS}'"
else
echo "INFO: No BetterStack heartbeat URL configured, skipped heartbeat notification."
fi
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
if: ${{ !cancelled() && (env.GITHUB_WORKFLOW_RUNTIME != 'ACT') }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: aignostics/foundry-python-core
- name: Upload test results to Codecov
if: ${{ !cancelled() && (env.GITHUB_WORKFLOW_RUNTIME != 'ACT') }}
uses: codecov/test-results-action@0fa95f0e1eeaafde2c782583b36b28ad0d8c77d3 # v1.2.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: SonarQube Scan
if: ${{ !cancelled() && (env.GITHUB_WORKFLOW_RUNTIME != 'ACT') }}
uses: SonarSource/sonarqube-scan-action@299e4b793aaa83bf2aba7c9c14bedbb485688ec4 # v7.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Fail workflow if any tests failed
if: always()
shell: bash
run: |
EXIT_CODE=${{ steps.test-status.outputs.exit_code }}
if [ "$EXIT_CODE" != "0" ]; then
echo "Workflow failed due to test failures: ${{ steps.test-status.outputs.failed_tests }}"
exit $EXIT_CODE
fi