Skip to content

Commit

Permalink
Add commit message to Prettier GH Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitrrine committed Dec 8, 2023
1 parent be3af17 commit a2d6ff5
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Prettier

on: [push, pull_request]
on:
push:
pull_request:

jobs:
prettier:
Expand All @@ -27,13 +29,26 @@ jobs:
- name: Install dependencies
run: npm install

- name: Check for changes
id: check_changes
run: |
if npx prettier --check .; then
echo "No changes"
echo "::set-output name=result::No changes"
else
echo "Changes detected"
echo "::set-output name=result::Changes detected"
fi
- name: Format code
run: npx prettier --write .
if: steps.check_changes.outputs.result == 'Changes detected'
run: npx prettier --write . || echo "Prettier encountered errors."

- name: Commit and push changes
if: steps.check_changes.outputs.result == 'Changes detected'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add .
git commit -m "Format code with Prettier"
git commit -m "${{ github.event.head_commit.message }} (Formatted code with Prettier)"
git push

0 comments on commit a2d6ff5

Please sign in to comment.