forked from scratchfoundation/scratch-editor
-
Notifications
You must be signed in to change notification settings - Fork 1
396 lines (385 loc) · 15.9 KB
/
ci-cd.yml
File metadata and controls
396 lines (385 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
name: CI/CD
on:
pull_request:
paths-ignore:
- '.claude/**'
- '.gemini/**'
- '.serena/**'
- 'Dockerfile'
- 'docker-compose.yml'
- 'CLAUDE.md'
- 'GEMINI.md'
- '.editorconfig'
- '.env.example'
- '.gitignore'
- '.mcp.json'
- 'entrypoint.sh'
- 'README.md'
- 'Release.md'
- 'TRADEMARK'
- 'infra/**'
push:
branches: [main, master, develop, hotfix/*]
paths-ignore:
- '.claude/**'
- '.gemini/**'
- '.serena/**'
- 'Dockerfile'
- 'docker-compose.yml'
- 'CLAUDE.md'
- 'GEMINI.md'
- '.editorconfig'
- '.env.example'
- '.gitignore'
- '.mcp.json'
- 'entrypoint.sh'
- 'README.md'
- 'Release.md'
- 'TRADEMARK'
- 'infra/**'
workflow_dispatch:
concurrency:
group: "${{ github.workflow }} @ ${{ github.head_ref || github.ref }}"
cancel-in-progress: true
permissions:
contents: write # publish a GitHub release
pages: write # deploy to GitHub Pages
issues: write # comment on released issues
pull-requests: write # comment on released pull requests
jobs:
lint:
runs-on: ubuntu-latest
if: |
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main'
))
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Build dependency packages
run: npm run build:dev --workspace=packages/scratch-svg-renderer --workspace=packages/scratch-render --workspace=packages/scratch-vm
- name: Lint
run: npm run lint
unit-test-vm:
runs-on: ubuntu-latest
if: |
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main'
))
env:
NODE_OPTIONS: --max-old-space-size=4000
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Build dependency packages
run: npm run build:dev --workspace=packages/scratch-svg-renderer --workspace=packages/scratch-render --workspace=packages/scratch-vm
- name: Run scratch-vm Unit Tests
run: npm run test:unit --workspace=packages/scratch-vm
unit-test-gui:
runs-on: ubuntu-latest
if: |
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main'
))
env:
NODE_OPTIONS: --max-old-space-size=4000
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Build dependency packages
run: npm run build:dev --workspace=packages/scratch-svg-renderer --workspace=packages/scratch-render --workspace=packages/scratch-vm
- name: Run scratch-gui Unit Tests
run: npm run test:unit --workspace=packages/scratch-gui
integration-test-vm:
runs-on: ubuntu-latest
if: |
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main'
))
strategy:
matrix:
shard: [1, 2]
env:
NODE_OPTIONS: --max-old-space-size=4000
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: Info
run: |
cat <<EOF
Node version: $(node --version)
NPM version: $(npm --version)
GitHub ref: ${{ github.ref }}
GitHub head ref: ${{ github.head_ref }}
EOF
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Build packages
run: npm run build:dev
- name: Create test-results directories
run: mkdir -p packages/scratch-vm/test-results
- name: Run scratch-vm Integration Tests
env:
MESH_DATA_UPDATE_INTERVAL_MS: 100
MESH_EVENT_BATCH_INTERVAL_MS: 100
MESH_PERIODIC_DATA_SYNC_INTERVAL_MS: 1000
working-directory: packages/scratch-vm
run: |
# Collect all integration test files and sort for deterministic sharding
files=$(find test/integration -name '*.js' -o -name '*.test.js' | sort)
total=$(echo "$files" | wc -l)
half=$(( (total + 1) / 2 ))
if [ "${{ matrix.shard }}" = "1" ]; then
selected=$(echo "$files" | head -n "$half")
else
selected=$(echo "$files" | tail -n +"$((half + 1))")
fi
echo "Shard ${{ matrix.shard }}/$total files: running $(echo "$selected" | wc -l) files"
echo "$selected"
echo "$selected" | xargs npx tap
- name: Store Test Results
if: always() # Even if tests fail
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: test-output-integration-vm-shard-${{ matrix.shard }}
path: packages/scratch-vm/test-results/*
integration-test-gui:
runs-on: ubuntu-latest
if: |
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main'
))
strategy:
matrix:
shard: [1, 2]
env:
NODE_OPTIONS: --max-old-space-size=4000
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: Info
run: |
cat <<EOF
Node version: $(node --version)
NPM version: $(npm --version)
GitHub ref: ${{ github.ref }}
GitHub head ref: ${{ github.head_ref }}
EOF
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Build packages
run: npm run build:dev
- name: Create test-results directories
run: mkdir -p packages/scratch-gui/test-results
- name: Run scratch-gui Integration Tests
env:
JEST_JUNIT_OUTPUT_DIR: packages/scratch-gui/test-results
run: npm run test:integration --workspace=packages/scratch-gui -- --shard=${{ matrix.shard }}/2
- name: Store Test Results
if: always() # Even if tests fail
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: test-output-integration-gui-shard-${{ matrix.shard }}
path: packages/scratch-gui/test-results/*
build-and-deploy:
runs-on: ubuntu-latest
env:
NODE_OPTIONS: --max-old-space-size=4000
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: Info
run: |
cat <<EOF
Node version: $(node --version)
NPM version: $(npm --version)
GitHub ref: ${{ github.ref }}
GitHub head ref: ${{ github.head_ref }}
EOF
- name: Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Run Build
env:
NODE_ENV: production
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
MESH_GRAPHQL_ENDPOINT: ${{ secrets.MESH_GRAPHQL_ENDPOINT }}
MESH_API_KEY: ${{ secrets.MESH_API_KEY }}
MESH_AWS_REGION: ${{ secrets.MESH_AWS_REGION }}
MESH_DATA_UPDATE_INTERVAL_MS: ${{ vars.MESH_DATA_UPDATE_INTERVAL_MS }}
MESH_EVENT_BATCH_INTERVAL_MS: ${{ vars.MESH_EVENT_BATCH_INTERVAL_MS }}
MESH_PERIODIC_DATA_SYNC_INTERVAL_MS: ${{ vars.MESH_PERIODIC_DATA_SYNC_INTERVAL_MS }}
GEMINI_RELAY_ENDPOINT: ${{ secrets.GEMINI_RELAY_ENDPOINT }}
MAX_USER_MESSAGE_LENGTH: ${{ vars.MAX_USER_MESSAGE_LENGTH }}
MIN_USER_MESSAGE_LENGTH: ${{ vars.MIN_USER_MESSAGE_LENGTH }}
GTM_ID: ${{ github.ref == 'refs/heads/develop' && secrets.GTM_ID || '' }}
GTM_ENV_AUTH: ${{ github.ref == 'refs/heads/develop' && secrets.GTM_ENV_AUTH || '' }}
COMMIT_SHA: ${{ github.sha }}
run: npm run build
- name: Generate version.json
run: |
echo '{"commitId":"${{ github.sha }}"}' > packages/scratch-gui/build/version.json
echo '{"commitId":"${{ github.sha }}"}' > packages/scratch-gui/dist/version.json
- name: Store Build Output
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: build-output
path: packages/scratch-gui/build
- name: Store Dist Output
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: dist-output
path: packages/scratch-gui/dist
- name: Prepare deployment files for smalruby.app
if: github.ref == 'refs/heads/develop'
run: touch packages/scratch-gui/dist/.nojekyll
- name: Deploy to smalruby.app GitHub Pages
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
if: github.ref == 'refs/heads/develop'
with:
deploy_key: ${{ secrets.SMALRUBY_APP_DEPLOY_KEY }}
publish_dir: ./packages/scratch-gui/dist
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
cname: smalruby.app
external_repository: smalruby/smalruby.app
- name: Rebuild for smalruby3-editor GitHub Pages
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
env:
PUBLIC_PATH: /smalruby3-editor/
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
MESH_GRAPHQL_ENDPOINT: ${{ secrets.MESH_GRAPHQL_ENDPOINT }}
MESH_API_KEY: ${{ secrets.MESH_API_KEY }}
MESH_AWS_REGION: ${{ secrets.MESH_AWS_REGION }}
MESH_DATA_UPDATE_INTERVAL_MS: ${{ vars.MESH_DATA_UPDATE_INTERVAL_MS }}
MESH_EVENT_BATCH_INTERVAL_MS: ${{ vars.MESH_EVENT_BATCH_INTERVAL_MS }}
MESH_PERIODIC_DATA_SYNC_INTERVAL_MS: ${{ vars.MESH_PERIODIC_DATA_SYNC_INTERVAL_MS }}
GEMINI_RELAY_ENDPOINT: ${{ secrets.GEMINI_RELAY_ENDPOINT }}
MAX_USER_MESSAGE_LENGTH: ${{ vars.MAX_USER_MESSAGE_LENGTH }}
MIN_USER_MESSAGE_LENGTH: ${{ vars.MIN_USER_MESSAGE_LENGTH }}
GTM_ID: ''
GTM_ENV_AUTH: ''
run: cd packages/scratch-gui && npm exec node ./scripts/postbuild.mjs
- name: Prepare deployment files
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
run: touch packages/scratch-gui/build/.nojekyll
- name: Deploy to smalruby3-editor GitHub Pages
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./packages/scratch-gui/build
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
- name: Set branch name
id: branch
run: echo "BRANCH_NAME=${{ github.head_ref || github.ref_name }}" >> $GITHUB_OUTPUT
- name: Rebuild for branch GitHub Pages
if: |
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/hotfix/') ||
startsWith(github.ref, 'refs/heads/dependabot/') ||
startsWith(github.ref, 'refs/heads/renovate/')
))
env:
PUBLIC_PATH: /smalruby3-editor/${{ steps.branch.outputs.BRANCH_NAME }}/
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
MESH_GRAPHQL_ENDPOINT: ${{ secrets.MESH_GRAPHQL_ENDPOINT }}
MESH_API_KEY: ${{ secrets.MESH_API_KEY }}
MESH_AWS_REGION: ${{ secrets.MESH_AWS_REGION }}
MESH_DATA_UPDATE_INTERVAL_MS: ${{ vars.MESH_DATA_UPDATE_INTERVAL_MS }}
MESH_EVENT_BATCH_INTERVAL_MS: ${{ vars.MESH_EVENT_BATCH_INTERVAL_MS }}
MESH_PERIODIC_DATA_SYNC_INTERVAL_MS: ${{ vars.MESH_PERIODIC_DATA_SYNC_INTERVAL_MS }}
GEMINI_RELAY_ENDPOINT: ${{ secrets.GEMINI_RELAY_ENDPOINT }}
MAX_USER_MESSAGE_LENGTH: ${{ vars.MAX_USER_MESSAGE_LENGTH }}
MIN_USER_MESSAGE_LENGTH: ${{ vars.MIN_USER_MESSAGE_LENGTH }}
GTM_ID: ''
GTM_ENV_AUTH: ''
run: cd packages/scratch-gui && npm exec node ./scripts/postbuild.mjs
- name: Prepare deployment files for branch GitHub Pages
if: |
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/hotfix/') ||
startsWith(github.ref, 'refs/heads/dependabot/') ||
startsWith(github.ref, 'refs/heads/renovate/')
))
run: touch packages/scratch-gui/build/.nojekyll
- name: Deploy playground to GitHub Pages for branch
if: |
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/hotfix/') ||
startsWith(github.ref, 'refs/heads/dependabot/') ||
startsWith(github.ref, 'refs/heads/renovate/')
))
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./packages/scratch-gui/build
full_commit_message: "Build for ${{ steps.branch.outputs.BRANCH_NAME }} (${{ github.sha }}) ${{ github.event.head_commit.message }}"
destination_dir: ${{ steps.branch.outputs.BRANCH_NAME }}
keep_files: true
- name: Comment preview URL on PR (once only)
if: |
github.event_name == 'pull_request' &&
(!(
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/hotfix/') ||
startsWith(github.ref, 'refs/heads/dependabot/') ||
startsWith(github.ref, 'refs/heads/renovate/')
))
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PREVIEW_URL: https://smalruby.jp/smalruby3-editor/${{ steps.branch.outputs.BRANCH_NAME }}/
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
ALREADY_COMMENTED=$(gh pr view "$PR_NUMBER" --repo ${{ github.repository }} --json comments \
--jq "[.comments[].body | contains(\"$PREVIEW_URL\")] | any")
if [ "$ALREADY_COMMENTED" != "true" ]; then
gh pr comment "$PR_NUMBER" --repo ${{ github.repository }} \
--body "🚀 Preview deployed: $PREVIEW_URL"
fi