Skip to content

Commit

Permalink
feat: add auto run v8 ci
Browse files Browse the repository at this point in the history
  • Loading branch information
gengjiawen committed Oct 13, 2022
1 parent 4e59a64 commit 8e866ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ tmp-*
.eslintcache
.ncu
package-lock.json
.idea/
43 changes: 35 additions & 8 deletions lib/ci/run_ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ import {
CI_TYPES,
CI_TYPES_KEYS
} from './ci_type_parser.js';
import PRData from "../pr_data.js";

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

const CI_V8_NAME = CI_TYPES.get(CI_TYPES_KEYS.V8).jobName;
export const CI_V8_URL = `https://${CI_DOMAIN}/job/${CI_V8_NAME}/build`;

export class RunPRJob {
constructor(cli, request, owner, repo, prid) {
this.cli = cli;
this.request = request;
this.owner = owner;
this.repo = repo;
this.prid = prid;
this.prData = new PRData({prid, owner, repo}, cli)
}

async getCrumb() {
try {
const { crumb } = await this.request.json(CI_CRUMB_URL);
const {crumb} = await this.request.json(CI_CRUMB_URL);
return crumb;
} catch (e) {
return false;
Expand All @@ -32,19 +37,19 @@ export class RunPRJob {
const payload = new FormData();
payload.append('json', JSON.stringify({
parameter: [
{ name: 'CERTIFY_SAFE', value: 'on' },
{ name: 'TARGET_GITHUB_ORG', value: this.owner },
{ name: 'TARGET_REPO_NAME', value: this.repo },
{ name: 'PR_ID', value: this.prid },
{ name: 'REBASE_ONTO', value: '<pr base branch>' },
{ name: 'DESCRIPTION_SETTER_DESCRIPTION', value: '' }
{name: 'CERTIFY_SAFE', value: 'on'},
{name: 'TARGET_GITHUB_ORG', value: this.owner},
{name: 'TARGET_REPO_NAME', value: this.repo},
{name: 'PR_ID', value: this.prid},
{name: 'REBASE_ONTO', value: '<pr base branch>'},
{name: 'DESCRIPTION_SETTER_DESCRIPTION', value: ''}
]
}));
return payload;
}

async start() {
const { cli } = this;
const {cli} = this;
cli.startSpinner('Validating Jenkins credentials');
const crumb = await this.getCrumb();

Expand All @@ -71,6 +76,28 @@ export class RunPRJob {
return false;
}
cli.stopSpinner('PR CI job successfully started');

// check if the job need a v8 build and trigger it
await this.prData.getPR();
const labels = this.prData.pr.labels
if (labels.includes('v8 engine')) {
cli.startSpinner('Starting V8 CI job');
const response = await this.request.fetch(CI_V8_URL, {
method: 'POST',
headers: {
'Jenkins-Crumb': crumb
},
body: this.payload
});
if (response.status !== 201) {
cli.stopSpinner(
`Failed to start V8 CI: ${response.status} ${response.statusText}`,
this.cli.SPINNER_STATUS.FAILED);
return false;
}
cli.stopSpinner('V8 CI job successfully started');
}

} catch (err) {
cli.stopSpinner('Failed to start CI', this.cli.SPINNER_STATUS.FAILED);
return false;
Expand Down

0 comments on commit 8e866ef

Please sign in to comment.