Use env vars for workflow_run context values in example workflows (#1125)
* Use env vars for workflow_run context values in example workflows * Add security note to ci-failure-auto-fix example about trust requirements
This commit is contained in:
parent
85133eeab2
commit
263993d836
@ -1,5 +1,21 @@
|
||||
name: Auto Fix CI Failures
|
||||
|
||||
# ⚠️ SECURITY NOTE
|
||||
#
|
||||
# This workflow checks out the PR branch and runs build/test commands
|
||||
# (npm, bun, etc.) against it with elevated permissions (contents:write,
|
||||
# id-token:write). This means code from the PR branch executes in a
|
||||
# trusted context with access to secrets and the ability to push to the
|
||||
# repository.
|
||||
#
|
||||
# Only use this workflow in repositories where everyone with write access
|
||||
# is fully trusted with these permissions. Do not use this in repositories
|
||||
# that accept contributions from untrusted or semi-trusted collaborators.
|
||||
#
|
||||
# The pull_requests[0] check below limits this to same-repo PRs (fork PRs
|
||||
# are excluded), but anyone who can push a branch to this repository can
|
||||
# control what code runs here.
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["CI"]
|
||||
@ -35,10 +51,14 @@ jobs:
|
||||
|
||||
- name: Create fix branch
|
||||
id: branch
|
||||
env:
|
||||
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
||||
RUN_ID: ${{ github.run_id }}
|
||||
run: |
|
||||
BRANCH_NAME="claude-auto-fix-ci-${{ github.event.workflow_run.head_branch }}-${{ github.run_id }}"
|
||||
SAFE_BRANCH=$(printf '%s' "$HEAD_BRANCH" | tr -cd 'a-zA-Z0-9/_.-')
|
||||
BRANCH_NAME="claude-auto-fix-ci-${SAFE_BRANCH}-${RUN_ID}"
|
||||
git checkout -b "$BRANCH_NAME"
|
||||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Get CI failure details
|
||||
id: failure_details
|
||||
|
||||
@ -53,6 +53,8 @@ jobs:
|
||||
fromJSON(steps.detect.outputs.structured_output).confidence >= 0.7
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
|
||||
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
||||
run: |
|
||||
OUTPUT='${{ steps.detect.outputs.structured_output }}'
|
||||
CONFIDENCE=$(echo "$OUTPUT" | jq -r '.confidence')
|
||||
@ -63,8 +65,7 @@ jobs:
|
||||
echo ""
|
||||
echo "Triggering automatic retry..."
|
||||
|
||||
gh workflow run "${{ github.event.workflow_run.name }}" \
|
||||
--ref "${{ github.event.workflow_run.head_branch }}"
|
||||
gh workflow run "$WORKFLOW_NAME" --ref "$HEAD_BRANCH"
|
||||
|
||||
# Low confidence flaky detection - skip retry
|
||||
- name: Low confidence detection
|
||||
@ -83,13 +84,14 @@ jobs:
|
||||
if: github.event.workflow_run.event == 'pull_request'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
||||
run: |
|
||||
OUTPUT='${{ steps.detect.outputs.structured_output }}'
|
||||
IS_FLAKY=$(echo "$OUTPUT" | jq -r '.is_flaky')
|
||||
CONFIDENCE=$(echo "$OUTPUT" | jq -r '.confidence')
|
||||
SUMMARY=$(echo "$OUTPUT" | jq -r '.summary')
|
||||
|
||||
pr_number=$(gh pr list --head "${{ github.event.workflow_run.head_branch }}" --json number --jq '.[0].number')
|
||||
pr_number=$(gh pr list --head "$HEAD_BRANCH" --json number --jq '.[0].number')
|
||||
|
||||
if [ -n "$pr_number" ]; then
|
||||
if [ "$IS_FLAKY" = "true" ]; then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user