name: prettier on: pull_request: branches: - main - jarred/test-actions # Allows you to run this workflow manually from the Actions tab workflow_dispatch: jobs: prettier-fmt: name: prettier runs-on: ubuntu-latest outputs: prettier_fmt_errs: ${{ steps.fmt.outputs.prettier_fmt_errs }} steps: - uses: actions/checkout@v3 with: submodules: recursive - id: setup name: Setup uses: oven-sh/setup-bun@v1 with: bun-version: latest - id: install name: Install prettier run: bun install - name: Run prettier id: fmt run: | rm -f .failed bun prettier --check "./bench/**/*.{ts,tsx,js,jsx,mjs}" "./test/**/*.{ts,tsx,js,jsx,mjs}" "./src/**/*.{ts,tsx,js,jsx}" --config .prettierrc.cjs 2> prettier-fmt.err > prettier-fmt1.err || echo 'failed' > .failed if [ -s .failed ]; then delimiter="$(openssl rand -hex 8)" echo "prettier_fmt_errs<<${delimiter}" >> "${GITHUB_OUTPUT}" cat prettier-fmt.err >> "${GITHUB_OUTPUT}" cat prettier-fmt1.err >> "${GITHUB_OUTPUT}" echo "${delimiter}" >> "${GITHUB_OUTPUT}" fi - name: Comment on PR if: steps.fmt.outputs.prettier_fmt_errs != '' uses: thollander/actions-comment-pull-request@v2 with: comment_tag: prettier-fmt message: | ❌ @${{ github.actor }} `prettier` reported errors ```js ${{ steps.fmt.outputs.prettier_fmt_errs }} ``` To one-off fix this manually, run: ```sh bun fmt ``` You might need to run `bun install` locally and configure your text editor to [auto-format on save](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode). [#${{github.sha}}](https://github.com/oven-sh/bun/commits/${{github.sha}}) - name: Uncomment on PR if: steps.fmt.outputs.prettier_fmt_errs == '' uses: thollander/actions-comment-pull-request@v2 with: comment_tag: prettier-fmt mode: upsert create_if_not_exists: false message: | ✅ `prettier` errors have been resolved. Thank you. [#${{github.sha}}](https://github.com/oven-sh/bun/commits/${{github.sha}}) - name: Fail the job if: steps.fmt.outputs.prettier_fmt_errs != '' run: exit 1