diff --git a/.github/workflows/format-pr.yml b/.github/workflows/format-pr.yml new file mode 100644 index 0000000000..653bbf8e62 --- /dev/null +++ b/.github/workflows/format-pr.yml @@ -0,0 +1,43 @@ +name: Format pull request + +on: + workflow_dispatch: + issue_comment: + types: [created] + +jobs: + format: + runs-on: ubuntu-latest + + if: | + github.event_name == 'workflow_dispatch' || ( + github.event_name == 'issue_comment' && + github.event.issue.pull_request && + contains(github.event.comment.body, '!format') + ) + + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + # Credentials needed for pushing changes at the end + persist-credentials: true + - name: Install Node.js + uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af + with: + node-version: 20.x + - name: Install dependencies + run: npm ci + - name: Format + run: npm run format + - name: Commit + run: | + git config --global user.name "$GITHUB_ACTOR" + git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" + git stage . + git commit --author "format-pr-bot " -m "[Automated] Format code" || echo "No changes to commit" + - name: Push + run: git push