Repository navigation
223 lines (210 loc) · 9.08 KB
/
Copy pathbug-server.yml
File metadata and controls
223 lines (210 loc) · 9.08 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
name: Bug Server CI
# 这里业务方根据需求设置
on:
workflow_dispatch:
inputs:
pr_number:
description: 'Fork PR number to test'
required: true
type: string
head_sha:
description: 'Reviewed PR head commit (full 40-character SHA)'
required: true
type: string
push:
branches: ['main']
pull_request:
branches: ['main', 'develop', 'dev/**']
permissions:
contents: read
jobs:
gray-scope:
# 无权限、不检出仓库;仅以 GitHub 事件元数据和受控起点交接旧 Photo。
runs-on: ubuntu-latest
permissions: {}
outputs:
skip: ${{ steps.scope.outputs.skip }}
steps:
- id: scope
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
BASE_REPOSITORY: ${{ github.event.pull_request.base.repo.full_name }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REPOSITORY_ID: ${{ github.event.pull_request.head.repo.id }}
BASE_REPOSITORY_ID: ${{ github.event.pull_request.base.repo.id }}
CREATED_AT: ${{ github.event.pull_request.created_at }}
REPOSITORY: ${{ github.repository }}
INTERNAL_SINCE: ${{ vars.VISACTOR_WORKFLOW_INTERNAL_SINCE }}
run: |
# 仅交接目标 develop;其他分支保留旧 Photo,新 Draft 等待 ready。
skip=$(python3 - <<'PY'
import os, re
from datetime import datetime
e = os.environ
skip = False
if (e['EVENT_NAME'] == 'pull_request' and e['REPOSITORY'] == 'VisActor/VRender'
and e['HEAD_REPOSITORY'] == e['BASE_REPOSITORY'] == e['REPOSITORY']
and e['BASE_REF'] == 'develop' and e['INTERNAL_SINCE']):
# 已配置交接却缺失可信元数据时停止旧构建,避免两套 Photo 同时执行。
since = e['INTERNAL_SINCE']
if not re.fullmatch(r'[1-9][0-9]{0,15}', since) or int(since) > 8640000000000000:
raise SystemExit('Invalid VISACTOR_WORKFLOW_INTERNAL_SINCE')
if e['BASE_REPOSITORY_ID'] != '649514587' or e['HEAD_REPOSITORY_ID'] != e['BASE_REPOSITORY_ID']:
raise SystemExit('Invalid internal repository identity')
created = e['CREATED_AT']
if not re.fullmatch(r'[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z', created):
raise SystemExit('Invalid PR creation time')
skip = int(datetime.fromisoformat(created.replace('Z', '+00:00')).timestamp() * 1000) > int(since)
print('true' if skip else 'false')
PY
)
echo "skip=$skip" >> "$GITHUB_OUTPUT"
build:
needs: gray-scope
if: >-
needs.gray-scope.outputs.skip != 'true' &&
(github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 24.x
uses: actions/setup-node@v4
with:
node-version: 24.x
cache: 'npm'
cache-dependency-path: './common/config/rush/pnpm-lock.yaml'
- name: Test manual dispatch validation
run: |
node --test .github/scripts/bug-server-dispatch.test.cjs
python3 -m unittest discover -s .github/scripts -p 'test_extract_bug_server_bundle.py'
- name: Print All Github Environment Variables
run: env
- name: Install native deps for node-canvas (macOS)
if: runner.os == 'macOS'
run: |
brew update
brew install pkg-config cairo pango libpng jpeg giflib librsvg
- name: Install native deps for node-canvas (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libcairo2-dev libpango1.0-dev libpng-dev libjpeg-dev libgif-dev librsvg2-dev
- name: Update rush
run: node common/scripts/install-run-rush.js update --bypass-policy
- name: Install rush
run: node common/scripts/install-run-rush.js install --bypass-policy
- name: Build
run: node common/scripts/install-run-rush.js build -t @internal/bugserver-trigger
- name: Run CI
working-directory: ./tools/bugserver-trigger
env:
BUG_SERVER_TOKEN: ${{ secrets.BUG_SERVER_TOKEN }}
run: node ../../common/scripts/install-run-rushx.js ci
resolve-manual-target:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
actions: read
outputs:
sha: ${{ steps.target.outputs.sha }}
pr_number: ${{ steps.target.outputs.pr_number }}
head_ref: ${{ steps.target.outputs.head_ref }}
pr_url: ${{ steps.target.outputs.pr_url }}
artifact_id: ${{ steps.target.outputs.artifact_id }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.workflow_sha }}
persist-credentials: false
sparse-checkout: .github/scripts
- name: Validate reviewed PR head
id: target
uses: actions/github-script@v8
env:
PR_NUMBER: ${{ inputs.pr_number }}
HEAD_SHA: ${{ inputs.head_sha }}
with:
script: |
const { resolveBugServerTarget } = require('./.github/scripts/bug-server-dispatch.cjs');
const target = await resolveBugServerTarget({
github, context,
prNumber: process.env.PR_NUMBER,
headSha: process.env.HEAD_SHA
});
core.setOutput('sha', target.sha);
core.setOutput('pr_number', target.prNumber);
core.setOutput('head_ref', target.headRef);
core.setOutput('pr_url', target.prUrl);
core.setOutput('artifact_id', target.artifactId);
await core.summary
.addHeading('Bug Server manual test')
.addLink(`PR #${target.prNumber}`, target.prUrl)
.addLink(`Source build ${target.runId}`, target.runUrl)
.addRaw(`\n\nTested head: \`${target.sha}\`\n`)
.write();
submit-manual-bundle:
needs: resolve-manual-target
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: read
actions: read
steps:
# Use the immutable default-branch workflow commit, never scripts from the PR.
- uses: actions/checkout@v4
with:
ref: ${{ github.workflow_sha }}
persist-credentials: false
sparse-checkout: |
.github/scripts
tools/bugserver-trigger/scripts
- uses: actions/setup-node@v4
with:
node-version: 24.x
- name: Install isolated trigger client dependencies
run: |
mkdir -p "$RUNNER_TEMP/bug-server-client"
npm install --prefix "$RUNNER_TEMP/bug-server-client" --ignore-scripts --no-audit --no-fund --package-lock=false \
- name: Download reviewed PR artifact
uses: actions/github-script@v8
env:
ARTIFACT_ID: ${{ needs.resolve-manual-target.outputs.artifact_id }}
with:
script: |
const archive = await github.rest.actions.downloadArtifact({
...context.repo,
artifact_id: Number(process.env.ARTIFACT_ID),
archive_format: 'zip'
});
const fs = require('node:fs');
const path = require('node:path');
fs.writeFileSync(path.join(process.env.RUNNER_TEMP, 'bug-server-bundle.zip'), Buffer.from(archive.data));
- name: Read bundle as data
run: python3 .github/scripts/extract_bug_server_bundle.py "$RUNNER_TEMP/bug-server-bundle.zip" tools/bugserver-trigger/dist/index.js
- name: Trigger Bug Server for reviewed PR
working-directory: tools/bugserver-trigger
env:
BUG_SERVER_TOKEN: ${{ secrets.BUG_SERVER_TOKEN }}
NODE_PATH: ${{ runner.temp }}/bug-server-client/node_modules
TEST_SHA: ${{ needs.resolve-manual-target.outputs.sha }}
TEST_REF: refs/pull/${{ needs.resolve-manual-target.outputs.pr_number }}/head
TEST_BRANCH: ${{ needs.resolve-manual-target.outputs.head_ref }}
TEST_PR_URL: ${{ needs.resolve-manual-target.outputs.pr_url }}
run: |
if [ -z "$BUG_SERVER_TOKEN" ]; then
echo '::error::BUG_SERVER_TOKEN is not configured for this repository.'
exit 1
fi
test -f dist/index.js
printf 'PR: %s\nTested head: `%s`\n' "$TEST_PR_URL" "$TEST_SHA" >> "$GITHUB_STEP_SUMMARY"
env GITHUB_SHA="$TEST_SHA" GITHUB_REF="$TEST_REF" GITHUB_HEAD_REF="$TEST_BRANCH" \
node "$RUNNER_TEMP/bug-server-client/node_modules/ts-node/dist/bin.js" \
--transpile-only --skip-project \
--compiler-options '{"module":"CommonJS","moduleResolution":"node","esModuleInterop":true}' \
scripts/trigger-test.ts