name: Code Formatting on: push: branches: [ main, master ] pull_request: branches: [ main, master ] # Allow manual triggering workflow_dispatch: jobs: format: runs-on: ubuntu-latest permissions: # Give the default GITHUB_TOKEN write permission to commit and push contents: write steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ github.token }} - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Install Biome run: npm install --global @biomejs/biome - name: Format with Biome run: biome format --write . - name: Check for changes id: git-check run: | git diff --quiet || echo "changes=true" >> $GITHUB_OUTPUT - name: Configure Git if: steps.git-check.outputs.changes == 'true' run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" - name: Commit and push changes if: steps.git-check.outputs.changes == 'true' run: | branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} echo "Current branch: $branch_name" git add -A git status git commit -m "chore: format code" git push origin HEAD:$branch_name