adds prettier gh action #6
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Fix Formatting | |
on: | |
issue_comment: | |
types: | |
- created | |
pull_request: | |
types: | |
- labeled | |
jobs: | |
auto-fix-formatting: | |
if: > | |
(github.event.issue.pull_request && ( | |
contains(github.event.comment.body, 'auto fix prettier') || | |
contains(github.event.comment.body, 'auto fix fmt') || | |
contains(github.event.comment.body, 'auto fix formatting') || | |
contains(github.event.comment.body, 'auto fix format') | |
)) || | |
(github.event.label.name == 'fmt/auto-fix') | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
registry-url: "https://registry.npmjs.org" | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Setup git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git checkout -B ${GITHUB_HEAD_REF} | |
- name: Run prettier to format the code | |
run: pnpm run fmt | |
- name: Commit and push changes | |
run: | | |
git commit -am "Auto-fix formatting issues" | |
git push --set-upstream origin ${{ env.BRANCH_NAME }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
- name: Remove "fmt/auto-fix" label if exists | |
if: github.event_name == 'pull_request' | |
env: | |
REPO_NAME: ${{ github.repository }} | |
run: | | |
curl \ | |
-X DELETE \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/$REPO_NAME/issues/$PR_ID/labels/fmt/auto-fix" |