Skip to content

Commit

Permalink
CI: Refactor commit and push steps of 'format-fix' workflow (#37580)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsteers authored Apr 25, 2024
1 parent 5629bb9 commit 0de1b48
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions .github/workflows/format-fix-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
required: false

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

# - name: Checkout PR (${{ github.event.inputs.pr }})
# uses: dawidd6/action-checkout-pr@v1
# with:
# pr: ${{ github.event.inputs.pr }}

- name: Append comment with job run link
# If not comment-id is provided, this will create a new
# If comment-id is not provided, this will create a new
# comment with the job run link.
id: first-comment-action
uses: peter-evans/create-or-update-comment@v4
Expand Down Expand Up @@ -89,29 +84,44 @@ jobs:
- name: Remove any files that have been gitignored
run: git ls-files -i -c --exclude-from=.gitignore | xargs -r git rm --cached

- name: Commit Formatting Changes (PR)
# Check for changes in git

- name: Check for changes
id: git-diff
run: |
git diff --quiet && echo "No changes to commit" || echo "::set-output name=changes::true"
shell: bash

# Commit changes (if any)

- name: Commit changes
id: commit-step
uses: stefanzweifel/git-auto-commit-action@v5
# Don't commit if we're on master
if: github.ref != 'refs/heads/master'
with:
repository: ${{ steps.job-vars.outputs.repo }}
commit_message: "chore: format code"
commit_user_name: Octavia Squidington III
commit_user_email: octavia-squidington-iii@users.noreply.github.com
if: steps.git-diff.outputs.changes == 'true'
run: |
git config --global user.name "Octavia Squidington III"
git config --global user.email "octavia-squidington-iii@users.noreply.github.com"
git add .
git commit -m "chore: auto-fix lint and format issues"
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Push changes to '(${{ steps.job-vars.outputs.repo }})'
if: steps.git-diff.outputs.changes == 'true'
run: |
git remote add contributor https://github.com/${{ steps.job-vars.outputs.repo }}.git
git push contributor HEAD:${{ steps.job-vars.outputs.branch }}
- name: Append success comment
uses: peter-evans/create-or-update-comment@v4
if: steps.commit-step.outputs.changes_detected == 'true'
if: steps.git-diff.outputs.changes == 'true'
with:
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
reactions: hooray
body: |
> ✅ Changes applied successfully. (${{ steps.commit-step.outputs.commit_hash }})
> ✅ Changes applied successfully. (${{ steps.commit-step.outputs.sha }})
- name: Append success comment (no-op)
uses: peter-evans/create-or-update-comment@v4
if: steps.commit-step.outputs.changes_detected != 'true'
if: steps.git-diff.outputs.changes != 'true'
with:
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
reactions: "+1"
Expand Down

0 comments on commit 0de1b48

Please sign in to comment.