Skip to content

Commit 00e1309

Browse files
authored
ci: move prettier to its own workflow (@Miodec) (monkeytypegame#6198)
Add pretty fix step if pretty check failed. --------- Co-authored-by: Miodec <[email protected]>
1 parent 219b413 commit 00e1309

File tree

2 files changed

+72
-54
lines changed

2 files changed

+72
-54
lines changed

.github/workflows/monkey-ci.yml

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,17 @@ jobs:
5555
- 'packages/**/*'
5656
anti-cheat:
5757
- 'backend/**/anticheat/**'
58+
workflows:
59+
- '.github/workflows/**/*'
5860
5961
- name: Check Anti-cheat
6062
if: steps.filter.outputs.anti-cheat == 'true'
6163
run: exit 1
6264

65+
- name: Check Workflow Changes
66+
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')
67+
run: exit 1
68+
6369
- name: Export changes
6470
id: export-changes
6571
run: |
@@ -115,59 +121,9 @@ jobs:
115121
name: Install dependencies
116122
run: pnpm install
117123

118-
check-pretty:
119-
name: check-pretty
120-
needs: [pre-ci, prime-cache]
121-
runs-on: ubuntu-latest
122-
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')
123-
steps:
124-
- uses: actions/checkout@v4
125-
126-
- name: Set up Node.js
127-
uses: actions/setup-node@v4
128-
with:
129-
node-version: ${{ env.NODE_VERSION }}
130-
131-
- name: Setup pnpm
132-
uses: pnpm/action-setup@v4
133-
with:
134-
version: ${{ env.PNPM_VERSION }}
135-
136-
- name: Install prettier
137-
run: pnpm add -g [email protected]
138-
139-
- name: Get changed files
140-
if: github.event_name == 'pull_request'
141-
id: get-changed-files
142-
uses: actions/github-script@v7
143-
with:
144-
script: |
145-
const changedFiles = await github.paginate(
146-
github.rest.pulls.listFiles,
147-
{
148-
owner: context.repo.owner,
149-
repo: context.repo.repo,
150-
pull_number: context.payload.pull_request.number,
151-
}
152-
);
153-
return changedFiles.filter(file=> file.status !== "removed").map(file => file.filename).join(' ');
154-
155-
- name: Check pretty (changed files)
156-
if: github.event_name == 'pull_request'
157-
id: check-pretty
158-
run: |
159-
CHANGED_FILES=$(echo ${{ steps.get-changed-files.outputs.result }})
160-
if [ -n "$CHANGED_FILES" ]; then
161-
pnpm prettier --check $CHANGED_FILES
162-
fi
163-
164-
- name: Check pretty (all files)
165-
if: github.event_name == 'push'
166-
run: pnpm prettier --check .
167-
168124
ci-be:
169125
name: ci-be
170-
needs: [pre-ci, prime-cache, check-pretty]
126+
needs: [pre-ci, prime-cache]
171127
runs-on: ubuntu-latest
172128
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')
173129
steps:
@@ -215,7 +171,7 @@ jobs:
215171

216172
ci-fe:
217173
name: ci-fe
218-
needs: [pre-ci, prime-cache, check-pretty]
174+
needs: [pre-ci, prime-cache]
219175
runs-on: ubuntu-latest
220176
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')
221177
steps:
@@ -268,7 +224,7 @@ jobs:
268224

269225
ci-assets:
270226
name: ci-assets
271-
needs: [pre-ci, prime-cache, check-pretty]
227+
needs: [pre-ci, prime-cache]
272228
runs-on: ubuntu-latest
273229
if: needs.pre-ci.outputs.assets-json == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci')
274230
steps:
@@ -337,7 +293,7 @@ jobs:
337293

338294
ci-pkg:
339295
name: ci-pkg
340-
needs: [pre-ci, prime-cache,check-pretty]
296+
needs: [pre-ci, prime-cache]
341297
runs-on: ubuntu-latest
342298
if: needs.pre-ci.outputs.should-build-pkg == 'true' || contains(github.event.pull_request.labels.*.name, 'force-full-ci')
343299
steps:

.github/workflows/pretty-check.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Prettier Check
2+
3+
env:
4+
PNPM_VERSION: "9.6.0"
5+
NODE_VERSION: "20.16.0"
6+
7+
on:
8+
pull_request:
9+
branches: [master]
10+
types: [opened, reopened, synchronize, ready_for_review]
11+
12+
permissions:
13+
contents: read
14+
15+
concurrency:
16+
group: group-pretty-check-${{ github.ref }}-${{ github.workflow }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
check:
21+
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')
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Full checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: ${{ env.NODE_VERSION }}
32+
33+
- name: Setup pnpm
34+
uses: pnpm/action-setup@v4
35+
with:
36+
version: ${{ env.PNPM_VERSION }}
37+
38+
- name: Install prettier
39+
run: pnpm add -g [email protected]
40+
41+
- name: Get changed files
42+
id: get-changed-files
43+
uses: actions/github-script@v7
44+
with:
45+
script: |
46+
const changedFiles = await github.paginate(
47+
github.rest.pulls.listFiles,
48+
{
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
pull_number: context.payload.pull_request.number,
52+
}
53+
);
54+
return changedFiles.filter(file=> file.status !== "removed").map(file => file.filename).join(' ');
55+
56+
- name: Check pretty (changed files)
57+
run: |
58+
CHANGED_FILES=$(echo ${{ steps.get-changed-files.outputs.result }})
59+
if [ -n "$CHANGED_FILES" ]; then
60+
pnpm prettier --check $CHANGED_FILES
61+
fi
62+

0 commit comments

Comments
 (0)