Skip to content

Commit d0dee50

Browse files
authored
[CI] check-links: update code to push refcache etc (open-telemetry#6147)
1 parent 0d38602 commit d0dee50

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

.github/workflows/check-links.yml

+35-17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ on:
55
merge_group:
66
pull_request:
77

8+
env:
9+
CHANGED_FILES:
10+
PR_NUM: ${{ github.event.issue.number }}
11+
USER_EMAIL: [email protected]
12+
USER_NAME: opentelemetrybot
13+
814
jobs:
915
build-and-check-links:
1016
name: BUILD and CHECK LINKS
@@ -43,29 +49,41 @@ jobs:
4349
echo "submodule(s); or undo the submodule update(s) if it happened by mistake."
4450
npm run _diff:fail
4551
46-
- run: npm run log:check:links
52+
- run: |
53+
npm run log:check:links
54+
CHANGED_FILES=$(git status --porcelain)
55+
echo "CHANGED_FILES=$CHANGED_FILES" >> "$GITHUB_ENV"
4756
continue-on-error: true
4857
4958
- name: Push changes if any, and fail check
59+
if: ${{ env.CHANGED_FILES }}
5060
run: |
51-
if [[ $(git status --porcelain) ]]; then
52-
echo "Changes detected in the refcache etc:"
53-
git status --short
54-
55-
echo "\nPushing changes to PR."
56-
git config --local user.email "$USER_EMAIL"
57-
git config --local user.name "$USER_NAME"
58-
git add -A
59-
git commit -m "Updates from build-and-check-links workflow"
60-
git push
61-
62-
echo "Failing workflow so that changes can be reviewed, and checks rerun."
63-
exit 1
64-
fi
61+
echo "Changes detected in the refcache etc:"
62+
git status --short
63+
64+
gh pr checkout $PR_NUM -b "pr-check-links-${RANDOM}"
65+
git branch -v
66+
67+
git config --local user.email "$USER_EMAIL"
68+
git config --local user.name "$USER_NAME"
69+
git add -A
70+
git commit -m "Updates from build-and-check-links workflow"
71+
72+
echo "\nPushing changes to PR."
73+
current_branch=$(git rev-parse --abbrev-ref HEAD)
74+
echo current_branch=$current_branch
75+
# gh pr checkout sets some git configs that we can use to make sure
76+
# we push to the right repo & to the right branch
77+
remote_repo=$(git config --get branch.${current_branch}.remote)
78+
echo remote_repo=$remote_repo
79+
remote_branch=$(git config --get branch.${current_branch}.merge)
80+
echo remote_branch=$remote_branch
81+
git push ${remote_repo} HEAD:${remote_branch}
82+
83+
echo "Failing workflow so that changes can be reviewed, and checks rerun."
84+
exit 1
6585
env:
6686
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
67-
USER_EMAIL: [email protected]
68-
USER_NAME: opentelemetrybot
6987

7088
- uses: actions/upload-artifact@v4
7189
with:

0 commit comments

Comments
 (0)