Repository navigation
Check pull requests for edits to generated site files #1288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
| 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/" | ||||||
|
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/" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This check misses generated newsletter archives, allowing hand edits under Prompt for AI agents
Suggested change
|
||||||
| r"|scripts/forrt_contribs/contributors_cache\.csv$" | ||||||
| r"|data/(?!partners\.json$|publications\.yaml$|themes/|fonts/)[^/]+$)" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Prompt for AI agents
Suggested change
|
||||||
| ) | ||||||
|
|
||||||
| # 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": ( | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The Games Portal mapping misses the checked-in Prompt for AI agents |
||||||
| "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"), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Prompt for AI agents
Suggested change
|
||||||
| (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()) | ||||||
| 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) |
There was a problem hiding this comment.
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.pyto 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