From 00e130969a6613a91cf605aa2961f51992e1afc8 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 27 Jan 2025 13:47:48 +0100 Subject: [PATCH] ci: move prettier to its own workflow (@miodec) (#6198) Add pretty fix step if pretty check failed. --------- Co-authored-by: Miodec <13181393+Miodec@users.noreply.github.com> --- .github/workflows/monkey-ci.yml | 64 +++++------------------------- .github/workflows/pretty-check.yml | 62 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/pretty-check.yml diff --git a/.github/workflows/monkey-ci.yml b/.github/workflows/monkey-ci.yml index 7193bb64d..5caddde92 100644 --- a/.github/workflows/monkey-ci.yml +++ b/.github/workflows/monkey-ci.yml @@ -55,11 +55,17 @@ jobs: - 'packages/**/*' anti-cheat: - 'backend/**/anticheat/**' + workflows: + - '.github/workflows/**/*' - name: Check Anti-cheat if: steps.filter.outputs.anti-cheat == 'true' run: exit 1 + - name: Check Workflow Changes + if: steps.filter.outputs.workflows == 'true' && !contains(github.event.pull_request.labels.*.name, 'force-ci') && !contains(github.event.pull_request.labels.*.name, 'force-full-ci') + run: exit 1 + - name: Export changes id: export-changes run: | @@ -115,59 +121,9 @@ jobs: name: Install dependencies run: pnpm install - check-pretty: - name: check-pretty - needs: [pre-ci, prime-cache] - runs-on: ubuntu-latest - if: needs.pre-ci.outputs.should-build-be == 'true' || needs.pre-ci.outputs.should-build-fe == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true' || needs.pre-ci.outputs.assets-json == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci') - steps: - - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - - - name: Setup pnpm - uses: pnpm/action-setup@v4 - with: - version: ${{ env.PNPM_VERSION }} - - - name: Install prettier - run: pnpm add -g prettier@2.8.8 - - - name: Get changed files - if: github.event_name == 'pull_request' - id: get-changed-files - uses: actions/github-script@v7 - with: - script: | - const changedFiles = await github.paginate( - github.rest.pulls.listFiles, - { - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.payload.pull_request.number, - } - ); - return changedFiles.filter(file=> file.status !== "removed").map(file => file.filename).join(' '); - - - name: Check pretty (changed files) - if: github.event_name == 'pull_request' - id: check-pretty - run: | - CHANGED_FILES=$(echo ${{ steps.get-changed-files.outputs.result }}) - if [ -n "$CHANGED_FILES" ]; then - pnpm prettier --check $CHANGED_FILES - fi - - - name: Check pretty (all files) - if: github.event_name == 'push' - run: pnpm prettier --check . - ci-be: name: ci-be - needs: [pre-ci, prime-cache, check-pretty] + needs: [pre-ci, prime-cache] runs-on: ubuntu-latest if: needs.pre-ci.outputs.should-build-be == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci') steps: @@ -215,7 +171,7 @@ jobs: ci-fe: name: ci-fe - needs: [pre-ci, prime-cache, check-pretty] + needs: [pre-ci, prime-cache] runs-on: ubuntu-latest if: needs.pre-ci.outputs.should-build-fe == 'true' || needs.pre-ci.outputs.should-build-pkg == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci') steps: @@ -268,7 +224,7 @@ jobs: ci-assets: name: ci-assets - needs: [pre-ci, prime-cache, check-pretty] + needs: [pre-ci, prime-cache] runs-on: ubuntu-latest if: needs.pre-ci.outputs.assets-json == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci') steps: @@ -337,7 +293,7 @@ jobs: ci-pkg: name: ci-pkg - needs: [pre-ci, prime-cache,check-pretty] + needs: [pre-ci, prime-cache] runs-on: ubuntu-latest if: needs.pre-ci.outputs.should-build-pkg == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci') steps: diff --git a/.github/workflows/pretty-check.yml b/.github/workflows/pretty-check.yml new file mode 100644 index 000000000..0f6b59d31 --- /dev/null +++ b/.github/workflows/pretty-check.yml @@ -0,0 +1,62 @@ +name: Prettier Check + +env: + PNPM_VERSION: "9.6.0" + NODE_VERSION: "20.16.0" + +on: + pull_request: + branches: [master] + types: [opened, reopened, synchronize, ready_for_review] + +permissions: + contents: read + +concurrency: + group: group-pretty-check-${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + check: + if: github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'force-ci') || contains(github.event.pull_request.labels.*.name, 'force-full-ci') + runs-on: ubuntu-latest + + steps: + - name: Full checkout + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: ${{ env.PNPM_VERSION }} + + - name: Install prettier + run: pnpm add -g prettier@2.8.8 + + - name: Get changed files + id: get-changed-files + uses: actions/github-script@v7 + with: + script: | + const changedFiles = await github.paginate( + github.rest.pulls.listFiles, + { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + } + ); + return changedFiles.filter(file=> file.status !== "removed").map(file => file.filename).join(' '); + + - name: Check pretty (changed files) + run: | + CHANGED_FILES=$(echo ${{ steps.get-changed-files.outputs.result }}) + if [ -n "$CHANGED_FILES" ]; then + pnpm prettier --check $CHANGED_FILES + fi + \ No newline at end of file