|
| 1 | +name: Auto update project wiki |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + tags: |
| 8 | + - 'v*' # Initializes on any new tag |
| 9 | + |
| 10 | +jobs: |
| 11 | + update_wiki: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkouting main code |
| 15 | + uses: actions/checkout@v2 |
| 16 | + - name: Parsing git info |
| 17 | + run: | |
| 18 | + echo "::set-env name=LAST_COMMIT_AUTHOR_EMAIL::$(git show -s --format='%ae' HEAD)" |
| 19 | + echo "::set-env name=LAST_COMMIT_AUTHOR_NAME::$(git show -s --format='%an' HEAD)" |
| 20 | + BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) |
| 21 | + if [ "$BRANCH_NAME" == 'HEAD' ]; then |
| 22 | + BRANCH_NAME=$(git describe --tags --abbrev=0) |
| 23 | + fi; |
| 24 | + echo "::set-env name=BRANCH_NAME::$BRANCH_NAME" |
| 25 | + - name: Checking for required secrets |
| 26 | + run: | |
| 27 | + if [ -z "${{ secrets.WIKI_GITHUB_UPDATE_TOKEN }}" ]; then |
| 28 | + echo "Secret WIKI_GITHUB_UPDATE_TOKEN is missing. Use this link to create required token -> https://github.com/settings/tokens/new?scopes=repo&description=wiki%20api%20generator <- and than add to project secrets." |
| 29 | + exit 1 |
| 30 | + fi; |
| 31 | + if [ -z "${{ secrets.WIKI_GITHUB_UPDATE_USER }}" ]; then |
| 32 | + echo "Secret WIKI_GITHUB_UPDATE_USER is missing. Set this to username for who token belongs." |
| 33 | + exit 2 |
| 34 | + fi; |
| 35 | + - name: Cloning old wiki |
| 36 | + run: | |
| 37 | + mkdir .docs.old |
| 38 | + cd .docs.old |
| 39 | + git init |
| 40 | + git remote add origin https://${{ secrets.WIKI_GITHUB_UPDATE_USER }}:${{ secrets.WIKI_GITHUB_UPDATE_TOKEN }}@github.com/${{ github.repository }}.wiki.git |
| 41 | + git config --local gc.auto 0 |
| 42 | + git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin |
| 43 | + git checkout ${BRANCH_NAME} 2>/dev/null || git checkout -b ${BRANCH_NAME} |
| 44 | + git reset --hard |
| 45 | + cd .. |
| 46 | + - name: Installing hidden clean/phpdoc-md |
| 47 | + run: composer require --dev clean/phpdoc-md |
| 48 | + - name: Creating configuration |
| 49 | + run: | |
| 50 | + cat > .phpdoc-md <<EOF |
| 51 | + <?php |
| 52 | + return (object)[ |
| 53 | + 'rootNamespace' => 'Imponeer', |
| 54 | + 'destDirectory' => '.docs', |
| 55 | + 'format' => 'github', |
| 56 | + 'classes' => [ |
| 57 | + '\Imponeer\ToArrayInterface', |
| 58 | + ], |
| 59 | + ]; |
| 60 | + EOF |
| 61 | + - name: View config |
| 62 | + run: cat .phpdoc-md |
| 63 | + - name: Genereting docs... |
| 64 | + run: ./vendor/bin/phpdoc-md |
| 65 | + - name: Updating docs folder |
| 66 | + run: cp -r ./.docs.old/.git ./.docs/.git |
| 67 | + - name: Renaming README.md -> HOME.md |
| 68 | + working-directory: .docs/ |
| 69 | + run: mv README.md HOME.md |
| 70 | + - name: Adding extra info to HOME.md |
| 71 | + working-directory: .docs/ |
| 72 | + run: | |
| 73 | + sed -i '1i##### Notice: Wiki was automatic generated from project sources as project API documentation. Do not edit manually!' HOME.md |
| 74 | + sed -i "2i\ " HOME.md |
| 75 | + - name: Configuring commit author |
| 76 | + working-directory: .docs/ |
| 77 | + run: | |
| 78 | + git config --local user.email "$LAST_COMMIT_AUTHOR_EMAIL" |
| 79 | + git config --local user.name "$LAST_COMMIT_AUTHOR_NAME" |
| 80 | + - name: Checking what docs where updated |
| 81 | + working-directory: .docs/ |
| 82 | + run: git status |
| 83 | + - name: Commiting docs update |
| 84 | + working-directory: .docs/ |
| 85 | + run: | |
| 86 | + git add -u :/ |
| 87 | + git add . |
| 88 | + git commit -m "Automatically generated for https://github.com/${{ github.repository }}/commit/${GITHUB_SHA}" || true |
| 89 | + - name: Pushing docs update |
| 90 | + working-directory: .docs/ |
| 91 | + run: git push -u origin ${BRANCH_NAME} |
0 commit comments