Skip to content

Commit

Permalink
[CI] check-links: update code to push refcache etc
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin committed Jan 31, 2025
1 parent 0d38602 commit b01089a
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
merge_group:
pull_request:

env:
CHANGED_FILES:
PR_NUM: ${{ github.event.issue.number }}
USER_EMAIL: [email protected]
USER_NAME: opentelemetrybot

jobs:
build-and-check-links:
name: BUILD and CHECK LINKS
Expand Down Expand Up @@ -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: [email protected]
USER_NAME: opentelemetrybot

- uses: actions/upload-artifact@v4
with:
Expand Down

0 comments on commit b01089a

Please sign in to comment.