diff --git a/.github/workflows/check-links.yml b/.github/workflows/check-links.yml index ca4ab5e3df28..9a06cf3dc37c 100644 --- a/.github/workflows/check-links.yml +++ b/.github/workflows/check-links.yml @@ -5,6 +5,12 @@ on: merge_group: pull_request: +env: + CHANGED_FILES: + PR_NUM: ${{ github.event.issue.number }} + USER_EMAIL: 107717825+opentelemetrybot@users.noreply.github.com + USER_NAME: opentelemetrybot + jobs: build-and-check-links: name: BUILD and CHECK LINKS @@ -43,29 +49,42 @@ jobs: echo "submodule(s); or undo the submodule update(s) if it happened by mistake." npm run _diff:fail - - run: npm run log:check:links + - run: | + npm run log:check:links + CHANGED_FILES=$(git status --porcelain) + echo "CHANGED_FILES=$CHANGED_FILES" >> "$GITHUB_ENV" continue-on-error: true - name: Push changes if any, and fail check + if: ${{ env.CHANGED_FILES }} run: | - if [[ $(git status --porcelain) ]]; then - echo "Changes detected in the refcache etc:" - git status --short - - echo "\nPushing changes to PR." - git config --local user.email "$USER_EMAIL" - git config --local user.name "$USER_NAME" - git add -A - git commit -m "Updates from build-and-check-links workflow" - git push - - echo "Failing workflow so that changes can be reviewed, and checks rerun." - exit 1 - fi + echo "Changes detected in the refcache etc:" + git status --short + + gh pr checkout $PR_NUM -b "pr-check-links-${RANDOM}" + git branch -v + + git config --local user.email "$USER_EMAIL" + git config --local user.name "$USER_NAME" + git add -A + git commit -m "Updates from build-and-check-links workflow" + + echo "\nPushing changes to PR." + current_branch=$(git rev-parse --abbrev-ref HEAD) + echo current_branch=$current_branch + # gh pr checkout sets some git configs that we can use to make sure + # we push to the right repo & to the right branch + remote_repo=$(git config --get branch.${current_branch}.remote) + echo remote_repo=$remote_repo + remote_branch=$(git config --get branch.${current_branch}.merge) + echo remote_branch=$remote_branch + git commit -m "Results from /fix:${PR_ACTION}" + git push ${remote_repo} HEAD:${remote_branch} + + echo "Failing workflow so that changes can be reviewed, and checks rerun." + exit 1 env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - USER_EMAIL: 107717825+opentelemetrybot@users.noreply.github.com - USER_NAME: opentelemetrybot - uses: actions/upload-artifact@v4 with: