From 28881e45a1ea0b433f1f5fb3acd2aff2ff35b954 Mon Sep 17 00:00:00 2001 From: StarManTheGamer <68450308+StarManTheGamer@users.noreply.github.com> Date: Mon, 27 May 2024 16:52:48 -0500 Subject: [PATCH] prettier automatically work --- .github/workflows/prettier.yml | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/prettier.yml diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000..98772d8 --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,51 @@ +name: Prettier Format and Commit + +on: + push: + branches: + - main + - 'refs/heads/*' + +jobs: + prettier: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 'latest' + + - name: Install dependencies + run: npm install + + - name: Pull latest changes + run: git pull + + - name: Run Prettier + run: npx prettier --write . + + - name: Commit changes + id: commit + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add . + if git diff-index --quiet HEAD; then + echo "No changes to commit." + echo "changes_committed=false" >> $GITHUB_ENV + else + git commit -m "chore: format code with Prettier" + echo "changes_committed=true" >> $GITHUB_ENV + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Push changes + if: env.changes_committed == 'true' + run: git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}