|
| 1 | +name: Regenerate README file |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + paths-ignore: |
| 9 | + - 'features/**' |
| 10 | + - 'README.md' |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + regenerate-readme: #---------------------------------------------------------- |
| 15 | + name: Regenerate README.md file |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: ${{ ! contains(fromJson('[".github", "wp-cli", "php-cli-tools", "wp-config-transformer"]'), github.event.repository.name) }} |
| 18 | + steps: |
| 19 | + - name: Check out source code |
| 20 | + uses: actions/checkout@v2 |
| 21 | + |
| 22 | + - name: Set up PHP envirnoment |
| 23 | + uses: shivammathur/setup-php@v2 |
| 24 | + with: |
| 25 | + php-version: '7.4' |
| 26 | + |
| 27 | + - name: Check existence of composer.json file |
| 28 | + id: check_composer_file |
| 29 | + uses: andstor/file-existence-action@v1 |
| 30 | + with: |
| 31 | + files: "composer.json" |
| 32 | + |
| 33 | + - name: Get Composer cache directory |
| 34 | + if: steps.check_composer_file.outputs.files_exists == 'true' |
| 35 | + id: composer-cache |
| 36 | + run: | |
| 37 | + echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 38 | +
|
| 39 | + - name: Use Composer cache |
| 40 | + if: steps.check_composer_file.outputs.files_exists == 'true' |
| 41 | + uses: actions/cache@v1 |
| 42 | + with: |
| 43 | + path: ${{ steps['composer-cache'].outputs.dir }} |
| 44 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-composer- |
| 47 | +
|
| 48 | + - name: Install dependencies |
| 49 | + if: steps.check_composer_file.outputs.files_exists == 'true' |
| 50 | + run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest |
| 51 | + |
| 52 | + - name: Configure git user |
| 53 | + run: | |
| 54 | + git config --global user.email "alain.schlesser@gmail.com" |
| 55 | + git config --global user.name "Alain Schlesser" |
| 56 | +
|
| 57 | + - name: Check if remote branch exists |
| 58 | + id: remote-branch |
| 59 | + run: echo ::set-output name=exists::$([[ -z $(git ls-remote --heads origin regenerate-readme) ]] && echo "0" || echo "1") |
| 60 | + |
| 61 | + - name: Create branch to base pull request on |
| 62 | + if: steps.remote-branch.outputs.exists == 0 |
| 63 | + run: | |
| 64 | + git checkout -b regenerate-readme |
| 65 | +
|
| 66 | + - name: Fetch existing branch to add commits to |
| 67 | + if: steps.remote-branch.outputs.exists == 1 |
| 68 | + run: | |
| 69 | + git fetch --all --prune |
| 70 | + git checkout regenerate-readme |
| 71 | + git pull --no-rebase |
| 72 | +
|
| 73 | + - name: Install WP-CLI |
| 74 | + run: | |
| 75 | + curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar |
| 76 | + sudo mv wp-cli-nightly.phar /usr/local/bin/wp |
| 77 | + sudo chmod +x /usr/local/bin/wp |
| 78 | +
|
| 79 | + - name: Regenerate README.md file |
| 80 | + run: | |
| 81 | + wp package install "wp-cli/scaffold-package-command:^2" |
| 82 | + wp scaffold package-readme --force . |
| 83 | +
|
| 84 | + - name: Check if there are changes |
| 85 | + id: changes |
| 86 | + run: echo ::set-output name=changed::$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1") |
| 87 | + |
| 88 | + - name: Commit changes |
| 89 | + if: steps.changes.outputs.changed == 1 |
| 90 | + run: | |
| 91 | + git add README.md |
| 92 | + git commit -m "Regenerate README file - $(date +'%Y-%m-%d')" |
| 93 | + git push origin regenerate-readme |
| 94 | +
|
| 95 | + - name: Create pull request |
| 96 | + if: | |
| 97 | + steps.changes.outputs.changed == 1 && |
| 98 | + steps.remote-branch.outputs.exists == 0 |
| 99 | + uses: repo-sync/pull-request@v2 |
| 100 | + with: |
| 101 | + source_branch: regenerate-readme |
| 102 | + destination_branch: master |
| 103 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + pr_title: Regenerate README file |
| 105 | + pr_body: "**This is an automated pull-request**\n\nRefreshes the `README.md` file with the latest changes to the docblocks in the source code." |
| 106 | + pr_reviewer: schlessera |
| 107 | + pr_label: scope:documentation |
0 commit comments