Skip to content

Commit 00a7869

Browse files
committed
Incorporate from #53
1 parent e9794f2 commit 00a7869

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,18 @@ jobs:
5252
git config --global user.name "Alain Schlesser"
5353
5454
- name: Check if remote branch exists
55-
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin regenerate-readme) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
55+
id: check_remote_branch
56+
run: >
57+
echo "exists=$(git ls-remote --exit-code --heads origin regenerate-readme &>/dev/null
58+
&& echo "true" || echo "false")" >>"${GITHUB_OUTPUT}"
5659
5760
- name: Create branch to base pull request on
58-
if: env.REMOTE_BRANCH_EXISTS == 0
61+
if: ${{ steps.check_remote_branch.outputs.exists == 'false' }}
5962
run: |
6063
git checkout -b regenerate-readme
6164
6265
- name: Fetch existing branch to add commits to
63-
if: env.REMOTE_BRANCH_EXISTS == 1
66+
if: ${{ steps.check_remote_branch.outputs.exists == 'true' }}
6467
run: |
6568
git fetch --all --prune
6669
git checkout regenerate-readme
@@ -78,25 +81,29 @@ jobs:
7881
wp scaffold package-readme --branch=${{ github.event.repository.default_branch }} --force .
7982
8083
- name: Check if there are changes
81-
run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
84+
id: check_changes
85+
run: >
86+
echo "detected=$(test -n "$(git status --porcelain 2>/dev/null)"
87+
&& echo "true" || echo "false")" >>"${GITHUB_OUTPUT}"
8288
8389
- name: Commit changes
84-
if: env.CHANGES_DETECTED == 1
90+
if: ${{ steps.check_changes.outputs.detected == 'true' }}
8591
run: |
8692
git add README.md
8793
git commit -m "Regenerate README file - $(date +'%Y-%m-%d')"
8894
git push origin regenerate-readme
8995
9096
- name: Create pull request
91-
if: |
92-
env.CHANGES_DETECTED == 1 &&
93-
env.REMOTE_BRANCH_EXISTS == 0
97+
if: ${{ steps.check_changes.outputs.detected == 'true' && steps.check_remote_branch.outputs.exists == 'false' }}
9498
uses: repo-sync/pull-request@v2
9599
with:
96100
source_branch: regenerate-readme
97101
destination_branch: ${{ github.event.repository.default_branch }}
98102
github_token: ${{ secrets.GITHUB_TOKEN }}
99103
pr_title: Regenerate README file
100-
pr_body: "**This is an automated pull-request**\n\nRefreshes the `README.md` file with the latest changes to the docblocks in the source code."
104+
pr_body: |
105+
**This is an automated pull-request**
106+
107+
Refreshes the `README.md` file with the latest changes to the docblocks in the source code.
101108
pr_reviewer: schlessera
102109
pr_label: scope:documentation

0 commit comments

Comments
 (0)