Skip to content

Health Check

Health Check #5976

Workflow file for this run

name: Health Check
on:
schedule:
- cron: "0 * * * *"
workflow_dispatch:
concurrency:
group: health-check
cancel-in-progress: true
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
health-check:
runs-on: ubuntu-24.04
permissions:
issues: write
contents: read
steps:
- name: Check endpoints
id: check
run: |
set +e
failures=""
check_url() {
name="$1"
url="$2"
if [ -z "$url" ]; then
echo "::notice::$name URL is not configured; skipping."
return
fi
http_code=$(curl --silent --show-error --output /dev/null --write-out "%{http_code}" --max-time 10 "$url/api/health")
curl_status=$?
if [ "$curl_status" -ne 0 ] || [ "$http_code" -ne 200 ]; then
failures="${failures}${name}: ${url}/api/health returned ${http_code} (curl exit ${curl_status})%0A"
echo "::error::$name health check failed with HTTP $http_code"
else
echo "$name health check passed with HTTP $http_code"
fi
}
check_url "production" "${{ secrets.PROD_URL }}"
check_url "development" "${{ secrets.DEV_URL }}"
if [ -n "$failures" ]; then
echo "failed=true" >> "$GITHUB_OUTPUT"
echo "failures=$failures" >> "$GITHUB_OUTPUT"
exit 1
fi
echo "failed=false" >> "$GITHUB_OUTPUT"
- name: Find existing health-check issue
id: existing_issue
if: failure() && steps.check.outputs.failed == 'true'
uses: actions/github-script@v8
with:
script: |
const { owner, repo } = context.repo;
const { data } = await github.rest.search.issuesAndPullRequests({
q: `repo:${owner}/${repo} is:issue is:open in:title "Application Health Check Failed"`,
per_page: 1,
});
core.setOutput("number", data.items[0]?.number || "");
- name: Create health-check issue
if: failure() && steps.check.outputs.failed == 'true' && steps.existing_issue.outputs.number == ''
uses: actions/github-script@v8
with:
script: |
const body = [
"The scheduled health check failed.",
"",
"${{ steps.check.outputs.failures }}".replaceAll("%0A", "\n"),
"",
`Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
].join("\n");
await github.rest.issues.create({
...context.repo,
title: "Application Health Check Failed",
body,
});
- name: Update existing health-check issue
if: failure() && steps.check.outputs.failed == 'true' && steps.existing_issue.outputs.number != ''
uses: actions/github-script@v8
with:
script: |
const body = [
"The scheduled health check is still failing.",
"",
"${{ steps.check.outputs.failures }}".replaceAll("%0A", "\n"),
"",
`Latest workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
].join("\n");
await github.rest.issues.createComment({
...context.repo,
issue_number: Number("${{ steps.existing_issue.outputs.number }}"),
body,
});
- name: Fail workflow after reporting
if: failure() && steps.check.outputs.failed == 'true'
run: |
exit 1