Skip to content
Draft
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.github/ @NVIDIA-NeMo/run_maintainers @NVIDIA-NeMo/automation
/.pre-commit-config.yaml @NVIDIA-NeMo/run_maintainers @NVIDIA-NeMo/automation
67 changes: 67 additions & 0 deletions .github/tests/test_guardwords_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Verify the Guardwords caller with synthetic pull request metadata."""

import json
import os
import subprocess
import tempfile
import unittest
from pathlib import Path

import yaml

ROOT = Path(__file__).resolve().parents[2]
WORKFLOW = yaml.load(
(ROOT / ".github/workflows/guardwords-check.yml").read_text(), Loader=yaml.BaseLoader
)


class GuardwordsWorkflow(unittest.TestCase):
"""Check mirror attestation and credential forwarding."""

def test_scan_receives_only_catalog_key_after_verification(self) -> None:
"""Run only on mirror pushes and use the checked commit for scanning."""
self.assertEqual(WORKFLOW["on"], {"push": {"branches": ["pull-request/[0-9]+"]}})
self.assertEqual(WORKFLOW["permissions"], {"contents": "read", "pull-requests": "read"})
job = WORKFLOW["jobs"]["guardwords-check"]
self.assertEqual(job["needs"], "pr_info")
self.assertEqual(job["with"]["head-sha"], "${{ github.sha }}")
self.assertEqual(job["with"]["base-sha"], "${{ needs.pr_info.outputs.base_sha }}")
self.assertEqual(
job["with"]["pr-number"], "${{ fromJSON(needs.pr_info.outputs.pr_number) }}"
)
self.assertEqual(
job["secrets"], {"GUARDWORDS_DEPLOY_KEY": "${{ secrets.GUARDWORDS_DEPLOY_KEY }}"}
)

def test_mirror_must_match_the_current_pr_head(self) -> None:
"""Release PR coordinates only after matching the push SHA to the GitHub response."""
base, head = "a" * 40, "b" * 40
(lookup,) = WORKFLOW["jobs"]["pr_info"]["steps"]
for ref, sha, expected in (
("pull-request/42", head, True),
("pull-request/42", "c" * 40, False),
("pull-request/topic", head, False),
):
with self.subTest(ref=ref, sha=sha), tempfile.TemporaryDirectory() as tmp:
output = Path(tmp, "output")
output.touch()
stub = 'gh() { [[ "$*" == "api repos/NVIDIA-NeMo/Run/pulls/42" ]] && printf "%s" "$PR"; }'
result = subprocess.run(
["bash", "-eo", "pipefail", "-c", f"{stub}\n{lookup['run']}"],
env={
"PATH": os.environ["PATH"],
"PR": json.dumps({"base": {"sha": base}, "head": {"sha": head}}),
"GITHUB_REPOSITORY": "NVIDIA-NeMo/Run",
"GITHUB_REF_NAME": ref,
"GITHUB_SHA": sha,
"GITHUB_OUTPUT": str(output),
},
capture_output=True,
text=True,
)
self.assertEqual(result.returncode == 0, expected, result.stderr)
self.assertEqual(
output.read_text(), f"base_sha={base}\npr_number=42\n" if expected else ""
)
109 changes: 109 additions & 0 deletions .github/tests/test_release_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import re
import subprocess
import tempfile
import unittest
from pathlib import Path

Expand Down Expand Up @@ -132,6 +133,114 @@ def test_validate_ref_treats_input_as_data(self) -> None:
)
self.assertEqual(result.returncode == 0, ref == "a" * 40)

def test_protected_release_authentication(self) -> None:
"""Limit release credentials to the named environment in the called workflows."""
freeze = yaml.safe_load((ROOT / ".github/workflows/release-freeze.yml").read_text())
jobs = (JOBS["bump"], JOBS["finalize"], freeze["jobs"]["code-freeze"])
for job in jobs:
self.assertEqual(job["with"]["release-environment"], "run-release")
self.assertNotIn("app-id", job["with"])
self.assertNotIn("BOT_KEY", job.get("secrets", {}))
self.assertNotIn("RELEASE_APP_PRIVATE_KEY", job.get("secrets", {}))
self.assertEqual(jobs[2]["with"]["freeze-source-branch"], "main")
self.assertEqual(jobs[0]["with"]["release-branch-pattern"], "[rv][0-9]*.[0-9]*.[0-9]*")
self.assertEqual(JOBS["bump"]["permissions"], {"contents": "read"})

def test_workflow_authority(self) -> None:
"""Require explicit job permissions and isolate the dual-organization App."""
directory = ROOT / ".github/workflows"
for path in sorted(directory.glob("*.yml")):
text = path.read_text()
workflow = yaml.safe_load(text)
with self.subTest(workflow=path.name):
for job in workflow["jobs"].values():
self.assertIsInstance(job.get("permissions", workflow.get("permissions")), dict)
self.assertNotEqual(job.get("secrets"), "inherit")
if path.name != "community-bot.yml":
self.assertNotRegex(text, r"secrets\.(BOT_KEY|PAT)\b")
changelog = yaml.safe_load((directory / "changelog-build.yml").read_text())
nightly = yaml.safe_load((directory / "nightly.yml").read_text())
for job in (changelog["jobs"]["changelog"], nightly["jobs"]["tag"]):
self.assertEqual(job["if"], "github.ref == 'refs/heads/main'")

def test_docs_rehearsal_and_production(self) -> None:
"""Build rehearsal documentation and withhold the publisher credentials."""
finalize = JOBS["finalize"]
rehearsal = JOBS["rehearse-docs"]
docs = yaml.safe_load((ROOT / ".github/workflows/release-docs.yml").read_text())
nightly = yaml.safe_load((ROOT / ".github/workflows/release-nightly-docs.yml").read_text())
self.assertIn("rehearse-docs", JOBS["release-summary"]["needs"])
self.assertNotIn("secrets", rehearsal)
self.assertEqual(
set(finalize["secrets"]), set(nightly["jobs"]["call-release-docs"]["secrets"])
)
for ref, kind, dry, allowed in (
("refs/heads/main", "branch", False, True),
("refs/tags/v0.13.0", "tag", False, True),
("refs/heads/main", "branch", True, False),
("refs/heads/topic", "branch", False, False),
):
ctx = {"github.ref": ref, "github.ref_type": kind, "inputs.dry-run": dry}
self.assertEqual(evaluate(docs["jobs"]["publish-docs"]["if"], ctx), allowed)
for event, dry, requested, publish, build in (
("push", False, False, False, True),
("merge_group", False, False, False, True),
("workflow_dispatch", True, True, False, True),
("workflow_dispatch", False, True, True, False),
("workflow_dispatch", False, False, False, False),
):
with self.subTest(event=event, dry=dry, requested=requested):
ctx = {
"github.event_name": event,
"inputs.dry-run": dry,
"inputs.publish-docs": requested,
}
self.assertEqual(evaluate(finalize["with"]["publish-docs"], ctx), publish)
self.assertEqual(evaluate(rehearsal["if"], ctx), build)
gate = finalize["with"]["publish-docs"][4:-3]
for key, value in finalize["secrets"].items():
self.assertEqual(value, "${{ " + gate + " && secrets." + key + " || '' }}")

def test_manual_source_and_target_checks(self) -> None:
"""Accept protected branch ancestry and Run's multi-digit release branches."""
step = JOBS["validate-inputs"]["steps"][1]
self.assertEqual(step["if"], "github.event_name == 'workflow_dispatch'")
sha = "a" * 40
with tempfile.TemporaryDirectory() as directory:
gh = Path(directory) / "gh"
gh.write_text(
'#!/bin/sh\ncase "$2" in */branches/*) echo "$TIP" ;; '
'*/compare/*) echo "$COMPARISON" ;; *) exit 1 ;; esac\n'
)
gh.chmod(0o755)
for source, target, tip, comparison, allowed in (
("main", "r0.12.0", sha, "ahead", True),
("main", "v10.5.20", sha, "identical", True),
("main", "v10.5.20rc2", sha, "identical", False),
("main", "r0.13.0-unreviewed", sha, "identical", False),
("topic", "main", sha, "identical", False),
("main", "topic", sha, "identical", False),
("main", "main", "", "ahead", False),
("main", "main", sha, "diverged", False),
):
with self.subTest(source=source, target=target, tip=tip, comparison=comparison):
env = dict(
os.environ,
PATH=directory + os.pathsep + os.environ["PATH"],
TARGET_BRANCH=target,
RELEASE_REF=sha,
TIP=tip,
COMPARISON=comparison,
GITHUB_REF="refs/heads/" + source,
GITHUB_REPOSITORY="NVIDIA-NeMo/Run",
)
result = subprocess.run(
["bash", "-euo", "pipefail", "-c", step["run"]],
env=env,
capture_output=True,
)
self.assertEqual(result.returncode == 0, allowed, result.stderr)

def test_upload_has_no_checkout_or_password(self) -> None:
"""Keep source execution and build credentials outside the OIDC job."""
self.assertEqual(JOBS["build-wheel"]["permissions"], {"contents": "read"})
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/changelog-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ on:

jobs:
changelog:
if: github.ref == 'refs/heads/main'
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout branch
Expand Down Expand Up @@ -81,9 +86,11 @@ jobs:

- name: Create or update label
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
env:
RELEASE_BRANCH: ${{ inputs.release-branch }}
with:
script: |
const labelName = '${{ inputs.release-branch }}';
const labelName = process.env.RELEASE_BRANCH;
const labelColor = '0366d6'; // Blue color
const labelDescription = `Release ${labelName}`;

Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/close-inactive-issue-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
schedule:
- cron: "30 1 * * *"

permissions:
issues: write
pull-requests: write

jobs:
close-issues:
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_close_inactive_issue_pr.yml@9e07489b8a6bc533c8792099b012c588f4430298 # v0.44.0
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_close_inactive_issue_pr.yml@1ebb754bdbe6680cce2b3d81da4e63be7200380a
6 changes: 5 additions & 1 deletion .github/workflows/community-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ on:
issue_comment:
types: [created, edited, deleted]

permissions:
issues: write
pull-requests: write

jobs:
community-bot:
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_community_bot.yml@98ea77e930f3e1b0f97a1ce5255e12c407e9d0d4 # v1.8.7
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_community_bot.yml@1ebb754bdbe6680cce2b3d81da4e63be7200380a
with:
community_project_id: ${{ vars.COMMUNITY_PROJECT_ID }}
app-id: ${{ vars.BOT_ID }}
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/config/.secrets.baseline

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .github/workflows/copyright-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ on:
branches: ["pull-request/**"]
workflow_dispatch:

permissions:
contents: read
pull-requests: read

jobs:
copyright-check:
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_copyright_check.yml@a8006e87bff5bce54336c3e1e8571563ac70d88e # v0.54.4
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_copyright_check.yml@1ebb754bdbe6680cce2b3d81da4e63be7200380a
5 changes: 4 additions & 1 deletion .github/workflows/detect-secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ on:
push:
branches: ["pull-request/**"]

permissions:
contents: read

jobs:
secrets-detector:
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_secrets-detector.yml@859ae21dd5588c87e3bde499ddab7a3025773e8d # v0.74.0
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_secrets-detector.yml@1ebb754bdbe6680cce2b3d81da4e63be7200380a
41 changes: 41 additions & 0 deletions .github/workflows/guardwords-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
name: Guardwords check

on:
push:
branches: ["pull-request/[0-9]+"]

permissions:
contents: read
pull-requests: read

jobs:
pr_info:
runs-on: ubuntu-latest
outputs:
base_sha: ${{ steps.pr.outputs.base_sha }}
pr_number: ${{ steps.pr.outputs.pr_number }}
steps:
- name: Verify mirror commit
id: pr
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
[[ "$GITHUB_REF_NAME" =~ ^pull-request/([1-9][0-9]*)$ ]]
number=${BASH_REMATCH[1]}
base_sha=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$number" |
jq -er --arg head "$GITHUB_SHA" 'select(.head.sha == $head) | .base.sha')
[[ "$base_sha" =~ ^[0-9a-f]{40}$ ]]
printf 'base_sha=%s\npr_number=%s\n' "$base_sha" "$number" | tee -a "$GITHUB_OUTPUT"

guardwords-check:
needs: pr_info
uses: NVIDIA-NeMo/FW-CI-templates/.github/workflows/_guardwords_check.yml@1ebb754bdbe6680cce2b3d81da4e63be7200380a
with:
base-sha: ${{ needs.pr_info.outputs.base_sha }}
head-sha: ${{ github.sha }}
pr-number: ${{ fromJSON(needs.pr_info.outputs.pr_number) }}
secrets:
GUARDWORDS_DEPLOY_KEY: ${{ secrets.GUARDWORDS_DEPLOY_KEY }}
3 changes: 3 additions & 0 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
push:
branches: [main, "pull-request/**"]

permissions:
contents: read

jobs:
test:
runs-on: ${{ matrix.os }}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- cron: '0 0 * * *' # Runs at midnight UTC every day
workflow_dispatch: # Allows manual trigger

permissions:
contents: read

jobs:
format:
uses: ./.github/workflows/ruff-format.yml
Expand All @@ -14,11 +17,12 @@ jobs:
uses: ./.github/workflows/test.yml
tag:
name: Run Tests and Create Nightly Tag
if: github.ref == 'refs/heads/main'
permissions:
contents: write
runs-on: ubuntu-latest
needs: [format, lint, test]
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6

- name: Create nightly tag
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
Expand Down
Loading