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. # **Who does it impact**: site-policy-admins and Developer Policy teams. # Controls when the action will run. on: # Triggers the workflow pull requests merged to the main branch pull_request: branches: - main types: - closed paths: - 'content/site-policy/**' workflow_dispatch: permissions: contents: read jobs: sync: name: Get the latest docs if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && github.repository == 'github/docs-internal') runs-on: ubuntu-latest steps: - name: checkout docs-internal uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 - name: checkout public site-policy uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 with: repository: github/site-policy token: ${{ secrets.API_TOKEN_SITEPOLICY }} fetch-depth: '' path: public-repo - name: Commits internal policies to copy of public repo with descriptive message from triggering PR title env: PR_TITLE: ${{ github.event.pull_request.title }} run: | cd public-repo git config --local user.name 'site-policy-bot' git config --local user.email 'site-policy-bot@github.com' rm -rf Policies cp -r ../content/site-policy Policies git status git checkout -b automated-sync-$GITHUB_RUN_ID git add . echo PR_TITLE: $PR_TITLE [[ ! -z $PR_TITLE ]] && DESCRIPTION="${PR_TITLE}" || DESCRIPTION="Update manually triggered by workflow" 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 env: GITHUB_TOKEN: ${{ secrets.API_TOKEN_SITEPOLICY }} 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 ]] 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