GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Automation and CI / data-gridatlas / .github/workflows

Publish Renewable Energy Planning Database (REPD) Routing Workflow and 1 more file

A GitHub Actions workflow in Data GridAtlas that builds and publishes the site using data from GitHub API. Runs on push and by hand.

687 lines of YAML from data-gridatlas, in 2 files. Topic: Automation and CI. Section 1703 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Verify Live Pointer Workflow automation · data-gridatlas / .github/workflows/202608291239-verify-live-pointer.yml lines 1–332
  2. Publish Renewable Energy Planning Database (REPD) Routing Workflow automation · data-gridatlas / .github/workflows/202608291410-publish-repd-routing.yml lines 1–355

Verify Live Pointer Workflow

A GitHub Actions workflow in Data GridAtlas using data from GitHub API and the GridAtlas repository. Runs on push.

automationdata-gridatlas / .github/workflows/202608291239-verify-live-pointer.yml · lines 1–332 of 332 · version 2026-08-29 12:39 · Entry point

What it does
It runs automated jobs on GitHub Actions. Side effects: reads or writes files; makes network requests; starts processes.
Why it exists in the grid workflow
Domain stage upstream_foresight (repository name word 'gridatlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
Inputs & outputs
In: data source: gridatlas data; data source: GitHub API; JSON file current.json; JSON file live-set.json; JSON file release.json; JSON file browser-layer-registry.json; JSON file current-v3.json; JSON file release-manifest.json. Out: JSON file pages-workflow-run.json; JSON file public-stable-pointer-attestation.json.
Downstream impact
It is itself an entry point (workflow); no other file was found loading it.
What it achieves
Named “Verify live Data Grid Atlas pointer”.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
data-gridatlas · .github/workflows · workflow
Uses
Data GridAtlas — Data GridAtlas Page (estate URL), GridAtlas — Index Page (estate URL)
Used by
none found
Produces
none declared
Defines here
202608291239 Verify live Data Grid Atlas pointer
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
data-gridatlas@203f9dc3764c05153c2b95f8ace88eb543f26c1e .github/workflows/202608291239-verify-live-pointer.yml:1-332 · blob bd477e901c98fa5d1cd4156de08f6f06e00b31d0 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: filesystem, network, process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: supporting_data
name: 202608291239 Verify live Data Grid Atlas pointer

on:
  push:
    branches: [main]
    paths:
      - '.github/workflows/202608291239-verify-live-pointer.yml'
      - 'releases/current.json'
      - 'state/live-set.json'

permissions: {}

concurrency:
  group: data-gridatlas-live-pointer-202608291239
  cancel-in-progress: false

env:
  APP_BUILD_MANIFEST_SHA256: 889986bc8fda3c8086525eaa05d75eabd446e6d91d3015c4fa2d27ded6cac7d6
  APP_INDEX_SHA256: 023f758ff54bb522f1f4e0de00bfc52e42b5232c5e9d60b362930d3d3d77bfda
  APP_POINTER_COMMIT: 936a31f703d31bd975af22d7349708d68a143d56
  APP_POINTER_SHA256: 29628a9ba376b24a72248fac7e9333e0487a33e86ad50d309a7b868932fea4d6
  APP_PUBLICATION_COMMIT: 1898184ccbf52ca836cf1482362fc5933baf3e8d
  APP_RELEASE_ID: 202608291239-atlas-v9
  APP_RELEASE_MANIFEST_SHA256: 7c903a395e14e880bd76bd6e8a11fc68aafc2418bd351467d3538cefe3da90cc
  DATA_BROWSER_REGISTRY_SHA256: 9b2169bcfd47bf51f0aaf8350487de19578e32358e191b961385a149a4637e1b
  DATA_INDEX_SHA256: c9343edec682c790e6889ef0a2977e3ab7848aec42573e259c906e9e8aceefa4
  DATA_LEDGER_SHA256: 93c2639b9442244dc3b94b0079d16fdbfd0ba2153dc4601404fcb3fb1fb504d5
  DATA_MANIFEST_SHA256: 3246dbdaa042ae8352ec9b7128cb6c2fe65e4f1aba0534302510661828df2526
  DATA_RELEASE_COMMIT: 32459230b958ff6ddbdb24365f56da83ab1cdc93
  DATA_RELEASE_ID: 202608291237-data-gridatlas
  DATA_RELEASE_SHA256: 19684ac3e86fac4346fab121a948bab0aa857108564fec5be242484d2baefd06
  POINTER_SHA256: 08664a2fab1f2a6442a866b43abe3748fe4418e6bf0892630850a6edfd3f2283
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true'

jobs:
  verify_pointer_and_public_pages:
    name: Verify exact pointer, Pages bytes and app binding
    runs-on: ubuntu-24.04
    timeout-minutes: 20
    permissions:
      actions: read
      contents: read
    steps:
      - name: Checkout exact externally promoted pointer commit
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
        with:
          ref: ${{ github.sha }}
          fetch-depth: 2
          persist-credentials: false

      - name: Prove exact parent, diff and byte-identical pointers
        env:
          EXECUTED_WORKFLOW_SHA: ${{ github.workflow_sha }}
        run: |
          set -eu
          test "$GITHUB_EVENT_NAME" = push
          test "$GITHUB_REF" = refs/heads/main
          test "$EXECUTED_WORKFLOW_SHA" = "$GITHUB_SHA"
          test "$(git show -s --format=%P HEAD | wc -w)" -eq 1
          test "$(git rev-parse HEAD^)" = "$DATA_RELEASE_COMMIT"
          test -z "$(git status --porcelain --untracked-files=all)"
          mkdir -p work
          git diff --name-only "$DATA_RELEASE_COMMIT" "$GITHUB_SHA" | LC_ALL=C sort > work/actual-paths.txt
          cat > work/expected-paths.txt <<'EOF'
          .github/workflows/202608291239-verify-live-pointer.yml
          releases/current.json
          state/live-set.json
          EOF
          cmp --silent work/expected-paths.txt work/actual-paths.txt
          cmp --silent state/live-set.json releases/current.json
          test "$(sha256sum state/live-set.json | cut -d' ' -f1)" = "$POINTER_SHA256"
          test "$(sha256sum releases/current.json | cut -d' ' -f1)" = "$POINTER_SHA256"
          python - <<'PY'
          import json, os, re
          from pathlib import Path

          pointer = json.loads(Path('state/live-set.json').read_text(encoding='utf-8'))
          commit_pattern = re.compile(r'[0-9a-f]{40}')
          def validate_commit_fields(value, path='pointer'):
              if isinstance(value, dict):
                  for key, item in value.items():
                      item_path = f'{path}.{key}'
                      if key == 'commit' or key.endswith('_commit'):
                          if not isinstance(item, str) or commit_pattern.fullmatch(item) is None:
                              raise SystemExit(f'malformed commit at {item_path}: {item!r}')
                      validate_commit_fields(item, item_path)
              elif isinstance(value, list):
                  for index, item in enumerate(value):
                      validate_commit_fields(item, f'{path}[{index}]')
          validate_commit_fields(pointer)
          for env_name in (
              'APP_POINTER_COMMIT',
              'APP_PUBLICATION_COMMIT',
              'DATA_RELEASE_COMMIT',
          ):
              if commit_pattern.fullmatch(os.environ[env_name]) is None:
                  raise SystemExit(f'malformed workflow commit: {env_name}')
          exact = {
              'schema': 'data-gridatlas.live-set.v1',
              'classification': 'VERIFIED_LIVE_DATA_GRIDATLAS_V9',
              'generation': '202608291239',
          }
          for key, expected in exact.items():
              if pointer.get(key) != expected:
                  raise SystemExit(f'pointer mismatch: {key}')
          current = pointer.get('current') or {}
          expected_current = {
              'release_id': os.environ['DATA_RELEASE_ID'],
              'publication_commit': os.environ['DATA_RELEASE_COMMIT'],
              'release_sha256': os.environ['DATA_RELEASE_SHA256'],
              'browser_registry_sha256': os.environ['DATA_BROWSER_REGISTRY_SHA256'],
              'live_url': 'https://ventusltd.github.io/data-gridatlas/202608291237-data-gridatlas/',
          }
          for key, expected in expected_current.items():
              if current.get(key) != expected:
                  raise SystemExit(f'data binding mismatch: {key}')
          consumer = pointer.get('consumer') or {}
          expected_consumer = {
              'release_id': os.environ['APP_RELEASE_ID'],
              'publication_commit': os.environ['APP_PUBLICATION_COMMIT'],
              'app_pointer_commit': os.environ['APP_POINTER_COMMIT'],
              'release_manifest_sha256': os.environ['APP_RELEASE_MANIFEST_SHA256'],
              'live_url': 'https://ventusltd.github.io/gridatlas/202608291239-atlas-v9/',
          }
          for key, expected in expected_consumer.items():
              if consumer.get(key) != expected:
                  raise SystemExit(f'app binding mismatch: {key}')
          verification = pointer.get('verification') or {}
          if verification.get('promotion_eligible') is not True:
              raise SystemExit('pointer is not promotion eligible')
          if verification.get('initial_v8_parquet_requests') != 0:
              raise SystemExit('initial V8 Parquet request invariant failed')
          PY

      - name: Poll exact Pages deployment and prove public cross-repository bytes
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          python - <<'PY'
          import hashlib
          import json
          import os
          import time
          from datetime import datetime, timezone
          from pathlib import Path
          from urllib.request import Request, urlopen

          work = Path('work')
          work.mkdir(parents=True, exist_ok=True)
          repository = os.environ['GITHUB_REPOSITORY']
          pointer_commit = os.environ['GITHUB_SHA']
          token = os.environ['GH_TOKEN']
          api_headers = {
              'Accept': 'application/vnd.github+json',
              'Authorization': f'Bearer {token}',
              'X-GitHub-Api-Version': '2022-11-28',
          }

          pages_run = None
          runs_url = f'https://api.github.com/repos/{repository}/actions/runs?head_sha={pointer_commit}&per_page=100'
          for attempt in range(60):
              request = Request(runs_url, headers=api_headers)
              with urlopen(request, timeout=30) as response:
                  runs = json.load(response).get('workflow_runs', [])
              matches = [
                  run for run in runs
                  if run.get('path') == 'dynamic/pages/pages-build-deployment'
                  and run.get('head_sha') == pointer_commit
              ]
              if len(matches) > 1:
                  raise SystemExit(f'ambiguous dynamic Pages runs: {[run.get("id") for run in matches]}')
              if matches:
                  pages_run = matches[0]
                  if pages_run.get('status') == 'completed':
                      if pages_run.get('conclusion') != 'success':
                          raise SystemExit(f'dynamic Pages deployment failed: {pages_run}')
                      break
              if attempt == 59:
                  raise SystemExit('dynamic Pages deployment did not complete')
              time.sleep(5)

          expected_pages = {
              'path': 'dynamic/pages/pages-build-deployment',
              'event': 'dynamic',
              'head_branch': 'main',
              'head_sha': pointer_commit,
              'status': 'completed',
              'conclusion': 'success',
              'run_attempt': 1,
          }
          for key, expected in expected_pages.items():
              if pages_run.get(key) != expected:
                  raise SystemExit(f'dynamic Pages provenance mismatch: {key}')
          (work / 'pages-workflow-run.json').write_text(
              json.dumps(pages_run, sort_keys=True, indent=2) + '\n', encoding='utf-8'
          )

          def fetch(url, *, cors=False, timeout=30):
              request = Request(url, headers={'Accept-Encoding': 'identity', 'User-Agent': 'data-gridatlas-pointer-verifier'})
              with urlopen(request, timeout=timeout) as response:
                  payload = response.read()
                  if response.status != 200:
                      raise RuntimeError(f'HTTP {response.status}: {url}')
                  if response.headers.get('Content-Encoding') not in (None, 'identity'):
                      raise RuntimeError(f'encoded response: {url}')
                  if cors and response.headers.get('Access-Control-Allow-Origin') != '*':
                      raise RuntimeError(f'CORS mismatch: {url}')
                  return payload

          def require_sha(payload, expected, label):
              actual = hashlib.sha256(payload).hexdigest()
              if actual != expected:
                  raise SystemExit(f'{label} SHA-256 mismatch: {actual}')

          expected_pointer = Path('state/live-set.json').read_bytes()
          data_root = 'https://ventusltd.github.io/data-gridatlas/'
          public_pointer_urls = [
              data_root + 'state/live-set.json',
              data_root + 'releases/current.json',
          ]
          public_pointers = None
          last_error = None
          for attempt in range(60):
              try:
                  payloads = [fetch(url, cors=True, timeout=20) for url in public_pointer_urls]
                  if all(payload == expected_pointer for payload in payloads):
                      public_pointers = payloads
                      break
                  last_error = 'public pointer bytes have not converged'
              except Exception as exc:
                  last_error = repr(exc)
              if attempt == 59:
                  raise SystemExit(f'public pointers did not converge: {last_error}')
              time.sleep(5)
          for payload in public_pointers:
              require_sha(payload, os.environ['POINTER_SHA256'], 'public data pointer')

          data_release = data_root + os.environ['DATA_RELEASE_ID'] + '/'
          data_checks = {
              'release.json': os.environ['DATA_RELEASE_SHA256'],
              'browser-layer-registry.json': os.environ['DATA_BROWSER_REGISTRY_SHA256'],
              'data/manifest.json': os.environ['DATA_MANIFEST_SHA256'],
              'sha256sums.txt': os.environ['DATA_LEDGER_SHA256'],
              'index.html': os.environ['DATA_INDEX_SHA256'],
          }
          for relative, expected in data_checks.items():
              require_sha(fetch(data_release + relative, cors=True), expected, f'public data {relative}')

          app_root = 'https://ventusltd.github.io/gridatlas/'
          app_pointer_urls = [
              app_root + 'state/live-set.json',
              app_root + 'releases/current-v3.json',
          ]
          app_pointers = [fetch(url, cors=True) for url in app_pointer_urls]
          if app_pointers[0] != app_pointers[1]:
              raise SystemExit('public app pointers are not byte-identical')
          require_sha(app_pointers[0], os.environ['APP_POINTER_SHA256'], 'public app pointer')
          app_pointer = json.loads(app_pointers[0])
          if app_pointer.get('classification') != 'VERIFIED_LIVE_ATLAS_V9':
              raise SystemExit('public app pointer classification mismatch')
          current_app = app_pointer.get('current') or {}
          if current_app.get('publication_commit') != os.environ['APP_PUBLICATION_COMMIT']:
              raise SystemExit('public app publication commit mismatch')
          if current_app.get('data_release_commit') != os.environ['DATA_RELEASE_COMMIT']:
              raise SystemExit('public app data release commit mismatch')

          app_release = app_root + os.environ['APP_RELEASE_ID'] + '/'
          app_release_manifest = fetch(app_release + 'release-manifest.json', cors=True)
          app_build_manifest = fetch(app_release + 'build-manifest.json', cors=True)
          app_index = fetch(app_release + 'index.html', cors=True)
          deep_link_index = fetch(app_release + '?repd_ref=16135', cors=True)
          require_sha(app_release_manifest, os.environ['APP_RELEASE_MANIFEST_SHA256'], 'public app release manifest')
          require_sha(app_build_manifest, os.environ['APP_BUILD_MANIFEST_SHA256'], 'public app build manifest')
          require_sha(app_index, os.environ['APP_INDEX_SHA256'], 'public app index')
          require_sha(deep_link_index, os.environ['APP_INDEX_SHA256'], 'public app deep-link index')

          raw_app_pointer = fetch(
              'https://raw.githubusercontent.com/Ventusltd/gridatlas/'
              + os.environ['APP_POINTER_COMMIT'] + '/state/live-set.json'
          )
          if raw_app_pointer != app_pointers[0]:
              raise SystemExit('public app pointer differs from pinned pointer commit')
          raw_release_manifest = fetch(
              'https://raw.githubusercontent.com/Ventusltd/gridatlas/'
              + os.environ['APP_PUBLICATION_COMMIT'] + '/'
              + os.environ['APP_RELEASE_ID'] + '/release-manifest.json'
          )
          if raw_release_manifest != app_release_manifest:
              raise SystemExit('public app release differs from pinned publication commit')

          attestation = {
              'schema': 'data-gridatlas.public-stable-pointer-attestation.v1',
              'classification': 'VERIFIED_PUBLIC_STABLE_DATA_POINTER',
              'attested_at': datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'),
              'repository': repository,
              'pointer_commit': pointer_commit,
              'pointer_parent': os.environ['DATA_RELEASE_COMMIT'],
              'pointer_sha256': os.environ['POINTER_SHA256'],
              'public_pointer_urls': public_pointer_urls,
              'pages_workflow_run_id': pages_run['id'],
              'pages_workflow_run_attempt': pages_run['run_attempt'],
              'pages_workflow_url': pages_run['html_url'],
              'data_release_id': os.environ['DATA_RELEASE_ID'],
              'data_release_sha256': os.environ['DATA_RELEASE_SHA256'],
              'app_pointer_commit': os.environ['APP_POINTER_COMMIT'],
              'app_pointer_sha256': os.environ['APP_POINTER_SHA256'],
              'app_publication_commit': os.environ['APP_PUBLICATION_COMMIT'],
              'app_release_id': os.environ['APP_RELEASE_ID'],
              'app_release_manifest_sha256': os.environ['APP_RELEASE_MANIFEST_SHA256'],
              'deep_link_index_verified': True,
              'main_mutated_by_workflow': False,
              'failed': 0,
          }
          (work / 'public-stable-pointer-attestation.json').write_text(
              json.dumps(attestation, sort_keys=True, indent=2) + '\n', encoding='utf-8'
          )
          print(json.dumps(attestation, sort_keys=True))
          PY

      - name: Retain public stable-pointer attestation
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
        with:
          name: data-gridatlas-202608291239-public-stable-pointer-${{ github.sha }}
          path: |
            state/live-set.json
            work/actual-paths.txt
            work/expected-paths.txt
            work/pages-workflow-run.json
            work/public-stable-pointer-attestation.json
          if-no-files-found: error
          retention-days: 30
          compression-level: 0

Publish Renewable Energy Planning Database (REPD) Routing Workflow

A GitHub Actions workflow in Data GridAtlas that builds and publishes the site using data from GitHub API. Runs on push and by hand.

automationdata-gridatlas / .github/workflows/202608291410-publish-repd-routing.yml · lines 1–355 of 355 · version 2026-08-29 14:10 · Entry point

What it does
It builds and publishes its content. Side effects: reads or writes files; makes network requests; starts processes.
Why it exists in the grid workflow
Domain stage field_execution (path word 'routing'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
Inputs & outputs
In: data source: GitHub API; JSON file 202608291410-repd-routing-release.json; JSON file 202608291410-repository-boundary.json; JSON file release.json; JSON file projects.json; JSON file pages-run.json. Out: JSON file public-attestation.json; commits pushed to the repository.
Downstream impact
It is itself an entry point (workflow); no other file was found loading it.
What it achieves
Runs Verify Repository Boundary (`atman/202608291410-verify-repository-boundary.py`), Build Renewable Energy Planning Database (REPD) Routing Release (`compiler/202608291410-build-repd-routing-release.py`) and `atman/202608291410-verify-repd-routing-release.py`.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
data-gridatlas · .github/workflows · workflow
Uses
Verify Repository Boundary (workflow run), Build Renewable Energy Planning Database (REPD) Routing Release (workflow run)
Used by
none found
Produces
none declared
Defines here
202608291410 Publish REPD routing dependency
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
data-gridatlas@203f9dc3764c05153c2b95f8ace88eb543f26c1e .github/workflows/202608291410-publish-repd-routing.yml:1-355 · blob 6544ed364ac0a77a26c156f0e0490069ea4d1dd9 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: filesystem, network, process · domain stage: field_execution · users: IPP_developer, EPC_contractor, landowner_planner · canonical: supporting_data
name: 202608291410 Publish REPD routing dependency

on:
  push:
    branches: [main]
    paths:
      - '.github/workflows/202608291410-publish-repd-routing.yml'
      - 'contracts/202608291410-repd-routing-release.json'
      - 'contracts/202608291410-repository-boundary.json'
      - 'compiler/202608291410-build-repd-routing-release.py'
      - 'atman/202608291410-verify-repd-routing-release.py'
      - 'atman/202608291410-verify-repository-boundary.py'
      - '202608291410-repd-routing/**'
  workflow_dispatch:
    inputs:
      expected_main_sha:
        description: Exact main commit to classify
        required: true
        type: string

permissions:
  contents: read
  actions: read

concurrency:
  group: data-gridatlas-202608291410-repd-routing
  cancel-in-progress: false

env:
  RELEASE_ID: 202608291410-repd-routing
  RELEASE_CONTRACT: contracts/202608291410-repd-routing-release.json
  BOUNDARY_CONTRACT: contracts/202608291410-repository-boundary.json
  STAGE_BRANCH: ci/202608291410-repd-routing

jobs:
  classify:
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    outputs:
      mode: ${{ steps.phase.outputs.mode }}
      source_commit: ${{ steps.phase.outputs.source_commit }}
      current_commit: ${{ steps.phase.outputs.current_commit }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
        with:
          ref: ${{ inputs.expected_main_sha || github.sha }}
          fetch-depth: 3
          persist-credentials: false
      - id: phase
        env:
          EXPECTED_MAIN_SHA: ${{ inputs.expected_main_sha || github.sha }}
          EXECUTED_WORKFLOW_SHA: ${{ github.workflow_sha }}
        run: |
          set -euo pipefail
          test "$GITHUB_REF" = refs/heads/main
          test "$EXECUTED_WORKFLOW_SHA" = "$EXPECTED_MAIN_SHA"
          test "$(git rev-parse HEAD)" = "$EXPECTED_MAIN_SHA"
          git fetch --no-tags origin main:refs/remotes/origin/main
          test "$(git rev-parse origin/main)" = "$EXPECTED_MAIN_SHA"
          source_parent="$(jq -r .source_parent_commit "$RELEASE_CONTRACT")"
          test "$source_parent" = fd1c49eece37d1a8035d8fcdc6c08d20a5cdbd13
          test "$(jq -r .release_id "$RELEASE_CONTRACT")" = "$RELEASE_ID"
          if test ! -e "$RELEASE_ID"; then
            mode=source
            source_commit="$EXPECTED_MAIN_SHA"
            test "$(git show -s --format=%P HEAD | wc -w)" = 1
            test "$(git rev-parse HEAD^)" = "$source_parent"
            mapfile -t changed < <(git diff-tree --no-commit-id --name-only -r HEAD | sort)
            expected=(
              .github/workflows/202608291410-publish-repd-routing.yml
              atman/202608291410-verify-repd-routing-release.py
              atman/202608291410-verify-repository-boundary.py
              compiler/202608291410-build-repd-routing-release.py
              contracts/202608291410-repd-routing-release.json
              contracts/202608291410-repository-boundary.json
            )
            test "${#changed[@]}" = 6
            test "${changed[*]}" = "${expected[*]}"
          else
            mode=release
            source_commit="$(git rev-parse HEAD^)"
            test "$(git show -s --format=%P HEAD | wc -w)" = 1
            test "$(git show -s --format=%P "$source_commit" | wc -w)" = 1
            test "$(git rev-parse "$source_commit^")" = "$source_parent"
            git fetch --no-tags origin "$STAGE_BRANCH:refs/remotes/origin/$STAGE_BRANCH"
            test "$(git rev-parse HEAD)" = "$(git rev-parse "refs/remotes/origin/$STAGE_BRANCH")"
            test "$(jq -r .source_commit "$RELEASE_ID/release.json")" = "$source_commit"
            mapfile -t changed < <(git diff-tree --no-commit-id --name-only -r HEAD | sort)
            expected=(
              "$RELEASE_ID/index.html"
              "$RELEASE_ID/projects.json"
              "$RELEASE_ID/release.json"
              "$RELEASE_ID/sha256sums.txt"
            )
            test "${#changed[@]}" = 4
            test "${changed[*]}" = "${expected[*]}"
          fi
          python3 atman/202608291410-verify-repository-boundary.py \
            --repository . \
            --contract "$BOUNDARY_CONTRACT" \
            --mode "$mode"
          echo "mode=$mode" >> "$GITHUB_OUTPUT"
          echo "source_commit=$source_commit" >> "$GITHUB_OUTPUT"
          echo "current_commit=$EXPECTED_MAIN_SHA" >> "$GITHUB_OUTPUT"

  build_verify:
    needs: classify
    runs-on: ubuntu-24.04
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
        with:
          ref: ${{ needs.classify.outputs.current_commit }}
          fetch-depth: 3
          persist-credentials: false
      - name: Fetch and bind exact working-V8 routing source
        run: |
          set -euo pipefail
          mkdir -p work/source
          source_repository="$(jq -r .source.repository "$RELEASE_CONTRACT")"
          source_revision="$(jq -r .source.commit "$RELEASE_CONTRACT")"
          source_path="$(jq -r .source.path "$RELEASE_CONTRACT")"
          source_bytes="$(jq -r .source.bytes "$RELEASE_CONTRACT")"
          source_sha256="$(jq -r .source.sha256 "$RELEASE_CONTRACT")"
          url="https://raw.githubusercontent.com/$source_repository/$source_revision/$source_path"
          curl --fail --location --retry 6 --retry-all-errors --max-time 120 "$url" -o work/source/projects.json
          test "$(stat -c %s work/source/projects.json)" = "$source_bytes"
          test "$(sha256sum work/source/projects.json | cut -d' ' -f1)" = "$source_sha256"
      - name: Deterministic A/B compile and exhaustive set verification
        env:
          SOURCE_GIT_COMMIT: ${{ needs.classify.outputs.source_commit }}
        run: |
          set -euo pipefail
          source_time="$(git show -s --format=%cI "$SOURCE_GIT_COMMIT")"
          source_parent="$(git rev-parse "$SOURCE_GIT_COMMIT^")"
          for build in a b; do
            python3 compiler/202608291410-build-repd-routing-release.py \
              --contract "$RELEASE_CONTRACT" \
              --source work/source/projects.json \
              --source-commit "$SOURCE_GIT_COMMIT" \
              --source-parent-commit "$source_parent" \
              --source-committed-at "$source_time" \
              --output "work/build-$build/$RELEASE_ID"
            python3 atman/202608291410-verify-repd-routing-release.py \
              --contract "$RELEASE_CONTRACT" \
              --release "work/build-$build/$RELEASE_ID" \
              --source-commit "$SOURCE_GIT_COMMIT" \
              --source-committed-at "$source_time"
          done
          diff --recursive --no-dereference work/build-a work/build-b
          test "$(find work/build-a/$RELEASE_ID -type f | wc -l)" = 4
          if test "${{ needs.classify.outputs.mode }}" = release; then
            diff --recursive --no-dereference "work/build-a/$RELEASE_ID" "$RELEASE_ID"
          fi
          echo "### Working V8 routing parity" >> "$GITHUB_STEP_SUMMARY"
          echo "- 7,680 exact REPD identities" >> "$GITHUB_STEP_SUMMARY"
          echo "- 7,652 MAP / 28 NO MAP" >> "$GITHUB_STEP_SUMMARY"
          echo "- deterministic A/B build and exhaustive set hashes: PASS" >> "$GITHUB_STEP_SUMMARY"
      - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
        with:
          name: repd-routing-${{ needs.classify.outputs.source_commit }}
          path: work/build-a/202608291410-repd-routing
          if-no-files-found: error
          retention-days: 30

  stage_release:
    needs: [classify, build_verify]
    if: needs.classify.outputs.mode == 'source'
    runs-on: ubuntu-24.04
    timeout-minutes: 10
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
        with:
          ref: ${{ needs.classify.outputs.source_commit }}
          fetch-depth: 3
      - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131
        with:
          name: repd-routing-${{ needs.classify.outputs.source_commit }}
          path: work/accepted/202608291410-repd-routing
      - name: Stage exact one-parent folder commit on CI branch only
        env:
          SOURCE_GIT_COMMIT: ${{ needs.classify.outputs.source_commit }}
        run: |
          set -euo pipefail
          test "$(git rev-parse HEAD)" = "$SOURCE_GIT_COMMIT"
          git fetch --no-tags origin main:refs/remotes/origin/main
          test "$(git rev-parse origin/main)" = "$SOURCE_GIT_COMMIT"
          test ! -e "$RELEASE_ID"
          cp -a "work/accepted/$RELEASE_ID" "$RELEASE_ID"
          source_time="$(git show -s --format=%cI "$SOURCE_GIT_COMMIT")"
          python3 atman/202608291410-verify-repd-routing-release.py \
            --contract "$RELEASE_CONTRACT" \
            --release "$RELEASE_ID" \
            --source-commit "$SOURCE_GIT_COMMIT" \
            --source-committed-at "$source_time"
          git add -- "$RELEASE_ID"
          test "$(git diff --cached --name-only | wc -l)" = 4
          python3 atman/202608291410-verify-repository-boundary.py \
            --repository . \
            --contract "$BOUNDARY_CONTRACT" \
            --mode release
          git config user.name data-gridatlas-stage-bot
          git config user.email data-gridatlas-stage-bot@users.noreply.github.com
          stage_date="$source_time"
          GIT_AUTHOR_DATE="$stage_date" GIT_COMMITTER_DATE="$stage_date" git commit -m '202608291410: stage immutable REPD routing data'
          stage_commit="$(git rev-parse HEAD)"
          test "$(git rev-parse HEAD^)" = "$SOURCE_GIT_COMMIT"
          remote_old="$(git ls-remote --heads origin "refs/heads/$STAGE_BRANCH" | cut -f1)"
          if test -n "$remote_old"; then
            test "$remote_old" = "$stage_commit"
          else
            git push origin "$stage_commit:refs/heads/$STAGE_BRANCH"
          fi
          echo "### REPD routing stage" >> "$GITHUB_STEP_SUMMARY"
          echo "- source: \`$SOURCE_GIT_COMMIT\`" >> "$GITHUB_STEP_SUMMARY"
          echo "- stage: \`$stage_commit\`" >> "$GITHUB_STEP_SUMMARY"
          echo "- main unchanged; GitHub App promotion required" >> "$GITHUB_STEP_SUMMARY"

  verify_public:
    needs: [classify, build_verify]
    if: needs.classify.outputs.mode == 'release'
    runs-on: ubuntu-24.04
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
        with:
          ref: ${{ needs.classify.outputs.current_commit }}
          fetch-depth: 3
          persist-credentials: false
      - name: Wait for successful Pages deployment of exact commit
        env:
          GH_TOKEN: ${{ github.token }}
          RELEASE_COMMIT: ${{ needs.classify.outputs.current_commit }}
        run: |
          set -euo pipefail
          mkdir -p work/public
          for attempt in {1..60}; do
            response="$(curl --fail --silent --show-error --retry 3 --retry-all-errors --max-time 30 --header "Authorization: Bearer $GH_TOKEN" --header 'X-GitHub-Api-Version: 2022-11-28' "https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runs?head_sha=$RELEASE_COMMIT&per_page=100")"
            matches="$(jq -c --arg sha "$RELEASE_COMMIT" '[.workflow_runs[] | select(.path=="dynamic/pages/pages-build-deployment" and .head_sha==$sha)]' <<<"$response")"
            test "$(jq 'length' <<<"$matches")" -le 1
            conclusion=""
            if test "$(jq 'length' <<<"$matches")" = 1; then
              status="$(jq -r '.[0].status' <<<"$matches")"
              conclusion="$(jq -r '.[0].conclusion // ""' <<<"$matches")"
              if test "$status" = completed; then
                test "$conclusion" = success
                test "$(jq -r '.[0].head_branch' <<<"$matches")" = main
                test "$(jq -r '.[0].event' <<<"$matches")" = dynamic
                test "$(jq -r '.[0].run_attempt' <<<"$matches")" = 1
                jq '.[0]' <<<"$matches" > work/public/pages-run.json
              fi
            fi
            if test "$conclusion" = success; then break; fi
            test "$attempt" != 60
            sleep 10
          done
      - name: Verify every public byte, CORS and range transport
        env:
          RELEASE_COMMIT: ${{ needs.classify.outputs.current_commit }}
        run: |
          set -euo pipefail
          base="https://ventusltd.github.io/data-gridatlas/$RELEASE_ID"
          for relative in index.html projects.json release.json sha256sums.txt; do
            expected_bytes="$(stat -c %s "$RELEASE_ID/$relative")"
            expected_sha="$(sha256sum "$RELEASE_ID/$relative" | cut -d' ' -f1)"
            for attempt in {1..20}; do
              if curl --fail --location --silent --show-error --retry 3 --retry-all-errors --max-time 30 --header 'Accept-Encoding: identity' --dump-header "work-$relative.headers" "$base/$relative?commit=${{ needs.classify.outputs.current_commit }}&attempt=$attempt" -o "work-$relative" \
                && test "$(stat -c %s "work-$relative")" = "$expected_bytes" \
                && test "$(sha256sum "work-$relative" | cut -d' ' -f1)" = "$expected_sha" \
                && grep -Eiq '^access-control-allow-origin:[[:space:]]*\*' "work-$relative.headers" \
                && { ! grep -Eiq '^content-encoding:' "work-$relative.headers" || grep -Eiq '^content-encoding:[[:space:]]*identity' "work-$relative.headers"; }; then break; fi
              test "$attempt" != 20
              sleep 3
            done
          done
          for range_name in prefix suffix; do
            if test "$range_name" = prefix; then
              range='0-99'
              expected_content_range='bytes 0-99/979338'
              expected_range_bytes=100
            else
              range='-100'
              expected_content_range='bytes 979238-979337/979338'
              expected_range_bytes=100
            fi
            status="$(curl --fail --location --silent --show-error --retry 3 --retry-all-errors --max-time 30 --output "work-range-$range_name.bin" --dump-header "work-range-$range_name.headers" --write-out '%{http_code}' --header 'Accept-Encoding: identity' --header "Range: bytes=$range" "$base/projects.json?range=${{ needs.classify.outputs.current_commit }}-$range_name")"
            test "$status" = 206
            test "$(stat -c %s "work-range-$range_name.bin")" = "$expected_range_bytes"
            grep -Eiq '^access-control-allow-origin:[[:space:]]*\*' "work-range-$range_name.headers"
            grep -Eiq "^content-range:[[:space:]]*$expected_content_range" "work-range-$range_name.headers"
            ! grep -Eiq '^content-encoding:' "work-range-$range_name.headers" || grep -Eiq '^content-encoding:[[:space:]]*identity' "work-range-$range_name.headers"
            if test "$range_name" = prefix; then
              cmp --silent <(head -c 100 "$RELEASE_ID/projects.json") "work-range-$range_name.bin"
            else
              cmp --silent <(tail -c 100 "$RELEASE_ID/projects.json") "work-range-$range_name.bin"
            fi
          done
          python3 - <<'PY'
          import hashlib
          import json
          import os
          from datetime import datetime, timezone
          from pathlib import Path

          release_id = os.environ["RELEASE_ID"]
          root = Path(release_id)
          files = {}
          for name in ("index.html", "projects.json", "release.json", "sha256sums.txt"):
              payload = (root / name).read_bytes()
              files[name] = {"bytes": len(payload), "sha256": hashlib.sha256(payload).hexdigest()}
          pages_run = json.loads(Path("work/public/pages-run.json").read_text(encoding="utf-8"))
          attestation = {
              "schema": "data-gridatlas.repd-routing-public-attestation.v1",
              "classification": "VERIFIED_PUBLIC_REPD_ROUTING_RELEASE",
              "verified_at": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
              "release_id": release_id,
              "release_commit": os.environ["RELEASE_COMMIT"],
              "source_commit": json.loads((root / "release.json").read_text(encoding="utf-8"))["source_commit"],
              "stage_branch": os.environ["STAGE_BRANCH"],
              "pages_run_id": pages_run["id"],
              "pages_run_attempt": pages_run["run_attempt"],
              "pages_workflow_path": pages_run["path"],
              "public_url": f"https://ventusltd.github.io/data-gridatlas/{release_id}/",
              "files": files,
              "cors_all_files": True,
              "projects_prefix_range_exact": True,
              "projects_suffix_range_exact": True,
              "map_identities": 7652,
              "no_map_identities": 28,
              "failed": 0,
          }
          Path("work/public/public-attestation.json").write_text(
              json.dumps(attestation, sort_keys=True, indent=2) + "\n", encoding="utf-8"
          )
          print(json.dumps(attestation, sort_keys=True))
          PY
          echo "### Public REPD routing data" >> "$GITHUB_STEP_SUMMARY"
          echo "- $base/" >> "$GITHUB_STEP_SUMMARY"
          echo "- 7,652 MAP / 28 NO MAP identities" >> "$GITHUB_STEP_SUMMARY"
          echo "- exact bytes, CORS and HTTP range: PASS" >> "$GITHUB_STEP_SUMMARY"
      - name: Retain exact public routing proof
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
        with:
          name: repd-routing-public-${{ needs.classify.outputs.current_commit }}
          path: |
            work/public/pages-run.json
            work/public/public-attestation.json
            work-*.headers
            work-range-*.headers
            work-range-*.bin
          if-no-files-found: error
          retention-days: 30
          compression-level: 0