Skip to content

Commit 187d77c

Browse files
committed
Use gh pr create for reusable workflows
1 parent ce71638 commit 187d77c

2 files changed

Lines changed: 60 additions & 27 deletions

File tree

.github/workflows/reusable-check-branch-alias.yml

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
with:
3232
fetch-depth: 0 # Fetch all history for all tags
3333
token: ${{ secrets.GITHUB_TOKEN }}
34-
persist-credentials: false
3534

3635
- name: Set up PHP
3736
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
@@ -131,23 +130,40 @@ jobs:
131130
STEPS_CHECK_ALIAS_OUTPUTS_BRANCH_KEY: ${{ steps.check_alias.outputs.branch_key }}
132131
STEPS_CHECK_ALIAS_OUTPUTS_EXPECTED_ALIAS: ${{ steps.check_alias.outputs.expected_alias }}
133132

134-
- name: Create Pull Request
133+
- name: Commit and Create Pull Request
135134
if: steps.check_alias.outputs.needs_update == 'true'
136-
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8
137-
with:
138-
token: ${{ secrets.GITHUB_TOKEN }}
139-
base: ${{ github.event.repository.default_branch }}
140-
commit-message: "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}"
141-
title: "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}"
142-
body: |
135+
env:
136+
GH_TOKEN: ${{ github.token }}
137+
PR_BODY: |
143138
This PR updates the Composer `branch-alias` configuration to reflect the latest release.
144-
139+
145140
- Latest release: ${{ steps.check_alias.outputs.latest_tag }}
146141
- Previous branch-alias: `${{ steps.check_alias.outputs.current_alias }}`
147142
- Updated branch-alias: `${{ steps.check_alias.outputs.expected_alias }}`
148-
143+
149144
The branch-alias should point to the major development version for the latest major release.
150-
branch: update-branch-alias
151-
delete-branch: true
152-
labels: |
153-
automated-pr
145+
run: |
146+
if [ -n "$(git status --porcelain)" ]; then
147+
git config user.name "github-actions[bot]"
148+
git config user.email "github-actions[bot]@users.noreply.github.com"
149+
git checkout -b update-branch-alias
150+
git add composer.json
151+
git commit -m "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}"
152+
git push -f origin update-branch-alias
153+
154+
PR_NUMBER=$(gh pr list --head update-branch-alias --json number --jq '.[0].number // empty')
155+
if [ -z "$PR_NUMBER" ]; then
156+
gh pr create \
157+
--title "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}" \
158+
--body "$PR_BODY" \
159+
--label "automated-pr" \
160+
--base "${{ github.event.repository.default_branch }}" \
161+
--head "update-branch-alias"
162+
else
163+
gh pr edit "$PR_NUMBER" \
164+
--title "Update branch-alias to ${{ steps.check_alias.outputs.expected_alias }}" \
165+
--body "$PR_BODY" \
166+
--add-label "automated-pr" \
167+
--base "${{ github.event.repository.default_branch }}"
168+
fi
169+
fi

.github/workflows/reusable-regenerate-readme.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ jobs:
2323
steps:
2424
- name: Check out source code
2525
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
26-
with:
27-
persist-credentials: false
2826

2927
- name: Set up PHP environment
3028
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
@@ -56,16 +54,35 @@ jobs:
5654
env:
5755
GITHUB_EVENT_REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
5856

59-
- name: Create pull request
60-
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8
61-
with:
62-
branch: regenerate-readme
63-
base: ${{ github.event.repository.default_branch }}
64-
token: ${{ secrets.GITHUB_TOKEN }}
65-
title: Regenerate README file
66-
body: |
57+
- name: Commit and Create Pull Request
58+
env:
59+
GH_TOKEN: ${{ github.token }}
60+
PR_BODY: |
6761
**This is an automated pull-request**
6862
6963
Refreshes the `README.md` file with the latest changes to the docblocks in the source code.
70-
labels: scope:documentation
71-
commit-message: "Regenerate README file"
64+
run: |
65+
if [ -n "$(git status --porcelain)" ]; then
66+
git config user.name "github-actions[bot]"
67+
git config user.email "github-actions[bot]@users.noreply.github.com"
68+
git checkout -b regenerate-readme
69+
git add README.md
70+
git commit -m "Regenerate README file"
71+
git push -f origin regenerate-readme
72+
73+
PR_NUMBER=$(gh pr list --head regenerate-readme --json number --jq '.[0].number // empty')
74+
if [ -z "$PR_NUMBER" ]; then
75+
gh pr create \
76+
--title "Regenerate README file" \
77+
--body "$PR_BODY" \
78+
--label "scope:documentation" \
79+
--base "${{ github.event.repository.default_branch }}" \
80+
--head "regenerate-readme"
81+
else
82+
gh pr edit "$PR_NUMBER" \
83+
--title "Regenerate README file" \
84+
--body "$PR_BODY" \
85+
--add-label "scope:documentation" \
86+
--base "${{ github.event.repository.default_branch }}"
87+
fi
88+
fi

0 commit comments

Comments
 (0)