|
| 1 | +# This workflow will publish all of the documents stored under ./github/wiki directory |
| 2 | +# to Github Wiki of the given repository. |
| 3 | +# |
| 4 | +# To use this workflow, please follow these steps |
| 5 | +# - Setup the Github Wiki by following this official guide |
| 6 | +# https://docs.github.com/en/communities/documenting-your-project-with-wikis/adding-or-editing-wiki-pages#adding-wiki-pages |
| 7 | +# - Create Personal Access Token with `repo` scope enabled - a bot account is recommended to generate that token |
| 8 | +# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token |
| 9 | +# - Create a Repository Secret for the above token, e.g. name it as GH_ACTION_TOKEN |
| 10 | +# - Define your own workflow and provide the required inputs & secret, here is an example workflow: |
| 11 | +# |
| 12 | +# name: Publish Wiki |
| 13 | +# |
| 14 | +# on: |
| 15 | +# push: |
| 16 | +# branches: |
| 17 | +# - develop |
| 18 | +# paths: |
| 19 | +# - .github/wiki/** |
| 20 | +# |
| 21 | +# jobs: |
| 22 | +# publish: |
| 23 | +# name: Publish Wiki |
| 24 | +# uses: nimblehq/github-actions-workflows/.github/workflows/[email protected] |
| 25 | +# with: |
| 26 | +# USER_NAME: github-wiki-action |
| 27 | + |
| 28 | +# secrets: |
| 29 | +# USER_TOKEN: ${{ secrets.GH_ACTION_TOKEN }} |
| 30 | + |
| 31 | +name: Publish Wiki |
| 32 | + |
| 33 | +on: |
| 34 | + workflow_call: |
| 35 | + inputs: |
| 36 | + # The username of a Github (bot) account |
| 37 | + USER_NAME: |
| 38 | + required: true |
| 39 | + type: string |
| 40 | + # The e-mail of a Github (bot) account |
| 41 | + USER_EMAIL: |
| 42 | + required: true |
| 43 | + type: string |
| 44 | + secrets: |
| 45 | + # The Personal Access Token of a Github (bot) account |
| 46 | + USER_TOKEN: |
| 47 | + required: true |
| 48 | + |
| 49 | +env: |
| 50 | + USER_NAME: ${{ inputs.USER_NAME }} |
| 51 | + USER_EMAIL: ${{ inputs.USER_EMAIL }} |
| 52 | + USER_TOKEN: ${{ secrets.USER_TOKEN }} |
| 53 | + REPOSITORY: ${{ github.repository }} |
| 54 | + WIKI_FOLDER: .github/wiki |
| 55 | + TEMP_CLONE_WIKI_FOLDER: tmp_wiki |
| 56 | + |
| 57 | +jobs: |
| 58 | + publish: |
| 59 | + name: Publish Github Wiki |
| 60 | + runs-on: ubuntu-latest |
| 61 | + timeout-minutes: 1 |
| 62 | + |
| 63 | + steps: |
| 64 | + - name: Cancel previous runs |
| 65 | + |
| 66 | + with: |
| 67 | + access_token: ${{ github.token }} |
| 68 | + |
| 69 | + - name: Checkout the repository |
| 70 | + uses: actions/checkout@v2 |
| 71 | + with: |
| 72 | + ref: ${{ github.head_ref }} |
| 73 | + |
| 74 | + # This step will |
| 75 | + # - Create folder named `tmp_wiki` |
| 76 | + # - Initialize Git |
| 77 | + # - Pull old Wiki content |
| 78 | + - name: Pull current wiki content |
| 79 | + run: | |
| 80 | + mkdir $TEMP_CLONE_WIKI_FOLDER |
| 81 | + cd $TEMP_CLONE_WIKI_FOLDER |
| 82 | + git init |
| 83 | + git config user.name $USER_NAME |
| 84 | + git config user.email $USER_EMAIL |
| 85 | + git pull https://[email protected]/$REPOSITORY.wiki.git |
| 86 | +
|
| 87 | + # This step will |
| 88 | + # - Synchronize differences between `.github/wiki/` & `tmp_wiki` |
| 89 | + # - Push new Wiki content |
| 90 | + - name: Push new wiki content |
| 91 | + run: | |
| 92 | + rsync -av --delete $WIKI_FOLDER/ $TEMP_CLONE_WIKI_FOLDER/ --exclude .git |
| 93 | + cd $TEMP_CLONE_WIKI_FOLDER |
| 94 | + git add . |
| 95 | + git commit -m "Update Wiki content" |
| 96 | + git push -f --set-upstream https://[email protected]/$REPOSITORY.wiki.git master |
0 commit comments