From 575f698d57e56fddc88f96d6de31a96590d7162b Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Sun, 22 Nov 2026 10:42:26 +0000 Subject: [PATCH 1/3] Check pull requests for edits to generated site files --- .github/workflows/README.md | 8 ++ .github/workflows/generated-paths.yaml | 39 ++++++++++ scripts/check_generated_paths.py | 82 +++++++++++++++++++++ scripts/tests/test_check_generated_paths.py | 70 ++++++++++++++++++ 4 files changed, 199 insertions(+) create mode 100644 .github/workflows/generated-paths.yaml create mode 100644 scripts/check_generated_paths.py create mode 100644 scripts/tests/test_check_generated_paths.py diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 1c0c47e5ce6..bfb5e3f5d1a 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -49,6 +49,14 @@ Features: - Queues builds instead of canceling (concurrency) - Auto-cleans old staging branches (keeps 2) +### [generated-paths.yaml](generated-paths.yaml) + +Checks PRs into `main` and `rebrand-doors` for changed generator outputs since the merge +base. Edit the upstream source and rerun its generator. Apply `generated-output` to PRs +that intentionally commit regenerated files. Adding or removing the label reruns the +check. Same-repository glossary and Google Analytics PRs opened by the data workflow's +account on its automated branches are exempt. + ## Data Workflows ### [data-processing.yml](workflows/data-processing.yml) diff --git a/.github/workflows/generated-paths.yaml b/.github/workflows/generated-paths.yaml new file mode 100644 index 00000000000..bce6911ba68 --- /dev/null +++ b/.github/workflows/generated-paths.yaml @@ -0,0 +1,39 @@ +name: Generated paths + +on: + pull_request: + branches: [main, rebrand-doors] + types: [opened, synchronize, reopened, labeled, unlabeled] + +permissions: + contents: read + +jobs: + generated-paths: + name: Check generated paths + runs-on: ubuntu-latest + steps: + # The data-processing workflow opens these PRs with FORRT_PAT. + - name: Determine whether this is a generator-output PR + id: exemption + if: >- + contains(github.event.pull_request.labels.*.name, 'generated-output') || + (github.event.pull_request.head.repo.full_name == github.repository && + github.event.pull_request.user.login == 'richarddushime' && + (startsWith(github.head_ref, 'glossary-update-') || startsWith(github.head_ref, 'ga-data-update-'))) + run: | + echo "Generator-output PR is exempt" + echo "exempt=true" >> "$GITHUB_OUTPUT" + + - uses: actions/checkout@v6 + if: steps.exemption.outputs.exempt != 'true' + with: + fetch-depth: 0 + filter: blob:none + persist-credentials: false + + - name: Check changed paths + if: steps.exemption.outputs.exempt != 'true' + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: python3 scripts/check_generated_paths.py --base "$BASE_SHA" diff --git a/scripts/check_generated_paths.py b/scripts/check_generated_paths.py new file mode 100644 index 00000000000..e49bbaa2e9c --- /dev/null +++ b/scripts/check_generated_paths.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +"""Reject changes to generator outputs relative to a PR's merge base.""" + +import argparse +import os +import re +import subprocess + + +GENERATED = re.compile( + r"^(content/curated_resources/(?!_index\.md$)" + r"|content/glossary/(?!_build_references\.py$|_create_glossaries\.py$)" # its generators sit beside their output + r"|content/post/[^/]+/" + r"|content/contributors/tenzing\.md$" + r"|content/contributor-analysis/" + r"|content/publications/citation_chart\.webp$" + r"|content/replication-hub/flora/_index\.md$" + r"|content/clusters/cluster-\d+/index\.md$" + r"|content/about/steering-committee/index\.md$" + r"|static/data/" + r"|static/partials/" + r"|scripts/forrt_contribs/contributors_cache\.csv$" + r"|data/(?!partners\.json$|publications\.yaml$|themes/|fonts/)[^/]+$)" +) + +# Named outputs are also covered by GENERATED. Keep their source guidance explicit. +OUTPUT_SOURCES = { + "data/summaries.json": "the published FORRT summaries Google Doc, then run content/summaries/summaries.py", + "data/open_research_games.json": "the Games Portal source sheet, then run scripts/build_games_portal.py", + "data/scholar_citations.json": "the publication citation inputs used by scripts/gs-cite/google_scholar.py", + "content/publications/citation_chart.webp": "the publication citation inputs used by scripts/gs-cite/google_scholar.py", + "content/about/steering-committee/index.md": "the steering committee or personal-details sheet, then run scripts/generate_sc_profiles.py", + "data/clusters_v4.json": "the Clusters Google Doc, then run scripts/parse_clusters_to_sheet.py --json-only", + "data/ga_data.json": "Google Analytics, then run scripts/download_ga_data.py", +} + +PATTERN_SOURCES = ( + (r"^content/curated_resources/", "the curated resources Google Sheet, then run content/resources/resource.py"), + (r"^content/glossary/", "the glossary Google Sheet, then run content/glossary/_create_glossaries.py and _build_references.py"), + (r"^content/post/", "the announcements source used by scripts/create_announcements.R"), + (r"^content/clusters/", "the Clusters Google Doc, then run scripts/parse_clusters_to_sheet.py --json-only and scripts/generate_cluster_pages.py"), +) + + +def generated_source(path): + if not GENERATED.match(path): + return None + if path in OUTPUT_SOURCES: + return OUTPUT_SOURCES[path] + for pattern, source in PATTERN_SOURCES: + if re.match(pattern, path): + return source + return "the generator's source as described in AGENTS.md" + + +def changed_paths(base): + # Treat renames as delete/add so both paths are checked. NUL separators preserve + # whitespace and non-ASCII filenames. + diff = subprocess.check_output( + ["git", "diff", "--name-only", "--no-renames", "-z", f"{base}...HEAD", "--"] + ) + return [os.fsdecode(path) for path in diff.split(b"\0") if path] + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--base", required=True) + args = parser.parse_args() + + found = False + for path in changed_paths(args.base): + source = generated_source(path) + if source: + print(f" {path!r}: update {source}.") + found = True + if found: + print("Generated files changed. For intentional generator output, apply the generated-output label.") + return int(found) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/tests/test_check_generated_paths.py b/scripts/tests/test_check_generated_paths.py new file mode 100644 index 00000000000..410716b45e2 --- /dev/null +++ b/scripts/tests/test_check_generated_paths.py @@ -0,0 +1,70 @@ +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + +SCRIPTS = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(SCRIPTS)) +from check_generated_paths import generated_source + + +class GeneratedPathsTest(unittest.TestCase): + def test_generators_and_manual_sources(self): + for path in ( + "data/summaries.json", + "data/open_research_games.json", + "data/scholar_citations.json", + "content/post/announcement/index.md", + "content/curated_resources/topic/index.md", + "content/glossary/fr/terme.md", + ): + with self.subTest(path=path): + self.assertIsNotNone(generated_source(path)) + self.assertIn("content/summaries/summaries.py", generated_source("data/summaries.json")) + for path in ( + "data/partners.json", + "data/publications.yaml", + "data/themes/forrt.toml", + "data/fonts/forrt.toml", + "content/glossary/_create_glossaries.py", + "content/glossary/_build_references.py", + "content/curated_resources/_index.md", + "content/summaries/_index.md", + "content/summaries/summaries.py", + ): + with self.subTest(path=path): + self.assertIsNone(generated_source(path)) + + def test_merge_base_and_rename(self): + with tempfile.TemporaryDirectory(prefix="scratch-generated-paths-") as directory: + root = Path(directory) + + def git(*args): + subprocess.run(["git", *args], cwd=root, check=True, capture_output=True) + + def check(): + return subprocess.run( + [sys.executable, SCRIPTS / "check_generated_paths.py", "--base", "base"], + cwd=root, capture_output=True, text=True, + ) + + git("init", "-b", "base") + git("config", "user.name", "Test") + git("config", "user.email", "test@example.org") + git("config", "commit.gpgsign", "false") + path = "content/glossary/un terme é.md" + (root / path).parent.mkdir(parents=True) + (root / path).write_text("generated glossary term", encoding="utf-8") + git("add", ".") + git("commit", "-m", "initial") + git("branch", "topic") + (root / path).write_text("updated glossary term", encoding="utf-8") + git("commit", "-am", "regenerate on base") + git("switch", "topic") + self.assertEqual(check().returncode, 0) + git("mv", path, "manual.md") + git("commit", "-m", "move the output") + result = check() + self.assertEqual(result.returncode, 1) + self.assertIn(path, result.stdout) From 7b8b244df07f28c47b105e25439710564779934c Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Sun, 22 Nov 2026 11:10:57 +0000 Subject: [PATCH 2/3] Check the actual PR head and identify more generator sources --- .github/workflows/generated-paths.yaml | 5 +++++ scripts/check_generated_paths.py | 21 +++++++++++++++------ scripts/tests/test_check_generated_paths.py | 2 ++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/generated-paths.yaml b/.github/workflows/generated-paths.yaml index bce6911ba68..2d7564eef6f 100644 --- a/.github/workflows/generated-paths.yaml +++ b/.github/workflows/generated-paths.yaml @@ -8,6 +8,10 @@ on: permissions: contents: read +concurrency: + group: generated-paths-${{ github.event.pull_request.number }} + cancel-in-progress: true + jobs: generated-paths: name: Check generated paths @@ -28,6 +32,7 @@ jobs: - uses: actions/checkout@v6 if: steps.exemption.outputs.exempt != 'true' with: + ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 filter: blob:none persist-credentials: false diff --git a/scripts/check_generated_paths.py b/scripts/check_generated_paths.py index e49bbaa2e9c..87278c70aea 100644 --- a/scripts/check_generated_paths.py +++ b/scripts/check_generated_paths.py @@ -23,30 +23,39 @@ r"|data/(?!partners\.json$|publications\.yaml$|themes/|fonts/)[^/]+$)" ) -# Named outputs are also covered by GENERATED. Keep their source guidance explicit. +# Includes the redesign's NEW_OUTPUTS and the summaries generator's output. OUTPUT_SOURCES = { "data/summaries.json": "the published FORRT summaries Google Doc, then run content/summaries/summaries.py", "data/open_research_games.json": "the Games Portal source sheet, then run scripts/build_games_portal.py", "data/scholar_citations.json": "the publication citation inputs used by scripts/gs-cite/google_scholar.py", "content/publications/citation_chart.webp": "the publication citation inputs used by scripts/gs-cite/google_scholar.py", "content/about/steering-committee/index.md": "the steering committee or personal-details sheet, then run scripts/generate_sc_profiles.py", + "content/contributors/tenzing.md": "the Tenzing contributor sheets, then rerun the data-processing workflow", + "scripts/forrt_contribs/contributors_cache.csv": "the Tenzing contributor sheets, then rerun the data-processing workflow", + "static/partials/network-graph.html": "the contributor network source in content/contributor-analysis/network-graph.Rmd", + "static/data/fred_citation.txt": "the citation in FORRT's FReD-data repository, then run scripts/update_fred_citation.py", "data/clusters_v4.json": "the Clusters Google Doc, then run scripts/parse_clusters_to_sheet.py --json-only", + "data/disciplines.json": "the Open Research Across Disciplines Google Sheet, then run scripts/parse_disciplines_to_json.py", + "data/disciplines_citation.json": "the disciplines Tenzing sheet, then run scripts/build_disciplines_citation.py", "data/ga_data.json": "Google Analytics, then run scripts/download_ga_data.py", + "data/get_involved_projects.json": "the Get Involved Google Sheet or its fallback CSV, then run scripts/build_get_involved.py", } PATTERN_SOURCES = ( + (r"^data/(featured_resources|pub_cards|filter_tags)\.json$", "the recommendations or publications data used by scripts/build_featured_data.py"), (r"^content/curated_resources/", "the curated resources Google Sheet, then run content/resources/resource.py"), - (r"^content/glossary/", "the glossary Google Sheet, then run content/glossary/_create_glossaries.py and _build_references.py"), - (r"^content/post/", "the announcements source used by scripts/create_announcements.R"), + (r"^content/glossary/", "the glossary Google Sheet, then rerun glossary generation in the data-processing workflow"), + (r"^content/post/", "the FORRT Announcements Google Sheet, then run scripts/create_announcements.R"), + (r"^content/contributor-analysis/(?!.*\.Rmd$)", "the Tenzing contributor sheets or the R Markdown under content/contributor-analysis, then rerun the data-processing workflow"), (r"^content/clusters/", "the Clusters Google Doc, then run scripts/parse_clusters_to_sheet.py --json-only and scripts/generate_cluster_pages.py"), ) def generated_source(path): - if not GENERATED.match(path): - return None if path in OUTPUT_SOURCES: return OUTPUT_SOURCES[path] + if not GENERATED.match(path): + return None for pattern, source in PATTERN_SOURCES: if re.match(pattern, path): return source @@ -57,7 +66,7 @@ def changed_paths(base): # Treat renames as delete/add so both paths are checked. NUL separators preserve # whitespace and non-ASCII filenames. diff = subprocess.check_output( - ["git", "diff", "--name-only", "--no-renames", "-z", f"{base}...HEAD", "--"] + ["git", "diff", "--name-only", "--no-renames", "-z", "--end-of-options", f"{base}...HEAD", "--"] ) return [os.fsdecode(path) for path in diff.split(b"\0") if path] diff --git a/scripts/tests/test_check_generated_paths.py b/scripts/tests/test_check_generated_paths.py index 410716b45e2..832c3592480 100644 --- a/scripts/tests/test_check_generated_paths.py +++ b/scripts/tests/test_check_generated_paths.py @@ -22,6 +22,8 @@ def test_generators_and_manual_sources(self): with self.subTest(path=path): self.assertIsNotNone(generated_source(path)) self.assertIn("content/summaries/summaries.py", generated_source("data/summaries.json")) + self.assertIn("Tenzing", generated_source("scripts/forrt_contribs/contributors_cache.csv")) + self.assertIn("AGENTS.md", generated_source("static/partials/another-output.html")) for path in ( "data/partners.json", "data/publications.yaml", From 68916ee9377949d82fd9d681d76d659323dc2660 Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Sun, 22 Nov 2026 11:14:45 +0000 Subject: [PATCH 3/3] Name the main and Doors Games Portal generators --- scripts/check_generated_paths.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/check_generated_paths.py b/scripts/check_generated_paths.py index 87278c70aea..938edaf7786 100644 --- a/scripts/check_generated_paths.py +++ b/scripts/check_generated_paths.py @@ -26,7 +26,10 @@ # Includes the redesign's NEW_OUTPUTS and the summaries generator's output. OUTPUT_SOURCES = { "data/summaries.json": "the published FORRT summaries Google Doc, then run content/summaries/summaries.py", - "data/open_research_games.json": "the Games Portal source sheet, then run scripts/build_games_portal.py", + "data/open_research_games.json": ( + "the Games Portal source sheet, then run scripts/build_games_portal.py on Doors " + "or scripts/open_research_games_portal/Open-Research-Games-Portal.R on main" + ), "data/scholar_citations.json": "the publication citation inputs used by scripts/gs-cite/google_scholar.py", "content/publications/citation_chart.webp": "the publication citation inputs used by scripts/gs-cite/google_scholar.py", "content/about/steering-committee/index.md": "the steering committee or personal-details sheet, then run scripts/generate_sc_profiles.py",