Skip to content

Commit 8bfeff0

Browse files
committed
Use gh pr create instead of repo-sync/pull-request
1 parent 2a80663 commit 8bfeff0

1 file changed

Lines changed: 34 additions & 68 deletions

File tree

.github/workflows/regenerate-handbook.yml

Lines changed: 34 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,79 +15,45 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Check out source code
18-
uses: actions/checkout@v6
18+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
1919

20-
- name: Check if remote branch exists
21-
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin update-handbook) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
22-
23-
- name: Create branch to base pull request on
24-
if: env.REMOTE_BRANCH_EXISTS == 0
25-
run: |
26-
git checkout -b update-handbook
27-
28-
- name: Fetch existing branch to add commits to
29-
if: env.REMOTE_BRANCH_EXISTS == 1
30-
run: |
31-
git fetch --all --prune
32-
git checkout update-handbook
33-
git pull --no-rebase
34-
35-
- name: Set up PHP environment
36-
uses: shivammathur/setup-php@v2
37-
with:
38-
php-version: 'latest'
39-
coverage: 'none'
40-
env:
41-
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
- name: Generate handbook
21+
run: WP_CLI_PACKAGES_DIR=bin/packages WP_CLI_CONFIG_PATH=/dev/null wp handbook gen-all
4222

43-
- name: Install Composer dependencies & cache dependencies
44-
uses: "ramsey/composer-install@v4"
23+
- name: Commit and Create Pull Request
4524
env:
46-
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
47-
with:
48-
# Bust the cache at least once a month - output format: YYYY-MM.
49-
custom-cache-suffix: $(date -u "+%Y-%m")
25+
GH_TOKEN: ${{ github.token }}
26+
PR_BODY: |
27+
**This is an automated pull-request**
5028
51-
- name: Download WP-CLI nightly
29+
Updates the built Markdown pages with the latest changes.
5230
run: |
53-
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar
54-
chmod +x wp-cli-nightly.phar
55-
sudo mv wp-cli-nightly.phar /usr/local/bin/wp
31+
if [ -n "$(git status --porcelain)" ]; then
32+
git config user.name "github-actions[bot]"
33+
git config user.email "github-actions[bot]@users.noreply.github.com"
34+
git checkout -b update-handbook
35+
git add .
36+
git commit -m "Regenerate handbook"
37+
git push -f origin update-handbook
38+
39+
PR_NUMBER=$(gh pr list --head update-handbook --json number --jq '.[0].number // empty')
40+
if [ -z "$PR_NUMBER" ]; then
41+
gh pr create \
42+
--title "Update handbook" \
43+
--body "$PR_BODY" \
44+
--label "scope:distribution" \
45+
--base "${{ github.event.repository.default_branch }}" \
46+
--head "update-handbook" \
47+
--reviewer "swissspidy"
48+
else
49+
gh pr edit "$PR_NUMBER" \
50+
--title "Update handbook" \
51+
--body "$PR_BODY" \
52+
--add-label "scope:distribution" \
53+
--base "${{ github.event.repository.default_branch }}"
54+
fi
55+
56+
fi
5657
57-
- name: Verify WP-CLI installation
58-
run: wp --info
5958
60-
- name: Install non-bundled packages
61-
run: |
62-
chmod +x bin/install_packages.sh
63-
bash bin/install_packages.sh
64-
65-
- name: Generate handbook
66-
run: WP_CLI_PACKAGES_DIR=bin/packages WP_CLI_CONFIG_PATH=/dev/null wp handbook gen-all
67-
68-
69-
- name: Check if there are changes
70-
run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
71-
72-
- name: Commit changes
73-
if: env.CHANGES_DETECTED == 1
74-
run: |
75-
git config user.name "github-actions[bot]"
76-
git config user.email "github-actions[bot]@users.noreply.github.com"
77-
git add -A
78-
git commit -m "Regenerate handbook - $(date +'%Y-%m-%d')"
79-
git push origin update-handbook
8059
81-
- name: Create pull request
82-
if: |
83-
env.CHANGES_DETECTED == 1 &&
84-
env.REMOTE_BRANCH_EXISTS == 0
85-
uses: repo-sync/pull-request@v2
86-
with:
87-
source_branch: update-handbook
88-
destination_branch: ${{ github.event.repository.default_branch }}
89-
github_token: ${{ secrets.GITHUB_TOKEN }}
90-
pr_title: Update handbook
91-
pr_body: "**This is an automated pull-request**\n\nUpdates the built Markdown pages with the latest changes."
92-
pr_reviewer: swissspidy
93-
pr_label: scope:distribution

0 commit comments

Comments
 (0)