Scheduled Testing / Staging #109
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Scheduled Testing / Staging" | |
on: | |
schedule: | |
- cron: '0 * * * *' | |
workflow_dispatch: | |
jobs: | |
test-scheduled-main: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
with: | |
ref: feat/api-1_0_0_beta_7 | |
fetch-depth: 0 | |
- name: Install uv | |
uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d # v7.1.0 | |
with: | |
version-file: "pyproject.toml" | |
enable-cache: true | |
cache-dependency-glob: uv.lock | |
- name: Install dev tools | |
shell: bash | |
run: .github/workflows/_install_dev_tools.bash | |
- name: Install Python, venv and dependencies | |
shell: bash | |
run: uv sync --all-extras --frozen --link-mode=copy | |
- name: Create .env file | |
shell: bash | |
run: | | |
cat > .env << EOF | |
AIGNOSTICS_API_ROOT=https://platform-staging.aignostics.com | |
AIGNOSTICS_CLIENT_ID_DEVICE=${{ secrets.AIGNOSTICS_CLIENT_ID_DEVICE_STAGING }} | |
AIGNOSTICS_REFRESH_TOKEN=${{ secrets.AIGNOSTICS_REFRESH_TOKEN_STAGING }} | |
EOF | |
- name: Set up GCP credentials for bucket access | |
shell: bash | |
env: | |
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS_STAGING }} | |
run: | | |
echo "$GCP_CREDENTIALS" | base64 -d > credentials.json | |
echo "GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/credentials.json" >> $GITHUB_ENV | |
- name: Test / scheduled | |
env: | |
BETTERSTACK_HEARTBEAT_URL: "${{ secrets.BETTERSTACK_HEARTBEAT_URL_STAGING }}" | |
shell: bash | |
run: | | |
set +e | |
make test_scheduled | |
EXIT_CODE=$? | |
# Show test execution in GitHub Job summary | |
found_files=0 | |
for file in reports/pytest_*.md; do | |
if [ -f "$file" ]; then | |
cat "$file" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
found_files=1 | |
fi | |
done | |
if [ $found_files -eq 0 ]; then | |
echo "# All scheduled tests passed" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
fi | |
# Show test coverage in GitHub Job summary | |
if [ -f "reports/coverage.md" ]; then | |
cat "reports/coverage.md" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
else | |
echo "# No test coverage computed." >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
fi | |
# 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")" \ | |
'{ | |
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, | |
}, | |
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}'" | |
else | |
echo "WARNING: No BetterStack heartbeat URL configured, skipped heartbeat notification." | |
fi | |
exit $EXIT_CODE | |
- name: Upload test results | |
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 | |
if: always() | |
with: | |
name: test-results-scheduled-main | |
path: | | |
reports/junit.xml | |
reports/coverage.xml | |
reports/coverage.md | |
reports/coverage_html | |
aignostics.log | |
retention-days: 7 |