| 1 | name: Nightly release candidate |
| 2 | |
| 3 | # Starts release-candidate.yml for the current main commit once a day, so a |
| 4 | # release called the next day already has its candidate receipt. It only |
| 5 | # dispatches: it publishes nothing and holds no release secret, and the |
| 6 | # candidate it starts runs with nightly=true (unsigned manifest). |
| 7 | # |
| 8 | # It dispatches only when main's tip has no release-candidate run yet, no |
| 9 | # candidate is already queued or building, and the tip has a green full CI |
| 10 | # run (scripts/release/require-full-ci-receipt.sh). Otherwise it records why |
| 11 | # in the run summary and waits for the next night. |
| 12 | # |
| 13 | # Schedules run only from the default branch, and GitHub disables them after |
| 14 | # 60 days without repository activity. |
| 15 | on: |
| 16 | schedule: |
| 17 | - cron: '47 14 * * *' |
| 18 | workflow_dispatch: |
| 19 | inputs: |
| 20 | dry_run: |
| 21 | description: Report the decision without dispatching release-candidate.yml |
| 22 | required: false |
| 23 | default: false |
| 24 | type: boolean |
| 25 | |
| 26 | permissions: |
| 27 | contents: read |
| 28 | |
| 29 | concurrency: |
| 30 | group: nightly-candidate |
| 31 | cancel-in-progress: false |
| 32 | |
| 33 | jobs: |
| 34 | dispatch: |
| 35 | name: Dispatch nightly candidate |
| 36 | timeout-minutes: 10 |
| 37 | runs-on: ubuntu-24.04 |
| 38 | permissions: |
| 39 | actions: write |
| 40 | contents: read |
| 41 | steps: |
| 42 | - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 43 | with: |
| 44 | sparse-checkout: scripts/release |
| 45 | persist-credentials: false |
| 46 | - name: Decide whether main needs a candidate |
| 47 | id: decide |
| 48 | env: |
| 49 | GH_TOKEN: ${{ github.token }} |
| 50 | DRY_RUN: ${{ inputs.dry_run }} |
| 51 | run: | |
| 52 | set -euo pipefail |
| 53 | sha="$(gh api "repos/${GITHUB_REPOSITORY}/commits/main" --jq .sha)" |
| 54 | if [[ "${#sha}" -ne 40 || "${sha}" =~ [^0-9a-f] ]]; then |
| 55 | echo "::error::Could not resolve main to a commit SHA, got '${sha}'." >&2 |
| 56 | exit 1 |
| 57 | fi |
| 58 | candidates="$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/release-candidate.yml/runs?head_sha=${sha}&per_page=100" \ |
| 59 | --jq "[.workflow_runs[] | select(.head_sha == \"${sha}\")] | length")" |
| 60 | building="$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/release-candidate.yml/runs?per_page=50" \ |
| 61 | --jq '[.workflow_runs[] | select(.status != "completed")] | length')" |
| 62 | if [[ "${candidates}" != "0" ]]; then |
| 63 | decision=skip |
| 64 | reason="main (${sha}) already has a release-candidate run; main has not moved since." |
| 65 | elif [[ "${building}" != "0" ]]; then |
| 66 | decision=skip |
| 67 | reason="a release candidate is already queued or building; not stacking another." |
| 68 | elif receipt="$(bash scripts/release/require-full-ci-receipt.sh "${GITHUB_REPOSITORY}" "${sha}" 2>&1)"; then |
| 69 | decision=dispatch |
| 70 | reason="${receipt}" |
| 71 | else |
| 72 | decision=skip |
| 73 | reason="main (${sha}) has no green full CI run (red, still running, or only scoped); no candidate tonight. ${receipt//$'\n'/ }" |
| 74 | echo "::warning::${reason}" |
| 75 | fi |
| 76 | echo "sha=${sha}" >> "${GITHUB_OUTPUT}" |
| 77 | echo "decision=${decision}" >> "${GITHUB_OUTPUT}" |
| 78 | if [[ "${DRY_RUN}" == "true" ]]; then reason="${reason} (dry run: nothing dispatched)"; fi |
| 79 | echo "${decision}: ${reason}" | tee -a "${GITHUB_STEP_SUMMARY}" |
| 80 | - name: Dispatch release-candidate.yml for main |
| 81 | if: steps.decide.outputs.decision == 'dispatch' && !inputs.dry_run |
| 82 | env: |
| 83 | GH_TOKEN: ${{ github.token }} |
| 84 | SHA: ${{ steps.decide.outputs.sha }} |
| 85 | run: | |
| 86 | set -euo pipefail |
| 87 | gh workflow run release-candidate.yml --repo "${GITHUB_REPOSITORY}" --ref main \ |
| 88 | -f expected_sha="${SHA}" -f nightly=true |
| 89 | echo "Dispatched release-candidate.yml (nightly) for ${SHA}." | tee -a "${GITHUB_STEP_SUMMARY}" |
| 90 |