mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 22:34:21 +08:00
build: use shared circleci dev-infra for common circleci code
This allows us to remove the `rebase-pr.js` script so that we can maintain this script in a single place.
This commit is contained in:
parent
6ddcc364a1
commit
d829d73f18
@ -11,6 +11,7 @@ version: 2.1
|
|||||||
|
|
||||||
orbs:
|
orbs:
|
||||||
browser-tools: circleci/browser-tools@1.1.3
|
browser-tools: circleci/browser-tools@1.1.3
|
||||||
|
devinfra: angular/dev-infra@1.0.1
|
||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
snapshot_changed:
|
snapshot_changed:
|
||||||
@ -102,19 +103,18 @@ commands:
|
|||||||
|
|
||||||
rebase_pr:
|
rebase_pr:
|
||||||
steps:
|
steps:
|
||||||
- run:
|
- devinfra/rebase-pr-on-target-branch:
|
||||||
name: Rebase PR on target branch
|
base_revision: << pipeline.git.base_revision >>
|
||||||
shell: bash
|
head_revision: << pipeline.git.revision >>
|
||||||
command: >
|
|
||||||
if [[ -n "${CIRCLE_PR_NUMBER}" ]]; then
|
rebase_pr_win:
|
||||||
# User is required for rebase.
|
steps:
|
||||||
git config user.name "angular-ci"
|
- devinfra/rebase-pr-on-target-branch:
|
||||||
git config user.email "angular-ci"
|
base_revision: << pipeline.git.base_revision >>
|
||||||
# Rebase PR on top of target branch.
|
head_revision: << pipeline.git.revision >>
|
||||||
node tools/rebase-pr.js angular/angular-cli ${CIRCLE_PR_NUMBER}
|
# Use `bash.exe` as Shell because the CircleCI-orb command is an
|
||||||
else
|
# included Bash script and expects Bash as shell.
|
||||||
echo "This build is not over a PR, nothing to do."
|
shell: bash.exe
|
||||||
fi
|
|
||||||
|
|
||||||
custom_attach_workspace:
|
custom_attach_workspace:
|
||||||
description: Attach workspace at a predefined location
|
description: Attach workspace at a predefined location
|
||||||
@ -367,7 +367,7 @@ jobs:
|
|||||||
parallelism: 16
|
parallelism: 16
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- rebase_pr
|
- rebase_pr_win
|
||||||
- setup_windows
|
- setup_windows
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
|
||||||
* found in the LICENSE file at https://angular.io/license
|
|
||||||
*/
|
|
||||||
// tslint:disable:no-console
|
|
||||||
// ** IMPORTANT **
|
|
||||||
// This script cannot use external dependencies because it needs to run before they are installed.
|
|
||||||
|
|
||||||
const util = require('util');
|
|
||||||
const https = require('https');
|
|
||||||
const child_process = require('child_process');
|
|
||||||
const exec = util.promisify(child_process.exec);
|
|
||||||
|
|
||||||
function determineTargetBranch(repository, prNumber) {
|
|
||||||
const pullsUrl = `https://api.github.com/repos/${repository}/pulls/${prNumber}`;
|
|
||||||
// GitHub requires a user agent: https://developer.github.com/v3/#user-agent-required
|
|
||||||
const options = { headers: { 'User-Agent': repository } };
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
https
|
|
||||||
.get(pullsUrl, options, (res) => {
|
|
||||||
const { statusCode } = res;
|
|
||||||
const contentType = res.headers['content-type'];
|
|
||||||
|
|
||||||
let error;
|
|
||||||
if (statusCode !== 200) {
|
|
||||||
error = new Error(`Request Failed.\nStatus Code: ${statusCode}.\nResponse: ${res}.\n' +`);
|
|
||||||
} else if (!/^application\/json/.test(contentType)) {
|
|
||||||
error = new Error(
|
|
||||||
'Invalid content-type.\n' + `Expected application/json but received ${contentType}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
res.resume();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
res.setEncoding('utf8');
|
|
||||||
let rawData = '';
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
rawData += chunk;
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
try {
|
|
||||||
const parsedData = JSON.parse(rawData);
|
|
||||||
resolve(parsedData['base']['ref']);
|
|
||||||
} catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.on('error', (e) => {
|
|
||||||
reject(e);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.argv.length != 4) {
|
|
||||||
console.error(`This script requires the GitHub repository and PR number as arguments.`);
|
|
||||||
console.error(`Example: node scripts/rebase-pr.js angular/angular 123`);
|
|
||||||
process.exitCode = 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const repository = process.argv[2];
|
|
||||||
const prNumber = process.argv[3];
|
|
||||||
let targetBranch;
|
|
||||||
|
|
||||||
return Promise.resolve()
|
|
||||||
.then(() => {
|
|
||||||
console.log(`Determining target branch for PR ${prNumber} on ${repository}.`);
|
|
||||||
return determineTargetBranch(repository, prNumber);
|
|
||||||
})
|
|
||||||
.then((target) => {
|
|
||||||
targetBranch = target;
|
|
||||||
console.log(`Target branch is ${targetBranch}.`);
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
console.log(`Fetching ${targetBranch} from origin.`);
|
|
||||||
return exec(`git fetch origin ${targetBranch}`);
|
|
||||||
})
|
|
||||||
.then((target) => {
|
|
||||||
console.log(`Rebasing current branch on ${targetBranch}.`);
|
|
||||||
return exec(`git rebase origin/${targetBranch}`);
|
|
||||||
})
|
|
||||||
.then(() => console.log('Rebase successfull.'))
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('Failed to rebase on top or target branch.\n');
|
|
||||||
console.error(err);
|
|
||||||
process.exitCode = 1;
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user