3434
3535 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3636 with :
37- ref : refs/pull/${{ github.event.issue.number }}/head
3837 fetch-depth : 999
3938
4039 - name : Extract action name
@@ -43,23 +42,19 @@ jobs:
4342 PR_ACTION=$(echo "$COMMENT" | grep -oP '/fix:\K[:-_0-9a-z]+')
4443 echo "action_name=$PR_ACTION" >> "$GITHUB_OUTPUT"
4544
45+ - run : gh pr checkout $PR_NUM -b "pr-action-${RANDOM}"
46+ env :
47+ GH_TOKEN : ${{ github.token }}
48+
4649 - name : Setup Node
4750 uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
4851 with :
4952 node-version-file : .nvmrc
50- cache : npm
5153
5254 - name : Install deps & run fixer
5355 run : |
54- npm ci
55- case ${{ steps.extract.outputs.action_name }} in
56- all|refcache*|text)
57- npm install --omit=optional
58- ;&
59- *)
60- npm run fix:${{ steps.extract.outputs.action_name }}
61- ;;
62- esac
56+ npm install --omit=optional
57+ npm run fix:${{ steps.extract.outputs.action_name }}
6358
6459 - name : Generate and validate patch
6560 id : check_patch
@@ -104,29 +99,42 @@ jobs:
10499
105100 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
106101 with :
107- ref : refs/pull/${{ github.event.issue.number }}/head
108102 fetch-depth : 999
109103
104+ - run : gh pr checkout $PR_NUM -b "pr-action-${RANDOM}"
105+ env :
106+ GH_TOKEN : ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
107+
110108 - name : Download patch
111109 uses : actions/download-artifact@v4
112110 with :
113111 name : ${{ needs.generate-patch.outputs.patch_name }}
114112
115- - name : Apply patch and push
113+ - name : Apply patch
116114 run : |
117115 git apply --check pr-fix.patch && git apply pr-fix.patch || {
118116 echo "Patch failed to apply"
119117 exit 1
120118 }
121119
122- git config user.name "$USER_NAME"
123- git config user.email "$USER_EMAIL"
124-
125- if git diff --quiet; then
126- echo "No changes to commit"
120+ - name : Commit and push changes, if any
121+ run : |
122+ git config --local user.email "$USER_EMAIL"
123+ git config --local user.name "$USER_NAME"
124+ if [[ $(git status --porcelain) ]]; then
125+ git add -A
126+ current_branch=$(git rev-parse --abbrev-ref HEAD)
127+ echo current_branch=$current_branch
128+ # gh pr checkout sets some git configs that we can use to make sure
129+ # we push to the right repo & to the right branch
130+ remote_repo=$(git config --get branch.${current_branch}.remote)
131+ echo remote_repo=$remote_repo
132+ remote_branch=$(git config --get branch.${current_branch}.merge)
133+ echo remote_branch=$remote_branch
134+ git commit -m "Results from /fix:${PR_ACTION}"
135+ git push ${remote_repo} HEAD:${remote_branch}
127136 else
128- git commit -am "Results from /fix:${{ needs.generate-patch.outputs.action_name }}"
129- git push
137+ echo "No changes to commit"
130138 fi
131139 env :
132140 GH_TOKEN : ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
0 commit comments