1
0
mirror of synced 2026-01-06 06:02:35 -05:00

Only create a branch in the site policy repo if there are changes to push (#31100)

This commit is contained in:
Robert Sese
2022-10-03 17:51:31 -05:00
committed by GitHub
parent 61f1346c56
commit 6e8bdac02f

View File

@@ -1,7 +1,7 @@
name: Site policy sync
# **What it does**: Updates our site-policy repo when changes happen to site policy docs.
# **Why we have it**: We want keep site-policy repo up to date.
# **What it does**: Creates a branch in our site-policy repo with changes to site policy docs.
# **Why we have it**: We want to keep the site-policy repo up to date.
# **Who does it impact**: site-policy-admins and Developer Policy teams.
# Controls when the action will run.
@@ -53,24 +53,17 @@ jobs:
echo "DESCRIPTION=$DESCRIPTION" >> $GITHUB_ENV
git commit -m "$(echo $DESCRIPTION)"
- name: If there are changes to push, create a pull request in the public repo using the gh command line tool, then immediately approve the PR
id: createAndMergePullRequest
- name: If there are changes to push, create a branch in the public repo and push changes
env:
GITHUB_TOKEN: ${{ secrets.API_TOKEN_SITEPOLICY }}
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
run: |
cd public-repo
git config --local user.name 'site-policy-bot'
git config --local user.email 'site-policy-bot@github.com'
DIFF=$(git diff --name-status --summary HEAD^..HEAD)
NUM_FILES_CHANGED=$(git diff --name-only HEAD^..HEAD | wc -l)
[[ $NUM_FILES_CHANGED -ge 2 ]] && TITLE="Sync changes from GitHub Docs" || TITLE=$(echo $DIFF | sed -e 's/^A\s/Added /g;s/^D\s/Deleted /g;s/^C\s/Copied /g;s/^M\s/Modified /g;s/^R100\s/Renamed /g;')
if [[ ! -z $TITLE ]]
if [[ $NUM_FILES_CHANGED -ge 1]]
then
echo -e "This is an automated pull request to sync changes from GitHub Docs.\n\nDiff summary:\n\n${DIFF}" > msg
git push --set-upstream origin automated-sync-$GITHUB_RUN_ID
PR_URL=$(gh pr create --title "${TITLE}" --body-file msg --head automated-sync-$GITHUB_RUN_ID --base main --repo github/site-policy)
gh pr diff ${PR_URL}
gh pr review --approve || echo "Nothing to approve"
else
echo "No updates to push to the public repo"
fi