Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Refactor commit and push steps of 'format-fix' workflow #37580

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions .github/workflows/format-fix-command.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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"