Skip to content

Commit 3f5436f

Browse files
authored
Merge pull request #611 from wp-cli/add/handbook-prs
2 parents 6a2c746 + 70c5818 commit 3f5436f

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

.github/workflows/regenerate-handbook.yml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ jobs:
1616
- name: Check out source code
1717
uses: actions/checkout@v6
1818

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+
1934
- name: Set up PHP environment
2035
uses: shivammathur/setup-php@v2
2136
with:
@@ -49,19 +64,29 @@ jobs:
4964
- name: Generate handbook
5065
run: WP_CLI_PACKAGES_DIR=bin/packages WP_CLI_CONFIG_PATH=/dev/null wp handbook gen-all
5166

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
5670

5771
- name: Commit changes
58-
if: steps.changes.outputs.has_changes == 'true'
72+
if: env.CHANGES_DETECTED == 1
5973
run: |
6074
git config user.name "github-actions[bot]"
6175
git config user.email "github-actions[bot]@users.noreply.github.com"
6276
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
6479
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

Comments
 (0)