Skip to content

Commit 0de1b48

Browse files
authored
CI: Refactor commit and push steps of 'format-fix' workflow (#37580)
1 parent 5629bb9 commit 0de1b48

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

.github/workflows/format-fix-command.yml

+29-19
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
required: false
1313

1414
# These must be declared, but they are unused and ignored.
15-
# TODO: Get 'repo' and 'gitref' from the PR on other workflows, so we can remove these.
15+
# TODO: Infer 'repo' and 'gitref' from PR number on other workflows, so we can remove these.
1616
repo:
1717
description: "Repo (Ignored)"
1818
required: false
@@ -53,13 +53,8 @@ jobs:
5353
# Without this we would be forever waiting on required checks to pass.
5454
token: ${{ secrets.GH_PAT_APPROVINGTON_OCTAVIA }}
5555

56-
# - name: Checkout PR (${{ github.event.inputs.pr }})
57-
# uses: dawidd6/action-checkout-pr@v1
58-
# with:
59-
# pr: ${{ github.event.inputs.pr }}
60-
6156
- name: Append comment with job run link
62-
# If not comment-id is provided, this will create a new
57+
# If comment-id is not provided, this will create a new
6358
# comment with the job run link.
6459
id: first-comment-action
6560
uses: peter-evans/create-or-update-comment@v4
@@ -89,29 +84,44 @@ jobs:
8984
- name: Remove any files that have been gitignored
9085
run: git ls-files -i -c --exclude-from=.gitignore | xargs -r git rm --cached
9186

92-
- name: Commit Formatting Changes (PR)
87+
# Check for changes in git
88+
89+
- name: Check for changes
90+
id: git-diff
91+
run: |
92+
git diff --quiet && echo "No changes to commit" || echo "::set-output name=changes::true"
93+
shell: bash
94+
95+
# Commit changes (if any)
96+
97+
- name: Commit changes
9398
id: commit-step
94-
uses: stefanzweifel/git-auto-commit-action@v5
95-
# Don't commit if we're on master
96-
if: github.ref != 'refs/heads/master'
97-
with:
98-
repository: ${{ steps.job-vars.outputs.repo }}
99-
commit_message: "chore: format code"
100-
commit_user_name: Octavia Squidington III
101-
commit_user_email: [email protected]
99+
if: steps.git-diff.outputs.changes == 'true'
100+
run: |
101+
git config --global user.name "Octavia Squidington III"
102+
git config --global user.email "[email protected]"
103+
git add .
104+
git commit -m "chore: auto-fix lint and format issues"
105+
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
106+
107+
- name: Push changes to '(${{ steps.job-vars.outputs.repo }})'
108+
if: steps.git-diff.outputs.changes == 'true'
109+
run: |
110+
git remote add contributor https://github.com/${{ steps.job-vars.outputs.repo }}.git
111+
git push contributor HEAD:${{ steps.job-vars.outputs.branch }}
102112
103113
- name: Append success comment
104114
uses: peter-evans/create-or-update-comment@v4
105-
if: steps.commit-step.outputs.changes_detected == 'true'
115+
if: steps.git-diff.outputs.changes == 'true'
106116
with:
107117
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
108118
reactions: hooray
109119
body: |
110-
> ✅ Changes applied successfully. (${{ steps.commit-step.outputs.commit_hash }})
120+
> ✅ Changes applied successfully. (${{ steps.commit-step.outputs.sha }})
111121
112122
- name: Append success comment (no-op)
113123
uses: peter-evans/create-or-update-comment@v4
114-
if: steps.commit-step.outputs.changes_detected != 'true'
124+
if: steps.git-diff.outputs.changes != 'true'
115125
with:
116126
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
117127
reactions: "+1"

0 commit comments

Comments
 (0)