Skip to content
Merged
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
15 changes: 12 additions & 3 deletions .github/scripts/create_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@

4. **Job Isolation (`--verify-applied`)**:
The workflow runs this script in a `generate` job that has the Gemini key
but no write token, and never compiles the result. The patch is compiled
in a separate job that has no secrets. The `publish` job, which holds the
write token, applies the patch to the base commit and runs
with `contents:read` and `issues:write` (for early branch-exists notices),
and never compiles the result. The patch is compiled in a separate job that
has no secrets. The `publish` job, which holds the write token, applies the
patch to the base commit and runs
`create_pr.py --verify-applied pr_metadata.json` from that commit. This
checks again that only the listed `.kt` files changed and that the PR
metadata is sanitized before anything is pushed.
Expand Down Expand Up @@ -474,6 +475,9 @@ def main():
updated_content = get_gemini_response(api_key, edit_system, edit_user)
if updated_content:
updated_content = strip_markdown_code_fence(updated_content)
if updated_content == original_content:
print(f"No changes generated for {filepath}, skipping.", file=sys.stderr)
continue
with open(filepath, "w", encoding="utf-8") as f:
f.write(updated_content)
changed_files.append(filepath)
Expand Down Expand Up @@ -504,6 +508,11 @@ def main():
new_content = get_gemini_response(api_key, create_system, create_user)
if new_content:
new_content = strip_markdown_code_fence(new_content)
if os.path.isfile(filepath):
with open(filepath, "r", encoding="utf-8") as f:
if f.read() == new_content:
print(f"No changes generated for {filepath}, skipping.", file=sys.stderr)
continue
os.makedirs(os.path.dirname(filepath), exist_ok=True)
with open(filepath, "w", encoding="utf-8") as f:
f.write(new_content)
Expand Down
386 changes: 386 additions & 0 deletions .github/scripts/test_create_pr.py

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions .github/workflows/auto-fix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ name: Auto-Fix and PR Creator
# The patch is generated from untrusted issue content, so the work is split into
# three jobs that never share a runner:
#
# 1. generate - holds GEMINI_API_KEY and a read-only token. Writes the
# patch and PR metadata, uploads them as an artifact, and
# never runs Gradle or any other generated code.
# 1. generate - holds GEMINI_API_KEY with contents:read and issues:write
# (for early branch-exists notices). Writes the patch and PR
# metadata, uploads them as an artifact, and never runs Gradle
# or any other generated code.
# 2. compile - runs Gradle on the patched tree with no secrets and a
# read-only token. This is the only job that runs generated code.
# 3. publish - holds the write token. Checks the artifact digest, checks the
Expand Down Expand Up @@ -55,6 +56,7 @@ jobs:
github.event.label.name == 'agent: create-pr' ||
github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
issues: write
Expand Down Expand Up @@ -116,6 +118,10 @@ jobs:
# Mark new files as intent-to-add so `git diff` includes them.
git add --intent-to-add -- "${CHANGED_FILES[@]}"
git diff --binary -- "${CHANGED_FILES[@]}" > "$OUT_DIR/autofix.patch"
if [ ! -s "$OUT_DIR/autofix.patch" ]; then
echo "::error::Generated patch is empty; aborting."
exit 1
fi
cp pr_metadata.json "$OUT_DIR/pr_metadata.json"
echo "patch-sha256=$(sha256sum "$OUT_DIR/autofix.patch" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
echo "metadata-sha256=$(sha256sum "$OUT_DIR/pr_metadata.json" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
Expand All @@ -132,6 +138,7 @@ jobs:
compile:
needs: generate
runs-on: ubuntu-latest
timeout-minutes: 20
# Generated code runs here. No secrets and a read-only token.
permissions:
contents: read
Expand Down Expand Up @@ -173,6 +180,7 @@ jobs:
# does not post a failure comment or remove the label while the new run is in progress.
if: ${{ !cancelled() && needs.generate.result == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
pull-requests: write
Expand Down Expand Up @@ -228,10 +236,12 @@ jobs:
env:
ISSUE_NUMBER: ${{ github.event.issue.number || github.event.inputs.number }}
run: |
# Copy create_pr.py out of the working tree before applying the patch and
# run Python in isolated mode (-I) so a tampered patch cannot overwrite
# the validator or shadow stdlib modules in .github/scripts/ or the repo root.
cp .github/scripts/create_pr.py "$RUNNER_TEMP/verify_create_pr.py"
git apply -- "$PATCH"
# create_pr.py comes from the base commit, not from the patch, so it
# can check that the patch touches only allowed .kt files.
python .github/scripts/create_pr.py --verify-applied "$METADATA"
python -I "$RUNNER_TEMP/verify_create_pr.py" --verify-applied "$METADATA"

- name: Push Changes and Create Pull Request
# Use GITHUB_TOKEN (never SYNCED_GITHUB_TOKEN_REPO) and open as a draft PR so that
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/baseline-profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ jobs:
- name: Setup Gradle
if: steps.stale.outputs.stale == 'true'
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
# The auto-fix workflow compiles AI-generated code in the default-branch context, which
# can write to the Actions cache for main. Do not restore that cache in jobs that hold
# release, API, or repository credentials.
with:
cache-disabled: true

- name: Enable KVM
if: steps.stale.outputs.stale == 'true'
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/coverage-history.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ jobs:

- name: Setup Gradle
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
# The auto-fix workflow compiles AI-generated code in the default-branch context, which
# can write to the Actions cache for main. Do not restore that cache in jobs that hold
# release, API, or repository credentials.
with:
cache-disabled: true

- name: Resolve commit metadata
id: meta
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/demo-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ jobs:
- name: Setup Gradle
if: steps.key.outputs.available == 'true'
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
# The auto-fix workflow compiles AI-generated code in the default-branch context, which
# can write to the Actions cache for main. Do not restore that cache in jobs that hold
# release, API, or repository credentials.
with:
cache-disabled: true

- name: Enable KVM
if: steps.key.outputs.available == 'true'
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/instrumentation-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ jobs:

- name: Setup Gradle
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
# The auto-fix workflow compiles AI-generated code in the default-branch context, which
# can write to the Actions cache for main. Do not restore that cache in jobs that hold
# release, API, or repository credentials.
with:
cache-disabled: true

- name: Inject Maps API Key
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Run GitHub script unit tests

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My two cents: this job still restores the main Gradle cache while holding a pull-requests: write token for the coverage comment. The impact is small, but should we disable the cache here too, for consistency with the other workflows?

run: python3 -B -m unittest discover -s .github/scripts -p 'test_*.py' -v

- name: Set up JDK 21
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0
with:
Expand Down
Loading