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
28 changes: 25 additions & 3 deletions .github/workflows/commit-recordings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,37 @@ jobs:
core.setOutput('head_sha', headSha);
core.setOutput('is_fork_pr', headRepo !== `${context.repo.owner}/${context.repo.repo}`);
- name: Checkout PR branch
if: steps.pr-info.outputs.skip != 'true'
- name: Preserve artifacts before checkout
if: steps.pr-info.outputs.skip != 'true' && steps.pr-info.outputs.is_fork_pr != 'true'
run: mv recordings-temp /tmp/recordings-temp 2>/dev/null || true

- name: Checkout PR branch (same-repo)
if: steps.pr-info.outputs.skip != 'true' && steps.pr-info.outputs.is_fork_pr != 'true'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ${{ steps.pr-info.outputs.head_repo }}
ref: ${{ steps.pr-info.outputs.head_ref }}
fetch-depth: 0
token: ${{ github.token }}

- name: Restore artifacts after checkout
Comment on lines +161 to +170

Check failure

Code scanning / CodeQL

Checkout of untrusted code in trusted context High

Potential execution of untrusted code on a privileged workflow (
workflow_run
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a false positive. The workflow_run checkout is only used to get the branch state for committing recording files on top of. No code from the checkout is executed - the subsequent steps only run cp, git add, git commit, and git push. The recording files themselves are generated by the unprivileged pull_request-triggered workflow and passed via artifacts

if: steps.pr-info.outputs.skip != 'true' && steps.pr-info.outputs.is_fork_pr != 'true'
run: mv /tmp/recordings-temp recordings-temp 2>/dev/null || true

- name: Checkout PR branch (fork)
if: steps.pr-info.outputs.skip != 'true' && steps.pr-info.outputs.is_fork_pr == 'true'
env:
# RELEASE_PAT has repo scope, which allows cloning and pushing to fork
# PR branches when maintainerCanModify is enabled. github.token can't do this.
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
HEAD_REPO: ${{ steps.pr-info.outputs.head_repo }}
HEAD_REF: ${{ steps.pr-info.outputs.head_ref }}
run: |
# Move artifacts out of the way before cloning, then restore after.
mv recordings-temp /tmp/recordings-temp 2>/dev/null || true
git clone --depth 1 --branch "${HEAD_REF}" "https://x-access-token:${GH_TOKEN}@github.com/${HEAD_REPO}.git" .
mv /tmp/recordings-temp recordings-temp 2>/dev/null || true
- name: Copy recordings to repo
if: steps.pr-info.outputs.skip != 'true'
run: |
Expand All @@ -186,7 +208,7 @@ jobs:
- name: Commit and push recordings
if: steps.pr-info.outputs.skip != 'true'
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ steps.pr-info.outputs.is_fork_pr == 'true' && secrets.RELEASE_PAT || github.token }}
PR_NUMBER: ${{ steps.pr-info.outputs.pr_number }}
HEAD_REPO: ${{ steps.pr-info.outputs.head_repo }}
HEAD_REF: ${{ steps.pr-info.outputs.head_ref }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/record-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ jobs:
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
if [ -n "$INPUT_PR_NUMBER" ]; then
# Fetch PR info via API
PR_DATA=$(gh pr view "$INPUT_PR_NUMBER" --repo "$REPO" --json number,headRefName,headRefOid,headRepository)
PR_DATA=$(gh pr view "$INPUT_PR_NUMBER" --repo "$REPO" --json number,headRefName,headRefOid,headRepository,headRepositoryOwner)
PR_NUMBER="$INPUT_PR_NUMBER"
HEAD_REF=$(echo "$PR_DATA" | jq -r '.headRefName')
HEAD_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')
HEAD_REPO=$(echo "$PR_DATA" | jq -r '.headRepository.nameWithOwner')
# headRepository.nameWithOwner can be empty for fork PRs, so construct it manually
HEAD_REPO=$(echo "$PR_DATA" | jq -r '"\(.headRepositoryOwner.login)/\(.headRepository.name)"')
else
# Use current branch
PR_NUMBER="manual"
Expand Down
Loading