Skip to content

Commit bf304fb

Browse files
authored
Merge pull request #11688 from github/repo-sync
repo sync
2 parents 8ed144e + cd305c6 commit bf304fb

File tree

2 files changed

+54
-28
lines changed

2 files changed

+54
-28
lines changed

.github/allowed-actions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export default [
1313
'alex-page/github-project-automation-plus@bb266ff4dde9242060e2d5418e120a133586d488', // v0.8.1
1414
'andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90', // v1.0.4
1515
'crowdin/github-action@d7f217268068f1244883a993379d62d816f84f25', // v1.4.0
16-
'crykn/copy_folder_to_another_repo_action@0282e8b9fef06de92ddcae9fe6cb44df6226646c',
1716
'cschleiden/actions-linter@caffd707beda4fc6083926a3dff48444bc7c24aa', // uses github-actions-parser v0.23.0
1817
'dawidd6/action-delete-branch@47743101a121ad657031e6704086271ca81b1911', // v3.0.2
1918
'dawidd6/action-download-artifact@af92a8455a59214b7b932932f2662fdefbd78126', // v2.15.0

.github/workflows/site-policy-sync.yml

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Site policy sync
22

33
# **What it does**: Updates our site-policy repo when changes happen to site policy docs.
44
# **Why we have it**: We want keep site-policy repo up to date.
5-
# **Who does it impact**: Site-policy team.
5+
# **Who does it impact**: site-policy-admins and Developer Policy teams.
66

77
# Controls when the action will run.
88
on:
@@ -14,40 +14,67 @@ on:
1414
- closed
1515
paths:
1616
- 'content/github/site-policy/**'
17-
18-
# Allows you to run this workflow manually from the Actions tab
1917
workflow_dispatch:
2018

21-
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
2219
jobs:
23-
# This workflow contains a single job called "build"
24-
copy-file:
20+
sync:
21+
name: Get the latest docs
2522
if: >-
2623
github.event.pull_request.merged == true &&
2724
github.repository == 'github/docs-internal'
28-
# The type of runner that the job will run on
2925
runs-on: ubuntu-latest
30-
31-
# Steps represent a sequence of tasks that will be executed as part of the job
26+
permissions:
27+
contents: write
28+
pull-requests: write
3229
steps:
33-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
34-
- uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97
35-
# Sets commit message
36-
- name: custom message
30+
- name: checkout docs-internal
31+
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97
32+
33+
- name: checkout public site-policy
34+
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97
35+
with:
36+
repository: github/site-policy
37+
token: ${{ secrets.API_TOKEN_SITEPOLICY }}
38+
fetch-depth: ''
39+
path: public-repo
40+
41+
- name: Commits internal policies to copy of public repo with descriptive message from triggering PR title
3742
run: |
38-
echo "MESSAGE=${{github.event.pull_request.title}}" >> $GITHUB_ENV
43+
cd public-repo
44+
git config --local user.name 'site-policy-bot'
45+
git config --local user.email '[email protected]'
46+
rm -rf Policies
47+
cp -r ../content/github/site-policy Policies
48+
git status
49+
git checkout -b automated-sync-$GITHUB_RUN_ID
50+
git add .
51+
PR_TITLE=${{ github.event.pull_request.title }}
52+
[[ ! -z $PR_TITLE ]] && DESCRIPTION="${PR_TITLE}" || DESCRIPTION="Update manually triggered by workflow"
53+
echo "DESCRIPTION=$DESCRIPTION" >> $GITHUB_ENV
54+
git commit -m "$(echo $DESCRIPTION)"
3955
40-
# Pushes to other repo
41-
- name: Push folder to another repository
42-
uses: crykn/copy_folder_to_another_repo_action@0282e8b9fef06de92ddcae9fe6cb44df6226646c
56+
- name: If there are changes to push, create a pull request in the public repo using the gh command line tool, then immediately merge the PR and delete the branch
57+
id: createAndMergePullRequest
4358
env:
44-
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_SITEPOLICY }}
45-
with:
46-
source_folder: 'content/github/site-policy'
47-
destination_repo: 'github/site-policy'
48-
destination_branch: 'main'
49-
destination_branch_create: 'repo-sync'
50-
destination_folder: 'Policies'
51-
user_email: '[email protected]'
52-
user_name: 'site-policy-bot'
53-
commit_msg: '${{ env.MESSAGE }}'
59+
GITHUB_TOKEN: ${{ secrets.API_TOKEN_SITEPOLICY }}
60+
run: |
61+
cd public-repo
62+
git config --local user.name 'site-policy-bot'
63+
git config --local user.email '[email protected]'
64+
DIFF=$(git diff --name-status --summary HEAD^..HEAD)
65+
NUM_FILES_CHANGED=$(git diff --name-only HEAD^..HEAD | wc -l)
66+
[[ $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;')
67+
if [[ ! -z $TITLE ]]
68+
then
69+
echo -e "This is an automated pull request to sync changes from GitHub Docs.\n\nDiff summary:\n\n${DIFF}" > msg
70+
git push --set-upstream origin automated-sync-$GITHUB_RUN_ID
71+
PR_URL=$(gh pr create --title "${TITLE}" --body-file msg --head automated-sync-$GITHUB_RUN_ID --base main --repo github/site-policy)
72+
gh pr diff ${PR_URL}
73+
gh pr merge ${PR_URL} --merge --delete-branch
74+
else
75+
echo "No updates to push to the public repo"
76+
fi
77+
78+
- name: Delete remote updates branch if previous step failed
79+
if: failure() && steps.createAndMergePullRequest.outcome == 'failure'
80+
run: git push github/site-policy --delete automated-sync-$GITHUB_RUN_ID

0 commit comments

Comments
 (0)