Skip to content

Commit 616a01a

Browse files
committed
[U] Upgrade dependencies, harden workflows
1 parent 1d62c35 commit 616a01a

8 files changed

Lines changed: 1473 additions & 1443 deletions

File tree

.github/workflows/cloudflare-clean.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@ on:
88
jobs:
99
clean:
1010
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
project: [one-among-us, our-data]
1114

1215
steps:
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-node@v4
16+
- uses: actions/checkout@v6
17+
18+
- uses: actions/setup-node@v6
1519
with:
16-
node-version: 20
20+
node-version: 24
1721
cache: 'yarn'
18-
- run: yarn install
1922

20-
- name: Clean Cloudflare Deployments (one-among-us)
21-
run: yarn cloudflare_clean
22-
env:
23-
CF_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
24-
CF_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
25-
CF_PAGES_PROJECT_NAME: one-among-us
23+
- name: Install dependencies
24+
run: yarn install --frozen-lockfile
2625

27-
- name: Clean Cloudflare Deployments (our-data)
26+
- name: Clean Cloudflare Deployments (${{ matrix.project }})
2827
run: yarn cloudflare_clean
2928
env:
3029
CF_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
3130
CF_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
32-
CF_PAGES_PROJECT_NAME: our-data
31+
CF_PAGES_PROJECT_NAME: ${{ matrix.project }}

.github/workflows/generator.yml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,25 @@ permissions:
1515
contents: write
1616
pages: write
1717
id-token: write
18+
actions: write
1819

1920
jobs:
2021
build:
2122
runs-on: ubuntu-latest
22-
permissions: write-all
2323

2424
steps:
25-
- uses: actions/checkout@v3
26-
- uses: actions/setup-node@v3
27-
with:
28-
node-version: 18
25+
- uses: actions/checkout@v6
2926

30-
- name: Cache node_modules
31-
uses: actions/cache@v3
32-
id: cache
27+
- uses: actions/setup-node@v6
3328
with:
34-
path: node_modules
35-
key: ${{ runner.os }}-node-${{ hashFiles('yarn.lock') }}
36-
restore-keys: ${{ runner.os }}-node-
29+
node-version: 24
30+
cache: 'yarn'
3731

3832
- name: Install Dependencies
39-
if: steps.cache.outputs.cache-hit != 'true'
40-
run: yarn install --production --frozen-lockfile
33+
run: yarn install --frozen-lockfile
4134

4235
- name: Build
43-
run: yarn build
36+
run: yarn run build
4437

4538
- name: Deploy to GitHub branch
4639
uses: JamesIves/github-pages-deploy-action@v4
@@ -49,26 +42,36 @@ jobs:
4942
folder: dist
5043

5144
- name: Deploy to Cloudflare Pages
52-
uses: cloudflare/pages-action@v1
45+
uses: cloudflare/wrangler-action@v3
5346
with:
5447
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
5548
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
56-
projectName: our-data
57-
directory: dist
49+
command: pages deploy dist --project-name=our-data
5850

5951
- name: Check for document changes, ignoring comments
60-
uses: dorny/paths-filter@v2
52+
uses: dorny/paths-filter@v4
6153
id: changes
6254
with:
6355
filters: |
6456
src:
6557
- 'people/**/*[^.json]'
6658
59+
- name: Generate token for cross-repo dispatch
60+
id: generate-token
61+
if: steps.changes.outputs.src == 'true'
62+
uses: actions/create-github-app-token@v3
63+
with:
64+
app-id: ${{ vars.APP_CLIENT_ID }}
65+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
66+
owner: 'one-among-us'
67+
repositories: 'web'
68+
permission-actions: write
69+
6770
- name: Trigger web repackage
68-
uses: actions/github-script@v6
71+
uses: actions/github-script@v9
6972
if: steps.changes.outputs.src == 'true'
7073
with:
71-
github-token: ${{ secrets.GH_PERSONAL_TOKEN }}
74+
github-token: ${{ steps.generate-token.outputs.token }}
7275
script: |
7376
await github.rest.actions.createWorkflowDispatch({
7477
owner: 'one-among-us',

.github/workflows/pr-build.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: PR Build
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
branches: [main, develop]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout PR branch
20+
uses: actions/checkout@v6
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v6
24+
with:
25+
node-version: 24
26+
cache: 'yarn'
27+
28+
- name: Build Preview
29+
run: |
30+
yarn install --frozen-lockfile
31+
yarn build-preview
32+
rm -rf dist/web.tgz
33+
34+
- name: Save PR number
35+
run: echo ${{ github.event.pull_request.number }} > dist/pr_number.txt
36+
37+
- name: Upload Artifact
38+
uses: actions/upload-artifact@v7
39+
with:
40+
name: preview-dist
41+
path: dist/
42+
retention-days: 1
Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,61 @@
1-
name: PR Preview
1+
name: PR Deploy Preview
22

33
on:
4-
pull_request_target:
5-
types: [opened, synchronize, reopened]
6-
branches: [main, develop]
7-
workflow_dispatch:
8-
inputs:
9-
pr_number:
10-
description: 'Pull Request number to deploy preview for'
11-
required: true
4+
workflow_run:
5+
workflows: ["PR Build"]
6+
types:
7+
- completed
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
pull-requests: write
15+
actions: read
1216

1317
jobs:
14-
build:
18+
deploy:
1519
runs-on: ubuntu-latest
1620

17-
permissions:
18-
contents: write
19-
deployments: write
20-
pull-requests: write
21+
if: >
22+
github.event.workflow_run.event == 'pull_request' &&
23+
github.event.workflow_run.conclusion == 'success'
2124
2225
steps:
23-
# First, check out the workflow file (from the base) so secrets are available.
24-
- name: Checkout base branch
25-
uses: actions/checkout@v4
26+
- name: Download Artifact
27+
uses: actions/download-artifact@v8
28+
with:
29+
name: preview-dist
30+
path: dist/
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
run-id: ${{ github.event.workflow_run.id }}
2633

27-
# Determine PR info based on the event type.
28-
- name: Set PR info
34+
- name: Read PR Number
2935
id: pr-info
3036
run: |
31-
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
32-
echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_ENV
33-
else
34-
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
37+
PR_NUMBER=$(cat dist/pr_number.txt | tr -d '\n\r')
38+
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
39+
echo "Error: Invalid PR number format: $PR_NUMBER"
40+
exit 1
3541
fi
36-
37-
# Now check out the PR’s head branch (whether from a PR event or supplied manually)
38-
- name: Checkout PR branch
39-
uses: actions/checkout@v4
40-
with:
41-
ref: "refs/pull/${{ env.PR_NUMBER }}/merge"
42-
43-
- name: Setup Node.js
44-
uses: actions/setup-node@v4
45-
with:
46-
node-version: 20
47-
cache: 'yarn'
48-
49-
- name: Build
50-
run: |
51-
yarn install --production --frozen-lockfile
52-
yarn build-preview
53-
rm -rf dist/web.tgz
42+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
43+
rm dist/pr_number.txt
5444
5545
- name: Deploy to Cloudflare Pages
5646
uses: cloudflare/wrangler-action@v3
5747
with:
5848
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
5949
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
60-
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
6150
command: pages deploy dist --project-name=data-preview --branch=pr-${{ env.PR_NUMBER }}
6251

6352
- name: Pull request comment
64-
uses: actions/github-script@v6
53+
uses: actions/github-script@v9
54+
env:
55+
PR_NUMBER: ${{ env.PR_NUMBER }}
6556
with:
6657
script: |
67-
const prNumber = "${{ env.PR_NUMBER }}";
58+
const prNumber = parseInt(process.env.PR_NUMBER, 10);
6859
const now = new Date().toISOString().substring(0, 19).replace('T', ' ');
6960
const reviewBody = `🐱 感谢贡献!\n\n部署了预览,在这里哦: https://pr-${prNumber}.data-preview.pages.dev\n\n🕒 最后更新: ${now} (UTC)`;
7061

package.json

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,40 @@
99
"type": "module",
1010
"private": true,
1111
"scripts": {
12-
"build": "node --loader ts-node/esm/transpile-only scripts/build.ts",
12+
"build": "tsx scripts/build.ts",
1313
"build-preview": "yarn build && scripts/preview.sh",
1414
"serve": "http-server --cors='*' -c-1 dist",
1515
"preview": "yarn build-preview && yarn serve",
16-
"watch": "node --loader ts-node/esm/transpile-only scripts/watch.ts",
16+
"watch": "tsx scripts/watch.ts",
1717
"dev": "concurrently -n \"watch,serve\" -c \"cyan,green\" \"yarn watch\" \"yarn serve\"",
1818
"clean": "rm -rf dist/* .build-cache",
19-
"translate": "node --loader ts-node/esm/transpile-only scripts/translate.ts",
19+
"translate": "tsx scripts/translate.ts",
2020
"cloudflare_clean": "node scripts/cloudflare_clean.js"
2121
},
2222
"dependencies": {
2323
"@andreekeberg/imagedata": "^1.0.2",
24-
"@mdx-js/mdx": "^2.1.5",
24+
"@mdx-js/mdx": "^3.1.1",
2525
"@swc/core": "^1.3.17",
26-
"@types/fs-extra": "^11.0.1",
27-
"@types/node": "^20",
2826
"args-parser": "^1.3.0",
2927
"autocorrect-node": "^2.5.5",
3028
"blurhash": "^2.0.5",
31-
"esbuild": "^0.18.10",
3229
"fs-extra": "^11.1.0",
3330
"google-translate-api-x": "^10.7.1",
3431
"js-yaml": "^4.1.0",
35-
"katex": "^0.16.10",
3632
"lunar-typescript": "^1.8.6",
3733
"markdown-yaml-metadata-parser": "^3.0.0",
3834
"moment": "^2.29.4",
39-
"rehype-katex": "6",
40-
"remark-math": "5",
41-
"ts-node": "^10.9.1",
42-
"typescript": "^5.1.6"
35+
"rehype-katex": "^7.0.1",
36+
"remark-math": "^6.0.0"
4337
},
4438
"devDependencies": {
45-
"@octokit/core": "^4.1.0",
39+
"@types/fs-extra": "^11.0.1",
4640
"@types/js-yaml": "^4.0.5",
41+
"@types/node": "^25.6.0",
4742
"concurrently": "^9.2.1",
4843
"exponential-backoff": "^3.1.0",
4944
"http-server": "^14.1.1",
50-
"node-fetch": "^2.6.7"
45+
"tsx": "^4.21.0",
46+
"typescript": "^6.0.3"
5147
}
5248
}

scripts/cloudflare_clean.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch'
21
import { backOff } from 'exponential-backoff'
32

43
const CF_API_TOKEN = process.env.CF_API_TOKEN

scripts/watch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ async function build() {
3030
const startTime = Date.now();
3131

3232
buildProcess = spawn(
33-
"node",
34-
["--loader", "ts-node/esm/transpile-only", "scripts/build.ts"],
33+
"tsx",
34+
["scripts/build.ts"],
3535
{
3636
cwd: projectRoot,
3737
stdio: "inherit",

0 commit comments

Comments
 (0)