diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 197bc58b546..2c15900a12f 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -31,6 +31,8 @@ This document describes the GitHub Actions workflows used in the FORRT website r Builds the Hugo site and deploys to GitHub Pages (`gh-pages` branch). +It uses the newest `data-artifact` and `announcements-artifact` from runs on `main` only. Runs of `data-processing.yml` or `create_announcements.yml` dispatched from another branch, for example to test a pipeline change, upload `*-preview` artifacts (#1030) that production never uses (#960). Staging can opt in to a branch's data artifact only; it never uses branch announcement artifacts. To stage branch data, run `data-processing.yml` on the branch, then dispatch `staging-aggregate.yaml` with `data_branch` set to that branch (combine with `single_pr` to stage only the PR that changes the pipeline). Production never uses it. If a branch other than `main` is named and has no data artifact, staging stops with an error rather than substituting `main`'s data (`data_branch: main` behaves like leaving it empty). For default staging runs and production, a missing data artifact makes the fallback dispatch `data-processing.yml` on `main`; a missing announcements artifact is not regenerated by these workflows. + ### [staging-aggregate.yaml](staging-aggregate.yaml) **Staging deployment for pull requests** @@ -157,4 +159,5 @@ All workflows support `workflow_dispatch` for manual execution via GitHub Action | `cleanup-branches` | `dry_run` | Preview deletions without executing | | `staging-aggregate` | `force_deploy` | Deploy even with no PRs | | `staging-aggregate` | `single_pr` | Deploy only specified PR number | +| `staging-aggregate` | `data_branch` | Use that branch's data artifact instead of main's | | `data-processing` | `skip_deploy` | Skip triggering production deploy | diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 97cb39b7f6f..60f85263b7a 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -64,7 +64,8 @@ jobs: path: . github_token: ${{ secrets.GITHUB_TOKEN }} search_artifacts: true - if_no_artifact_found: warn + branch: main # only main's runs feed deploys; branch test runs must not (#960) + if_no_artifact_found: fail # continue-on-error is set; failure triggers the fallback below # ======================= # Data Processing (Fallback) @@ -89,14 +90,14 @@ jobs: exit 0 fi - # Determine branch ref to dispatch (must be a branch or tag) - REF="${GITHUB_REF#refs/heads/}" - if [ -z "$REF" ]; then - REF="main" - fi + # Always regenerate from main: deploys use main's data only (#960) + REF="main" + # The run this job dispatches is the first one newer than any that exists now + RUNS_URL="https://api.github.com/repos/${{ github.repository }}/actions/workflows/data-processing.yml/runs?event=workflow_dispatch&branch=$REF&per_page=100" + BEFORE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" "$RUNS_URL" | jq '[.workflow_runs[].id] | max // 0') echo "🚀 Dispatching data-processing workflow for ref: $REF because artifact was missing" - curl -s -X POST \ + curl -sSf -X POST \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \ "https://api.github.com/repos/${{ github.repository }}/actions/workflows/data-processing.yml/dispatches" \ @@ -115,9 +116,9 @@ jobs: sleep 10 while [ $attempts -lt $max_attempts ]; do - # Get the latest run triggered by workflow_dispatch + # The first run created after the dispatch is ours runs_json=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ - "https://api.github.com/repos/${{ github.repository }}/actions/workflows/data-processing.yml/runs?event=workflow_dispatch&branch=$REF&per_page=1") + "$RUNS_URL" | jq --argjson before "$BEFORE" '{workflow_runs: [.workflow_runs[] | select(.id > $before)] | sort_by(.id)}') run_id=$(echo "$runs_json" | jq -r '.workflow_runs[0].id') status=$(echo "$runs_json" | jq -r '.workflow_runs[0].status') @@ -172,6 +173,7 @@ jobs: path: .announcements github_token: ${{ secrets.GITHUB_TOKEN }} search_artifacts: true + branch: main # only main's runs feed deploys; branch test runs must not (#960) if_no_artifact_found: warn - name: Apply announcements diff --git a/.github/workflows/rebrand-preview.yaml b/.github/workflows/rebrand-preview.yaml index 406a030f6f5..631ebe11f8f 100644 --- a/.github/workflows/rebrand-preview.yaml +++ b/.github/workflows/rebrand-preview.yaml @@ -76,6 +76,7 @@ jobs: path: ${{ runner.temp }}/artifacts/data github_token: ${{ secrets.GITHUB_TOKEN }} search_artifacts: true + branch: main # as in deploy.yaml: only main's runs, never a branch test run (#960) if_no_artifact_found: warn - name: Download announcements artifact @@ -87,6 +88,7 @@ jobs: path: ${{ runner.temp }}/artifacts/announcements github_token: ${{ secrets.GITHUB_TOKEN }} search_artifacts: true + branch: main # as in deploy.yaml: only main's runs, never a branch test run (#960) if_no_artifact_found: warn - name: Apply artifacts to both checkouts diff --git a/.github/workflows/staging-aggregate.yaml b/.github/workflows/staging-aggregate.yaml index 7bdc77c4c89..5c3a9caa33a 100644 --- a/.github/workflows/staging-aggregate.yaml +++ b/.github/workflows/staging-aggregate.yaml @@ -39,6 +39,11 @@ on: required: false type: boolean default: false + data_branch: + description: 'Use the data artifact from this branch instead of main (to stage a data-processing change; run data-processing.yml on that branch first)' + required: false + type: string + default: '' # Workflow-level concurrency to queue staging builds (wait instead of cancel) concurrency: @@ -280,11 +285,14 @@ jobs: continue-on-error: true with: workflow: data-processing.yml - name: data-artifact + # Branch runs of data-processing.yml upload data-artifact-preview (#1030) + name: ${{ (github.event.inputs.data_branch != '' && github.event.inputs.data_branch != 'main') && 'data-artifact-preview' || 'data-artifact' }} path: .staging-data-artifact github_token: ${{ secrets.GITHUB_TOKEN }} search_artifacts: true - if_no_artifact_found: warn + # main's runs only, unless a manual run names a branch to stage its data (#960) + branch: ${{ github.event.inputs.data_branch || 'main' }} + if_no_artifact_found: fail # continue-on-error is set; failure triggers the fallback below - name: Select newer committed or artifact data if: steps.download-artifact.outcome == 'success' @@ -295,9 +303,17 @@ jobs: # ======================= # Data Processing (Fallback) # ======================= + - name: Stop if the requested branch's data artifact is missing + if: steps.download-artifact.outcome == 'failure' && github.event.inputs.data_branch != '' && github.event.inputs.data_branch != 'main' + env: + DATA_BRANCH: ${{ github.event.inputs.data_branch }} # via env, never interpolated into the script + run: | + echo "::error::No data artifact from branch \"$DATA_BRANCH\". Run data-processing.yml on that branch first; staging won't substitute main's data." + exit 1 + - name: Run data processing if artifact missing id: data-processing - if: steps.download-artifact.outcome == 'failure' + if: steps.download-artifact.outcome == 'failure' && (github.event.inputs.data_branch == '' || github.event.inputs.data_branch == 'main') env: GITHUB_TOKEN: ${{ secrets.FORRT_PAT }} run: | @@ -310,14 +326,14 @@ jobs: exit 0 fi - # Determine branch ref to dispatch (must be a branch or tag) - REF="${GITHUB_REF#refs/heads/}" - if [ -z "$REF" ]; then - REF="main" - fi + # Always regenerate from main: deploys use main's data only (#960) + REF="main" + # The run this job dispatches is the first one newer than any that exists now + RUNS_URL="https://api.github.com/repos/${{ github.repository }}/actions/workflows/data-processing.yml/runs?event=workflow_dispatch&branch=$REF&per_page=100" + BEFORE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" "$RUNS_URL" | jq '[.workflow_runs[].id] | max // 0') echo "🚀 Dispatching data-processing workflow for ref: $REF because artifact was missing" - curl -s -X POST \ + curl -sSf -X POST \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \ "https://api.github.com/repos/${{ github.repository }}/actions/workflows/data-processing.yml/dispatches" \ @@ -336,9 +352,9 @@ jobs: sleep 10 while [ $attempts -lt $max_attempts ]; do - # Get the latest run triggered by workflow_dispatch + # The first run created after the dispatch is ours runs_json=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ - "https://api.github.com/repos/${{ github.repository }}/actions/workflows/data-processing.yml/runs?event=workflow_dispatch&branch=$REF&per_page=1") + "$RUNS_URL" | jq --argjson before "$BEFORE" '{workflow_runs: [.workflow_runs[] | select(.id > $before)] | sort_by(.id)}') run_id=$(echo "$runs_json" | jq -r '.workflow_runs[0].id') status=$(echo "$runs_json" | jq -r '.workflow_runs[0].status')