|
| 1 | +--- |
| 2 | +name: Docs/Wiki Sync |
| 3 | + |
| 4 | +# yamllint disable-line rule:truthy |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + - "docs/wiki/**" |
| 11 | + workflow_dispatch: {} |
| 12 | + |
| 13 | +env: |
| 14 | + wiki_source_repo: "${{ github.repository }}" |
| 15 | + wiki_source_repo_dir: "${{ github.repository }}/docs/wiki" |
| 16 | + wiki_target_repo: "${{ github.repository }}.wiki" |
| 17 | + github_user_name: "github-actions" |
| 18 | + github_email: "41898282+github-actions[bot]@users.noreply.github.com" |
| 19 | + github_commit_message: "GitHub Action syncing wiki from docs/wiki" |
| 20 | + |
| 21 | +jobs: |
| 22 | + sync-wiki: |
| 23 | + name: Sync docs/wiki to Wiki |
| 24 | + if: github.repository == 'Azure/Azure2AzureTK' || github.event_name == 'workflow_dispatch' |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout Source Repo |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + repository: ${{ env.wiki_source_repo }} |
| 34 | + path: ${{ env.wiki_source_repo }} |
| 35 | + |
| 36 | + - name: Checkout Wiki Repo |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + repository: ${{ env.wiki_target_repo }} |
| 40 | + path: ${{ env.wiki_target_repo }} |
| 41 | + |
| 42 | + - name: Configure Local Git |
| 43 | + run: | |
| 44 | + git config --global user.name $github_user_name |
| 45 | + git config --global user.email $github_email |
| 46 | + working-directory: ${{ env.GITHUB_WORKSPACE }} |
| 47 | + |
| 48 | + - name: Sync docs/wiki Into Wiki Repo |
| 49 | + run: | |
| 50 | + rsync -avzr --delete --exclude='.git/' "$wiki_source_repo_dir/" "$wiki_target_repo" |
| 51 | + working-directory: ${{ env.GITHUB_WORKSPACE }} |
| 52 | + |
| 53 | + - name: Check for changes |
| 54 | + id: git_status |
| 55 | + run: | |
| 56 | + mapfile -t CHECK_GIT_STATUS < <(git status -s) |
| 57 | + printf "%s\n" "${CHECK_GIT_STATUS[@]}" |
| 58 | + echo "changes=${#CHECK_GIT_STATUS[@]}" >> $GITHUB_OUTPUT |
| 59 | + working-directory: ${{ env.wiki_target_repo }} |
| 60 | + |
| 61 | + - name: Add files, commit and push into Wiki |
| 62 | + if: steps.git_status.outputs.changes > 0 |
| 63 | + run: | |
| 64 | + echo "Pushing changes to origin..." |
| 65 | + git add . |
| 66 | + git commit -m "$github_commit_message [$GITHUB_ACTOR/${GITHUB_SHA::8}]" |
| 67 | + git push --set-upstream https://$GITHUB_TOKEN@github.com/$wiki_target_repo.git master |
| 68 | + working-directory: ${{ env.wiki_target_repo }} |
0 commit comments