Skip to content

Commit 8e866ef

Browse files
committed
feat: add auto run v8 ci
1 parent 4e59a64 commit 8e866ef

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ tmp-*
88
.eslintcache
99
.ncu
1010
package-lock.json
11+
.idea/

lib/ci/run_ci.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ import {
55
CI_TYPES,
66
CI_TYPES_KEYS
77
} from './ci_type_parser.js';
8+
import PRData from "../pr_data.js";
89

910
export const CI_CRUMB_URL = `https://${CI_DOMAIN}/crumbIssuer/api/json`;
1011
const CI_PR_NAME = CI_TYPES.get(CI_TYPES_KEYS.PR).jobName;
1112
export const CI_PR_URL = `https://${CI_DOMAIN}/job/${CI_PR_NAME}/build`;
1213

14+
const CI_V8_NAME = CI_TYPES.get(CI_TYPES_KEYS.V8).jobName;
15+
export const CI_V8_URL = `https://${CI_DOMAIN}/job/${CI_V8_NAME}/build`;
16+
1317
export class RunPRJob {
1418
constructor(cli, request, owner, repo, prid) {
1519
this.cli = cli;
1620
this.request = request;
1721
this.owner = owner;
1822
this.repo = repo;
1923
this.prid = prid;
24+
this.prData = new PRData({prid, owner, repo}, cli)
2025
}
2126

2227
async getCrumb() {
2328
try {
24-
const { crumb } = await this.request.json(CI_CRUMB_URL);
29+
const {crumb} = await this.request.json(CI_CRUMB_URL);
2530
return crumb;
2631
} catch (e) {
2732
return false;
@@ -32,19 +37,19 @@ export class RunPRJob {
3237
const payload = new FormData();
3338
payload.append('json', JSON.stringify({
3439
parameter: [
35-
{ name: 'CERTIFY_SAFE', value: 'on' },
36-
{ name: 'TARGET_GITHUB_ORG', value: this.owner },
37-
{ name: 'TARGET_REPO_NAME', value: this.repo },
38-
{ name: 'PR_ID', value: this.prid },
39-
{ name: 'REBASE_ONTO', value: '<pr base branch>' },
40-
{ name: 'DESCRIPTION_SETTER_DESCRIPTION', value: '' }
40+
{name: 'CERTIFY_SAFE', value: 'on'},
41+
{name: 'TARGET_GITHUB_ORG', value: this.owner},
42+
{name: 'TARGET_REPO_NAME', value: this.repo},
43+
{name: 'PR_ID', value: this.prid},
44+
{name: 'REBASE_ONTO', value: '<pr base branch>'},
45+
{name: 'DESCRIPTION_SETTER_DESCRIPTION', value: ''}
4146
]
4247
}));
4348
return payload;
4449
}
4550

4651
async start() {
47-
const { cli } = this;
52+
const {cli} = this;
4853
cli.startSpinner('Validating Jenkins credentials');
4954
const crumb = await this.getCrumb();
5055

@@ -71,6 +76,28 @@ export class RunPRJob {
7176
return false;
7277
}
7378
cli.stopSpinner('PR CI job successfully started');
79+
80+
// check if the job need a v8 build and trigger it
81+
await this.prData.getPR();
82+
const labels = this.prData.pr.labels
83+
if (labels.includes('v8 engine')) {
84+
cli.startSpinner('Starting V8 CI job');
85+
const response = await this.request.fetch(CI_V8_URL, {
86+
method: 'POST',
87+
headers: {
88+
'Jenkins-Crumb': crumb
89+
},
90+
body: this.payload
91+
});
92+
if (response.status !== 201) {
93+
cli.stopSpinner(
94+
`Failed to start V8 CI: ${response.status} ${response.statusText}`,
95+
this.cli.SPINNER_STATUS.FAILED);
96+
return false;
97+
}
98+
cli.stopSpinner('V8 CI job successfully started');
99+
}
100+
74101
} catch (err) {
75102
cli.stopSpinner('Failed to start CI', this.cli.SPINNER_STATUS.FAILED);
76103
return false;

0 commit comments

Comments
 (0)