Skip to content

Commit cafdea9

Browse files
google-labs-jules[bot]greenc-FNALCopilot
authored
Improve Workflow Robustness and Feedback (#256)
* maintenance: Improve workflow robustness and feedback This commit introduces two main improvements to the GitHub Actions workflows: 1. **Emoji Reaction for Issue Comments:** The `get-pr-info` reusable action now automatically adds an "eyes" (👀) emoji reaction to any issue comment that triggers a workflow. This provides immediate visual feedback to the user that their command has been acknowledged. This logic is centralized in the reusable action, ensuring it is applied consistently across all workflows that use it. 2. **Robust Concurrent Push Handling:** The `handle-fix-commit` reusable action has been enhanced to gracefully handle race conditions where multiple workflows attempt to push to the same branch simultaneously. The third-party `EndBug/add-and-commit` action has been replaced with a custom script that implements a "rebase and retry" mechanism. If a push fails, the script will automatically fetch the latest changes, rebase the local commit, and retry the push, attempting this up to five times before failing. This prevents silent failures and makes the "fix" workflows more reliable. * maintenance: Address feedback from code review This commit incorporates feedback from the code review: - Adds a conditional check to the emoji reaction step to ensure it only runs on `issue_comment` events. - Improves the `handle-fix-commit` action by: - Using local instead of global git config. - Properly authenticating git push with the provided token. - Refining the rebase-and-retry logic for better robustness. - Ensuring the reported commit SHA is accurate after a potential rebase. * maintenance: Address feedback from code review This commit incorporates feedback from the code review: - Adds a conditional check to the emoji reaction step to ensure it only runs on `issue_comment` events. - Improves the `handle-fix-commit` action by: - Using local instead of global git config. - Properly authenticating git push with the provided token. - Refining the rebase-and-retry logic for better robustness. - Ensuring the reported commit SHA is accurate after a potential rebase. * fix: Correct remote URL for forks in handle-fix-commit This commit addresses a critical bug in the `handle-fix-commit` action where the `git remote` was always being set to the base repository. The action now correctly uses the `pr-info-repo` input to set the remote URL. This ensures that for pull requests from forks, the `git fetch`, `git rebase`, and `git push` commands all target the contributor's forked repository, allowing the rebase-and-retry logic to function as intended. * fix: Improve security and robustness of handle-fix-commit This commit addresses feedback from the latest code review, making the `handle-fix-commit` action more secure and robust: - **Secure Token Handling:** Replaces the `git remote set-url` method with a credential helper to avoid exposing the token in logs. - **Safer Staging:** Changes `git add .` to `git add -u` to prevent accidentally staging untracked files. - **Configurable Retries:** Adds a `retry-attempts` input to the action, making the retry logic transparent and configurable, with a default of 6. * Delete credentials file on exit Avoids potential credential leakage, per #256 (comment) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Chris Green <greenc@fnal.gov> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 590a4d9 commit cafdea9

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

.github/actions/get-pr-info/action.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ runs:
2525
core.setOutput('ref', pr.data.head.ref);
2626
core.setOutput('sha', pr.data.head.sha);
2727
core.setOutput('repo', pr.data.head.repo.full_name);
28+
- name: React to comment
29+
if: github.event_name == 'issue_comment'
30+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
31+
continue-on-error: true
32+
with:
33+
script: |
34+
github.rest.reactions.createForIssueComment({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
comment_id: context.payload.comment.id,
38+
content: 'eyes'
39+
});

.github/actions/handle-fix-commit/action.yaml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ inputs:
1818
pr-info-repo:
1919
description: 'The repository of the PR'
2020
required: true
21+
retry-attempts:
22+
description: 'The number of times to retry pushing the commit.'
23+
required: false
24+
default: '6'
2125

2226
runs:
2327
using: "composite"
@@ -53,21 +57,50 @@ runs:
5357
core.setOutput('maintainer_can_modify', pr.maintainer_can_modify);
5458
- name: Commit fixes
5559
if: steps.check_changes.outputs.changes == 'true' && (inputs.pr-info-repo == github.repository || steps.pr-properties.outputs.maintainer_can_modify == 'true')
56-
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4
57-
id: add_and_commit
58-
with:
59-
token: ${{ inputs.token }}
60-
cwd: ${{ inputs.working-directory }}
61-
author_name: "github-actions[bot]"
62-
author_email: "41898282+github-actions[bot]@users.noreply.github.com"
63-
message: "Apply ${{ inputs.tool }} fixes"
60+
id: commit_and_push
61+
shell: bash
62+
working-directory: ${{ inputs.working-directory }}
63+
run: |
64+
git config --local user.name "github-actions[bot]"
65+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
66+
67+
export GITHUB_TOKEN=${{ inputs.token }}
68+
echo "https://x-access-token:${GITHUB_TOKEN}@github.com" > ~/.git-credentials
69+
trap 'rm -f ~/.git-credentials' EXIT
70+
git config --local credential.helper 'store --file ~/.git-credentials'
71+
72+
git add -u
73+
git commit -m "Apply ${{ inputs.tool }} fixes"
74+
75+
for i in $(seq 1 ${{ inputs.retry-attempts }}); do
76+
if git push origin HEAD:${{ inputs.pr-info-ref }}; then
77+
echo "Push successful on attempt $i."
78+
COMMIT_SHA=$(git rev-parse HEAD)
79+
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
80+
echo "pushed=true" >> $GITHUB_OUTPUT
81+
exit 0
82+
fi
83+
if [ $i -eq ${{ inputs.retry-attempts }} ]; then
84+
break
85+
fi
86+
echo "Push failed on attempt $i. Fetching and rebasing before retry..."
87+
git fetch origin
88+
if ! git rebase origin/${{ inputs.pr-info-ref }}; then
89+
echo "::error::Automatic rebase failed. Please resolve conflicts manually."
90+
exit 1
91+
fi
92+
echo "Waiting before retry..."
93+
sleep $((5 * i))
94+
done
95+
echo "::error::Failed to push changes after multiple retries."
96+
exit 1
6497
6598
- name: Notify of commit
66-
if: steps.add_and_commit.conclusion == 'success' && steps.add_and_commit.outputs.committed == 'true' && steps.add_and_commit.outputs.pushed == 'true'
99+
if: steps.commit_and_push.conclusion == 'success' && steps.commit_and_push.outputs.pushed == 'true'
67100
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
68101
with:
69102
message: |
70-
Automatic ${{ inputs.tool }} fixes pushed (commit ${{ steps.add_and_commit.outputs.commit_sha }}).
103+
Automatic ${{ inputs.tool }} fixes pushed (commit ${{ steps.commit_and_push.outputs.commit_sha }}).
71104
⚠️ **Note:** Some issues may require manual review and fixing.
72105
73106
- name: Create patch

0 commit comments

Comments
 (0)