|
6 | 6 | - develop
|
7 | 7 | paths:
|
8 | 8 | - "docs/**"
|
9 |
| - |
10 | 9 | repository_dispatch:
|
11 | 10 | types: [docs]
|
| 11 | + gollum: |
| 12 | + |
| 13 | +env: |
| 14 | + THIRD_PARTY_GIT_AUTHOR_EMAIL: [email protected] |
| 15 | + THIRD_PARTY_GIT_AUTHOR_NAME: nr-opensource-bot |
12 | 16 |
|
13 | 17 | jobs:
|
14 |
| - job-sync-documentation: |
| 18 | + # Syncs changes made to the Wiki through the GitHub UI to the docs directory |
| 19 | + # Modified from: https://github.com/SwiftDocOrg/github-wiki-publish-action/blob/v1/entrypoint.sh |
| 20 | + job-sync-wiki-to-docs: |
15 | 21 | runs-on: ubuntu-latest
|
| 22 | + if: github.event_name == 'gollum' |
| 23 | + env: |
| 24 | + GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.NEWRELIC_BOT_TOKEN }} |
16 | 25 | steps:
|
17 |
| - - uses: actions/checkout@v2 |
18 |
| - # Additional steps to generate documentation in "Documentation" directory |
19 |
| - - name: Upload Documentation to Wiki |
20 |
| - uses: SwiftDocOrg/github-wiki-publish-action@v1 |
| 26 | + - name: Checkout Repo |
| 27 | + uses: actions/checkout@v2 |
21 | 28 | with:
|
22 |
| - path: "docs" |
23 |
| - env: |
24 |
| - GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.NEWRELIC_BOT_TOKEN }} |
| 29 | + token: ${{ secrets.NEWRELIC_BOT_TOKEN }} # allows us to push back to repo |
| 30 | + - name: Sync wiki to docs |
| 31 | + run: | |
| 32 | + function debug() { |
| 33 | + echo "$1" |
| 34 | + } |
| 35 | +
|
| 36 | + function warning() { |
| 37 | + echo "::warning::$1" |
| 38 | + } |
| 39 | +
|
| 40 | + function error() { |
| 41 | + echo "::error::$1" |
| 42 | + } |
| 43 | +
|
| 44 | + function add_mask() { |
| 45 | + echo "::add-mask::$1" |
| 46 | + } |
| 47 | +
|
| 48 | + # check that vars are set |
| 49 | + if [ -z "$GITHUB_ACTOR" ]; then |
| 50 | + error "GITHUB_ACTOR environment variable is not set" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | +
|
| 54 | + if [ -z "$GITHUB_REPOSITORY" ]; then |
| 55 | + error "GITHUB_REPOSITORY environment variable is not set" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + if [ -z "$GH_PERSONAL_ACCESS_TOKEN" ]; then |
| 60 | + error "GH_PERSONAL_ACCESS_TOKEN environment variable is not set" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + add_mask "${GH_PERSONAL_ACCESS_TOKEN}" |
| 65 | +
|
| 66 | + if [ -z "${WIKI_COMMIT_MESSAGE:-}" ]; then |
| 67 | + debug "WIKI_COMMIT_MESSAGE not set, using default" |
| 68 | + WIKI_COMMIT_MESSAGE='chore(docs): Sync wiki to docs [skip ci]' |
| 69 | + fi |
| 70 | +
|
| 71 | + GIT_REPOSITORY_URL="https://${GH_PERSONAL_ACCESS_TOKEN}@github.com/$GITHUB_REPOSITORY.wiki.git" |
| 72 | +
|
| 73 | + debug "Checking out wiki repository" |
| 74 | + tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) |
| 75 | + ( |
| 76 | + cd "$tmp_dir" || exit 1 |
| 77 | + git init |
| 78 | + git config user.name "$GITHUB_ACTOR" |
| 79 | + git config user.email "[email protected]" |
| 80 | + git pull "$GIT_REPOSITORY_URL" |
| 81 | + ) |
| 82 | +
|
| 83 | + debug "diffing files" |
| 84 | + files_modified=$(diff -qr --exclude=.git docs $tmp_dir || true) # diff returns -1 if there are differences, which exits the workflow |
| 85 | + if [ "$files_modified" != "" ]; then |
| 86 | +
|
| 87 | + debug "Syncing contents of Wiki to repository dir docs" |
| 88 | + rsync -avzr --delete --exclude='.git/' "$tmp_dir/" "docs" |
| 89 | +
|
| 90 | + debug "Committing and pushing changes" |
| 91 | + ( |
| 92 | + git config user.name "${{ env.THIRD_PARTY_GIT_AUTHOR_NAME }}" |
| 93 | + git config user.email "${{ env.THIRD_PARTY_GIT_AUTHOR_EMAIL }}" |
| 94 | + |
| 95 | + # master could have been modified, so pull before pushing |
| 96 | + git pull --ff-only origin master |
| 97 | + |
| 98 | + git add . |
| 99 | + git commit -m "$WIKI_COMMIT_MESSAGE" |
| 100 | + git push origin master |
| 101 | + ) |
| 102 | + else |
| 103 | + warning "No file diff between wiki and docs. Exiting." |
| 104 | + fi |
| 105 | + rm -rf "$tmp_dir" |
| 106 | + debug "Finished - Wiki synced to docs dir" |
| 107 | + exit 0 |
| 108 | +
|
| 109 | + job-sync-docs-to-wiki: |
| 110 | + runs-on: ubuntu-latest |
| 111 | + if: github.event_name != 'gollum' |
| 112 | + env: |
| 113 | + GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.NEWRELIC_BOT_TOKEN }} |
| 114 | + steps: |
| 115 | + - name: Checkout Repo |
| 116 | + uses: actions/checkout@v2 |
| 117 | + - name: Sync docs to wiki |
| 118 | + run: | |
| 119 | + function debug() { |
| 120 | + echo "$1" |
| 121 | + } |
| 122 | +
|
| 123 | + function warning() { |
| 124 | + echo "::warning::$1" |
| 125 | + } |
| 126 | +
|
| 127 | + function error() { |
| 128 | + echo "::error::$1" |
| 129 | + } |
| 130 | +
|
| 131 | + function add_mask() { |
| 132 | + echo "::add-mask::$1" |
| 133 | + } |
| 134 | +
|
| 135 | + # check that vars are set |
| 136 | + if [ -z "$GITHUB_ACTOR" ]; then |
| 137 | + error "GITHUB_ACTOR environment variable is not set" |
| 138 | + exit 1 |
| 139 | + fi |
| 140 | +
|
| 141 | + if [ -z "$GITHUB_REPOSITORY" ]; then |
| 142 | + error "GITHUB_REPOSITORY environment variable is not set" |
| 143 | + exit 1 |
| 144 | + fi |
| 145 | +
|
| 146 | + if [ -z "$GH_PERSONAL_ACCESS_TOKEN" ]; then |
| 147 | + error "GH_PERSONAL_ACCESS_TOKEN environment variable is not set" |
| 148 | + exit 1 |
| 149 | + fi |
| 150 | +
|
| 151 | + add_mask "${GH_PERSONAL_ACCESS_TOKEN}" |
| 152 | +
|
| 153 | + if [ -z "${WIKI_COMMIT_MESSAGE:-}" ]; then |
| 154 | + debug "WIKI_COMMIT_MESSAGE not set, using default" |
| 155 | + WIKI_COMMIT_MESSAGE='chore(docs): Sync docs to wiki [skip ci]' |
| 156 | + fi |
| 157 | +
|
| 158 | + GIT_REPOSITORY_URL="https://${GH_PERSONAL_ACCESS_TOKEN}@github.com/$GITHUB_REPOSITORY.wiki.git" |
| 159 | +
|
| 160 | + debug "Checking out wiki repository" |
| 161 | + tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) |
| 162 | + ( |
| 163 | + cd "$tmp_dir" || exit 1 |
| 164 | + git init |
| 165 | + git config user.name "${{ env.THIRD_PARTY_GIT_AUTHOR_NAME }}" |
| 166 | + git config user.email "${{ env.THIRD_PARTY_GIT_AUTHOR_EMAIL }}" |
| 167 | + git pull "$GIT_REPOSITORY_URL" |
| 168 | + ) |
| 169 | +
|
| 170 | + debug "diffing files" |
| 171 | + files_modified=$(diff -qr --exclude=.git docs $tmp_dir || true) # diff returns -1 if there are differences, which exits the workflow |
| 172 | + if [ "$files_modified" != "" ]; then |
| 173 | +
|
| 174 | + debug "Syncing contents of docs to wiki repository" |
| 175 | + rsync -avzr --delete --exclude='.git/' "docs/" "$tmp_dir" |
| 176 | +
|
| 177 | + debug "Committing and pushing changes" |
| 178 | + ( |
| 179 | + cd "$tmp_dir" || exit 1 |
| 180 | + git add . |
| 181 | + git commit -m "$WIKI_COMMIT_MESSAGE" |
| 182 | + git push --set-upstream "$GIT_REPOSITORY_URL" master |
| 183 | + ) |
| 184 | + else |
| 185 | + warning "No file diff between docs and wiki. Exiting." |
| 186 | + fi |
| 187 | +
|
| 188 | + rm -rf "$tmp_dir" |
| 189 | + debug "Finished - Wiki synced to docs dir" |
| 190 | + exit 0 |
0 commit comments