From 90590a331df84511d8ad738614077820543e8b11 Mon Sep 17 00:00:00 2001 From: Miodec Date: Thu, 23 Jan 2025 21:15:50 +0100 Subject: [PATCH] ci: run prettier write on pr label change --- .github/workflows/pretty-fix.yml | 75 +++++++++++++++++--------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/.github/workflows/pretty-fix.yml b/.github/workflows/pretty-fix.yml index 6669033ab..a3e6bbfc4 100644 --- a/.github/workflows/pretty-fix.yml +++ b/.github/workflows/pretty-fix.yml @@ -1,48 +1,53 @@ name: Prettier Fix +env: + PNPM_VERSION: "9.6.0" + NODE_VERSION: "20.16.0" + +permissions: + contents: write + on: - workflow_dispatch: - inputs: - reason: - description: "Reason for manually triggering this workflow" - required: false - schedule: - - cron: "0 0 * * 0" + pull_request_target: + types: [labeled] jobs: - prettier-fix: - permissions: write-all + prettify: runs-on: ubuntu-latest + if: github.event.label.name == 'prettify' steps: - - uses: actions/checkout@v4 - - name: Set up date environment variables - run: | - echo "BRANCH_TITLE=pretty-fix-$(date +%s)" >> $GITHUB_ENV - echo "PR_TITLE=Prettier Fix - $(date)" >> $GITHUB_ENV + - name: Checkout code + uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: "20.16.0" + node-version: ${{ env.NODE_VERSION }} - - name: Install dependencies - run: npm i prettier@2.5.1 --save-dev --save-exact - - - name: Pretty Check - run: npm run pretty-fix - - - name: Create commits - id: commits - continue-on-error: true - run: | - git config user.name 'monkeytypegeorge' - git config user.email 'monkeytypegeorge@gmail.com' - git add . - git commit -m 'refactor: run prettier' - - - name: Create pull request - uses: peter-evans/create-pull-request@v4 + - name: Setup pnpm + uses: pnpm/action-setup@v4 with: - branch: ${{ env.BRANCH_TITLE }} - title: ${{ env.PR_TITLE }} - body: ${{ env.PR_TITLE }} + version: ${{ env.PNPM_VERSION }} + + - name: Install prettier + run: pnpm add -g prettier@2.8.8 + + - name: Run Prettier fix + run: pnpm prettier --write . + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "prettier fix" + + - name: Remove label + uses: actions/github-script@v7 + with: + script: | + const { context, github } = require('@actions/github'); + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + name: 'prettify' + }); \ No newline at end of file