-
Notifications
You must be signed in to change notification settings - Fork 50
177 lines (165 loc) · 6.73 KB
/
Copy pathbug-server.yml
File metadata and controls
177 lines (165 loc) · 6.73 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
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:
build:
if: >-
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 \
node-fetch@2.6.6 form-data@4.0.6 ts-node@10.9.0 typescript@4.9.5
- 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