|
| 1 | +name: Biweekly API Health Check |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Every Monday at 08:00 UTC — the 'check-week' job skips odd ISO weeks |
| 6 | + # so the effective cadence is every other week. |
| 7 | + - cron: "0 8 * * 1" |
| 8 | + workflow_dispatch: # allow manual triggers anytime |
| 9 | + |
| 10 | +permissions: read-all |
| 11 | + |
| 12 | +# ── Gate job: skip odd ISO weeks so we run biweekly ────────────── |
| 13 | +jobs: |
| 14 | + check-week: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + should_run: ${{ steps.week_check.outputs.should_run }} |
| 18 | + steps: |
| 19 | + - id: week_check |
| 20 | + run: | |
| 21 | + WEEK=$(date +%V) |
| 22 | + if [ $((WEEK % 2)) -eq 0 ]; then |
| 23 | + echo "should_run=true" >> "$GITHUB_OUTPUT" |
| 24 | + else |
| 25 | + echo "should_run=false" >> "$GITHUB_OUTPUT" |
| 26 | + fi |
| 27 | +
|
| 28 | + # ── Main test job ────────────────────────────────────────────── |
| 29 | + api-health-check: |
| 30 | + needs: check-week |
| 31 | + if: >- |
| 32 | + needs.check-week.outputs.should_run == 'true' |
| 33 | + || github.event_name == 'workflow_dispatch' |
| 34 | + runs-on: ubuntu-latest |
| 35 | + |
| 36 | + env: |
| 37 | + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + ENTSOE_PAT: ${{ secrets.ENTSOE_PAT }} |
| 39 | + R_KEEP_PKG_SOURCE: yes |
| 40 | + |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + ref: main |
| 45 | + |
| 46 | + - uses: r-lib/actions/setup-pandoc@v2 |
| 47 | + |
| 48 | + - uses: r-lib/actions/setup-r@v2 |
| 49 | + with: |
| 50 | + r-version: release |
| 51 | + use-public-rspm: true |
| 52 | + |
| 53 | + - uses: r-lib/actions/setup-r-dependencies@v2 |
| 54 | + with: |
| 55 | + extra-packages: any::devtools, any::rcmdcheck |
| 56 | + needs: check |
| 57 | + |
| 58 | + - name: Run examples |
| 59 | + run: | |
| 60 | + Rscript -e ' |
| 61 | + devtools::load_all(".") |
| 62 | + tryCatch( |
| 63 | + devtools::run_examples(".", run_donttest = FALSE, run_dontrun = FALSE), |
| 64 | + error = function(e) { |
| 65 | + cli::cli_alert_danger("Examples failed: {conditionMessage(e)}") |
| 66 | + quit(status = 1L) |
| 67 | + } |
| 68 | + ) |
| 69 | + ' |
| 70 | +
|
| 71 | + - name: Run unit tests |
| 72 | + run: | |
| 73 | + Rscript -e ' |
| 74 | + res <- devtools::test(".", reporter = "summary") |
| 75 | + if (any(as.data.frame(res)$failed > 0)) quit(status = 1L) |
| 76 | + ' |
| 77 | +
|
| 78 | + # ── Retry job: waits 1 hour, then re-runs (handles 503s) ────── |
| 79 | + retry-on-503: |
| 80 | + needs: api-health-check |
| 81 | + if: failure() |
| 82 | + runs-on: ubuntu-latest |
| 83 | + |
| 84 | + env: |
| 85 | + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + ENTSOE_PAT: ${{ secrets.ENTSOE_PAT }} |
| 87 | + R_KEEP_PKG_SOURCE: yes |
| 88 | + |
| 89 | + steps: |
| 90 | + - name: Wait 1 hour before retry |
| 91 | + run: sleep 3600 |
| 92 | + |
| 93 | + - uses: actions/checkout@v4 |
| 94 | + with: |
| 95 | + ref: main |
| 96 | + |
| 97 | + - uses: r-lib/actions/setup-pandoc@v2 |
| 98 | + |
| 99 | + - uses: r-lib/actions/setup-r@v2 |
| 100 | + with: |
| 101 | + r-version: release |
| 102 | + use-public-rspm: true |
| 103 | + |
| 104 | + - uses: r-lib/actions/setup-r-dependencies@v2 |
| 105 | + with: |
| 106 | + extra-packages: any::devtools, any::rcmdcheck |
| 107 | + needs: check |
| 108 | + |
| 109 | + - name: Run examples (retry) |
| 110 | + run: | |
| 111 | + Rscript -e ' |
| 112 | + devtools::load_all(".") |
| 113 | + tryCatch( |
| 114 | + devtools::run_examples(".", run_donttest = FALSE, run_dontrun = FALSE), |
| 115 | + error = function(e) { |
| 116 | + cli::cli_alert_danger("Examples failed: {conditionMessage(e)}") |
| 117 | + quit(status = 1L) |
| 118 | + } |
| 119 | + ) |
| 120 | + ' |
| 121 | +
|
| 122 | + - name: Run unit tests (retry) |
| 123 | + run: | |
| 124 | + Rscript -e ' |
| 125 | + res <- devtools::test(".", reporter = "summary") |
| 126 | + if (any(as.data.frame(res)$failed > 0)) quit(status = 1L) |
| 127 | + ' |
| 128 | +
|
| 129 | + # ── Notification: opens an issue when both attempts fail ─────── |
| 130 | + notify-failure: |
| 131 | + needs: [api-health-check, retry-on-503] |
| 132 | + if: failure() |
| 133 | + runs-on: ubuntu-latest |
| 134 | + permissions: |
| 135 | + issues: write |
| 136 | + |
| 137 | + steps: |
| 138 | + - name: Create GitHub Issue on failure |
| 139 | + uses: actions/github-script@v7 |
| 140 | + with: |
| 141 | + script: | |
| 142 | + const title = `API Health Check failed – ${new Date().toISOString().slice(0, 10)}`; |
| 143 | + const body = [ |
| 144 | + '## Biweekly API Health Check Failed', |
| 145 | + '', |
| 146 | + 'Both the initial run and the 1-hour retry have failed.', |
| 147 | + '', |
| 148 | + `**Workflow run:** ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, |
| 149 | + '', |
| 150 | + 'This may indicate:', |
| 151 | + '- A breaking change in the ENTSO-E API', |
| 152 | + '- Prolonged API downtime (HTTP 503)', |
| 153 | + '- A regression in the `main` branch', |
| 154 | + '', |
| 155 | + 'Please investigate the workflow logs for details.', |
| 156 | + ].join('\n'); |
| 157 | +
|
| 158 | + await github.rest.issues.create({ |
| 159 | + owner: context.repo.owner, |
| 160 | + repo: context.repo.repo, |
| 161 | + title, |
| 162 | + body, |
| 163 | + labels: ['bug', 'api-health'], |
| 164 | + }); |
0 commit comments