|
16 | 16 | - name: Check out source code |
17 | 17 | uses: actions/checkout@v6 |
18 | 18 |
|
| 19 | + - name: Check if remote branch exists |
| 20 | + run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin update-handbook) ]] && echo "0" || echo "1")" >> $GITHUB_ENV |
| 21 | + |
| 22 | + - name: Create branch to base pull request on |
| 23 | + if: env.REMOTE_BRANCH_EXISTS == 0 |
| 24 | + run: | |
| 25 | + git checkout -b update-handbook |
| 26 | +
|
| 27 | + - name: Fetch existing branch to add commits to |
| 28 | + if: env.REMOTE_BRANCH_EXISTS == 1 |
| 29 | + run: | |
| 30 | + git fetch --all --prune |
| 31 | + git checkout update-handbook |
| 32 | + git pull --no-rebase |
| 33 | +
|
19 | 34 | - name: Set up PHP environment |
20 | 35 | uses: shivammathur/setup-php@v2 |
21 | 36 | with: |
@@ -49,19 +64,29 @@ jobs: |
49 | 64 | - name: Generate handbook |
50 | 65 | run: WP_CLI_PACKAGES_DIR=bin/packages WP_CLI_CONFIG_PATH=/dev/null wp handbook gen-all |
51 | 66 |
|
52 | | - - name: Check for changes |
53 | | - id: changes |
54 | | - run: | |
55 | | - git diff --exit-code --quiet HEAD || echo "has_changes=true" >> $GITHUB_OUTPUT |
| 67 | + |
| 68 | + - name: Check if there are changes |
| 69 | + run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV |
56 | 70 |
|
57 | 71 | - name: Commit changes |
58 | | - if: steps.changes.outputs.has_changes == 'true' |
| 72 | + if: env.CHANGES_DETECTED == 1 |
59 | 73 | run: | |
60 | 74 | git config user.name "github-actions[bot]" |
61 | 75 | git config user.email "github-actions[bot]@users.noreply.github.com" |
62 | 76 | git add -A |
63 | | - git commit -m "Regenerate handbook" |
| 77 | + git commit -m "Regenerate handbook - $(date +'%Y-%m-%d')" |
| 78 | + git push origin update-handbook |
64 | 79 |
|
65 | | - - name: Push changes |
66 | | - if: steps.changes.outputs.has_changes == 'true' |
67 | | - run: git push |
| 80 | + - name: Create pull request |
| 81 | + if: | |
| 82 | + env.CHANGES_DETECTED == 1 && |
| 83 | + env.REMOTE_BRANCH_EXISTS == 0 |
| 84 | + uses: repo-sync/pull-request@v2 |
| 85 | + with: |
| 86 | + source_branch: update-handbook |
| 87 | + destination_branch: ${{ github.event.repository.default_branch }} |
| 88 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + pr_title: Update handbook |
| 90 | + pr_body: "**This is an automated pull-request**\n\nUpdates the built Markdown pages with the latest changes." |
| 91 | + pr_reviewer: swissspidy |
| 92 | + pr_label: scope:distribution |
0 commit comments