ci: move prettier to its own workflow (@miodec) ()

Add pretty fix step if pretty check failed.

---------

Co-authored-by: Miodec <13181393+Miodec@users.noreply.github.com>
This commit is contained in:
Jack 2025-01-27 13:47:48 +01:00 committed by GitHub
parent 219b41302e
commit 00e130969a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 72 additions and 54 deletions

View file

@ -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:

62
.github/workflows/pretty-check.yml vendored Normal file
View file

@ -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