Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/generated-paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Generated paths

on:
pull_request:
branches: [main, rebrand-doors]
types: [opened, synchronize, reopened, labeled, unlabeled]

permissions:
contents: read

concurrency:
group: generated-paths-${{ github.event.pull_request.number }}
cancel-in-progress: true

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:
ref: ${{ github.event.pull_request.head.sha }}
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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This runs the checker from the untrusted PR tree, so a contributor can change scripts/check_generated_paths.py to ignore generated paths or always exit successfully. Run validation logic from a trusted base revision or keep the policy in a protected workflow/action instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/workflows/generated-paths.yaml, line 39:

<comment>This runs the checker from the untrusted PR tree, so a contributor can change `scripts/check_generated_paths.py` to ignore generated paths or always exit successfully. Run validation logic from a trusted base revision or keep the policy in a protected workflow/action instead.</comment>

<file context>
@@ -0,0 +1,39 @@
+        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"
</file context>

94 changes: 94 additions & 0 deletions scripts/check_generated_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/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/"
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
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/"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This check misses generated newsletter archives, allowing hand edits under static/newsletters/ to bypass the guard even though the data workflow regenerates and overwrites them. Add static/newsletters/ to the generated-path alternatives.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At scripts/check_generated_paths.py, line 21:

<comment>This check misses generated newsletter archives, allowing hand edits under `static/newsletters/` to bypass the guard even though the data workflow regenerates and overwrites them. Add `static/newsletters/` to the generated-path alternatives.</comment>

<file context>
@@ -0,0 +1,82 @@
+    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/)[^/]+$)"
</file context>
Suggested change
r"|static/partials/"
r"|static/partials/|static/newsletters/"

r"|scripts/forrt_contribs/contributors_cache\.csv$"
r"|data/(?!partners\.json$|publications\.yaml$|themes/|fonts/)[^/]+$)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The data rule incorrectly treats the hand-maintained lesson-plan data as generated. Exclude lesson_plans.json from this pattern so contributors can update the lesson-plan catalog.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At scripts/check_generated_paths.py, line 23:

<comment>The data rule incorrectly treats the hand-maintained lesson-plan data as generated. Exclude `lesson_plans.json` from this pattern so contributors can update the lesson-plan catalog.</comment>

<file context>
@@ -0,0 +1,82 @@
+    r"|static/data/"
+    r"|static/partials/"
+    r"|scripts/forrt_contribs/contributors_cache\.csv$"
+    r"|data/(?!partners\.json$|publications\.yaml$|themes/|fonts/)[^/]+$)"
+)
+
</file context>
Suggested change
r"|data/(?!partners\.json$|publications\.yaml$|themes/|fonts/)[^/]+$)"
r"|data/(?!lesson_plans\.json$|partners\.json$|publications\.yaml$|themes/|fonts/)[^/]+$)"

)

# 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": (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The Games Portal mapping misses the checked-in static/data/open_research_games.json output, so edits to that generated file still receive only generic AGENTS.md guidance. Map both branch-specific output paths to their corresponding generators.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At scripts/check_generated_paths.py, line 29:

<comment>The Games Portal mapping misses the checked-in `static/data/open_research_games.json` output, so edits to that generated file still receive only generic `AGENTS.md` guidance. Map both branch-specific output paths to their corresponding generators.</comment>

<file context>
@@ -23,30 +23,42 @@
 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"
</file context>

"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",
"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 rerun glossary generation in the data-processing workflow"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This guidance is incomplete for generated glossary references: those sources live in the Glossary BibTex Google Doc, not the term sheet, and _create_glossaries.py runs only with regenerate_glossary=true. Distinguish the two sources and tell contributors to manually dispatch data-processing.yml with that input.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At scripts/check_generated_paths.py, line 47:

<comment>This guidance is incomplete for generated glossary references: those sources live in the Glossary BibTex Google Doc, not the term sheet, and `_create_glossaries.py` runs only with `regenerate_glossary=true`. Distinguish the two sources and tell contributors to manually dispatch `data-processing.yml` with that input.</comment>

<file context>
@@ -23,30 +23,39 @@
     (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"),
</file context>
Suggested change
(r"^content/glossary/", "the glossary Google Sheet, then rerun glossary generation in the data-processing workflow"),
(r"^content/glossary/", "the Glossary Google Sheet for terms or the Glossary BibTex Google Doc for references, then manually dispatch data-processing.yml with regenerate_glossary=true"),

(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 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
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", "--end-of-options", 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())
72 changes: 72 additions & 0 deletions scripts/tests/test_check_generated_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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"))
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",
"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)
Loading