@@ -2,7 +2,7 @@ name: Site policy sync
2
2
3
3
# **What it does**: Updates our site-policy repo when changes happen to site policy docs.
4
4
# **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 .
6
6
7
7
# Controls when the action will run.
8
8
on :
14
14
- closed
15
15
paths :
16
16
- ' content/github/site-policy/**'
17
-
18
- # Allows you to run this workflow manually from the Actions tab
19
17
workflow_dispatch :
20
18
21
- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
22
19
jobs :
23
- # This workflow contains a single job called "build"
24
- copy-file :
20
+ sync :
21
+ name : Get the latest docs
25
22
if : >-
26
23
github.event.pull_request.merged == true &&
27
24
github.repository == 'github/docs-internal'
28
- # The type of runner that the job will run on
29
25
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
32
29
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
37
42
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)"
39
55
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
43
58
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
-
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