Skip to content

Commit ecc6c4c

Browse files
authored
Use gh pr create for update-framework workflow (#1001)
1 parent ac6e284 commit ecc6c4c

1 file changed

Lines changed: 38 additions & 10 deletions

File tree

.github/workflows/update-framework.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ concurrency:
1515
group: ${{ github.workflow }}-${{ github.ref }}
1616
cancel-in-progress: true
1717

18+
permissions:
19+
contents: write
20+
pull-requests: write
1821

1922
jobs:
2023

@@ -25,6 +28,8 @@ jobs:
2528
steps:
2629
- name: Check out source code
2730
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
31+
with:
32+
token: ${{ secrets.ACTIONS_BOT }}
2833

2934
- name: Set up PHP environment
3035
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
@@ -50,13 +55,36 @@ jobs:
5055
run: |
5156
composer update wp-cli/wp-cli --with-all-dependencies
5257
53-
- name: Create pull request
54-
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8
55-
with:
56-
branch: update-framework
57-
base: ${{ github.event.repository.default_branch }}
58-
token: ${{ secrets.ACTIONS_BOT }}
59-
title: Update wp-cli framework
60-
body: "**This is an automated pull-request**\n\nUpdates the `wp-cli/wp-cli` framework to the latest changeset."
61-
labels: scope:framework
62-
commit-message: "Update wp-cli framework"
58+
- name: Commit and Create Pull Request
59+
env:
60+
GH_TOKEN: ${{ secrets.ACTIONS_BOT }}
61+
PR_BODY: |
62+
**This is an automated pull-request**
63+
64+
Updates the `wp-cli/wp-cli` framework to the latest changeset.
65+
run: |
66+
if [ -n "$(git status --porcelain)" ]; then
67+
git config user.name "github-actions[bot]"
68+
git config user.email "github-actions[bot]@users.noreply.github.com"
69+
git checkout -b update-framework
70+
git add composer.json composer.lock
71+
git commit -m "Update wp-cli framework"
72+
73+
git push -f origin update-framework
74+
75+
PR_NUMBER=$(gh pr list --head update-framework --json number --jq '.[0].number // empty')
76+
if [ -z "$PR_NUMBER" ]; then
77+
gh pr create \
78+
--title "Update wp-cli framework" \
79+
--body "$PR_BODY" \
80+
--label "scope:framework" \
81+
--base "${{ github.event.repository.default_branch }}" \
82+
--head "update-framework"
83+
else
84+
gh pr edit "$PR_NUMBER" \
85+
--title "Update wp-cli framework" \
86+
--body "$PR_BODY" \
87+
--add-label "scope:framework" \
88+
--base "${{ github.event.repository.default_branch }}"
89+
fi
90+
fi

0 commit comments

Comments
 (0)