New docs - ChunYen-Chen/CheckNode GitHub Wiki

How to create a bi-directional updated wiki

Before getting started, I recommend you have some basic knowledge of repository, branch, fork, action, and workflow.

The following is the outline of this document:

Setup the original repository

  1. Create directory

    • Create a directory called wiki_docs to store the wiki documents.

    NOTE: The documents are stored under the directory wiki_docs by default. If you want to store the documents under your preference directory, please replace all the wiki_docs in sync-doc-to-wiki.yml and sync-wiki-to-doc.yml with your preference directory name.

  2. Copy sync-doc-to-wiki.yml and sync-wiki-to-doc.yml

    • Copy sync-doc-to-wiki.yml and sync-wiki-to-doc.yml under .github/workflows.

    sync-doc-to-wiki.yml

    name: Sync doc to wiki
    
    on:
      workflow_dispatch:
    
    env:
      GIT_AUTHOR_NAME: Actionbot
      GIT_AUTHOR_EMAIL: [email protected]
    
    jobs:
      job-sync-docs-to-wiki:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout Repo
            uses: actions/checkout@v2
          - name: Sync docs to wiki
            uses: newrelic/wiki-sync-action@main
            with:
              source: wiki_docs
              destination: wiki
              token: ${{ secrets.TOKEN_FOR_WIKI }}
              gitAuthorName: ${{ env.GIT_AUTHOR_NAME }}
              gitAuthorEmail: ${{ env.GIT_AUTHOR_EMAIL }}
    

    sync-wiki-to-doc.yml

    name: Sync wiki to doc
    
    on:
      workflow_dispatch:
    
    env:
      GIT_AUTHOR_NAME: Actionbot
      GIT_AUTHOR_EMAIL: [email protected]
    
    jobs:
      job-sync-wiki-to-docs:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout Repo
            uses: actions/checkout@v2
            with:
              token: ${{ secrets.TOKEN_FOR_WIKI }} # allows us to push back to repo
              ref: ${{ github.ref_name }}
          - name: Sync Wiki to Docs
            uses: newrelic/wiki-sync-action@main
            with:
              source: wiki
              destination: wiki_docs
              token: ${{ secrets.TOKEN_FOR_WIKI }}
              gitAuthorName: ${{ env.GIT_AUTHOR_NAME }}
              gitAuthorEmail: ${{ env.GIT_AUTHOR_EMAIL }}
              branch: ${{ github.ref_name }}
    
  3. Create a token for the action bot

    • Go to Setting of your account > Developer setting > Personal access tokens > Generate new token
    • Please check the repo and the workflow options.
    • You might want to set the Expiration to No expiration.

    image

  4. Create a repository secret token

    • Go to Setting of the repository > Security > Secrets and variables > Actions > Repository secrets

    image

    • Click New repository secrets, then you will see the following. Please replace <your personal access token> to your token at Secret.
  5. Congratulations :tada:

    • You finish the setup of the bi-directional updated wiki!

Setup forked repository

  1. Fork the repository

    • Fork the original repository.

    image

  2. Create first page

    • Click the Wiki page and create the first page

    image

  3. Create a token for the action bot

    • Setting of your account > Developer setting > Personal access tokens > Generate new token
    • Please check the repo and the workflow options.

    image

    • Remember to save the token since it will only be shown once!
  4. Create a repository secret token

    • Go to Setting of the repository > Security > Secrets and variables > Actions > Repository secrets

    image

    • Click New repository secrets, and then you will see the following. Please replace <your personal access token> to your token at Secret.
  5. Enable actions

    • Enable workflows to run in the forked repository.
    • Click Actions > click the green button. image
  6. Initialize wiki

    • Click Action > Workflows > Sync doc to wiki > Run workflow > choose Branch: master > Click green Run workflow. Once the workflow is done, the wiki is also updated to the master version.
  7. Congratulations :tada:

    • You finish the setup of the bi-directional updated wiki at the forked repository!

How to use it

We treat the wiki page on GitHub as a local in this method, and we use the workflow to approach the pull and push behavior of the wiki.

Change the wiki to the specific branch version

  • Click Action > Workflows > Sync doc to wiki > Run workflow > choose the specific branch > Click green Run workflow. Once the workflow is done, the wiki is also updated to the specific branch version.

Update the wiki content to the specific branch

  • Click Action > Workflows > Sync wiki to doc > Run workflow > choose the specific branch > Click green Run workflow. Once the workflow is done, the docs in the specific branch are updated to the latest wiki.

Reference

  1. Bi-directional Wiki Sync Action
  2. Create Pull Requests For Your GitHub Wiki