ci: clean up docs only change logic (#38456)
This commit is contained in:
parent
b4ec363b3d
commit
a769b48164
3 changed files with 22 additions and 39 deletions
|
@ -66,7 +66,7 @@ for:
|
||||||
build_script:
|
build_script:
|
||||||
- ps: |
|
- ps: |
|
||||||
node script/yarn.js install --frozen-lockfile
|
node script/yarn.js install --frozen-lockfile
|
||||||
node script/doc-only-change.js --prNumber=$env:APPVEYOR_PULL_REQUEST_NUMBER --prBranch=$env:APPVEYOR_REPO_BRANCH
|
node script/doc-only-change.js --prNumber=$env:APPVEYOR_PULL_REQUEST_NUMBER
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-warning "Skipping build for doc only change"; Exit-AppveyorBuild
|
Write-warning "Skipping build for doc only change"; Exit-AppveyorBuild
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ for:
|
||||||
build_script:
|
build_script:
|
||||||
- ps: |
|
- ps: |
|
||||||
node script/yarn.js install --frozen-lockfile
|
node script/yarn.js install --frozen-lockfile
|
||||||
node script/doc-only-change.js --prNumber=$env:APPVEYOR_PULL_REQUEST_NUMBER --prBranch=$env:APPVEYOR_REPO_BRANCH
|
node script/doc-only-change.js --prNumber=$env:APPVEYOR_PULL_REQUEST_NUMBER
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-warning "Skipping build for doc only change"; Exit-AppveyorBuild
|
Write-warning "Skipping build for doc only change"; Exit-AppveyorBuild
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ for:
|
||||||
build_script:
|
build_script:
|
||||||
- ps: |
|
- ps: |
|
||||||
node script/yarn.js install --frozen-lockfile
|
node script/yarn.js install --frozen-lockfile
|
||||||
node script/doc-only-change.js --prNumber=$env:APPVEYOR_PULL_REQUEST_NUMBER --prBranch=$env:APPVEYOR_REPO_BRANCH
|
node script/doc-only-change.js --prNumber=$env:APPVEYOR_PULL_REQUEST_NUMBER
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-warning "Skipping build for doc only change"; Exit-AppveyorBuild
|
Write-warning "Skipping build for doc only change"; Exit-AppveyorBuild
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ for:
|
||||||
build_script:
|
build_script:
|
||||||
- ps: |
|
- ps: |
|
||||||
node script/yarn.js install --frozen-lockfile
|
node script/yarn.js install --frozen-lockfile
|
||||||
node script/doc-only-change.js --prNumber=$env:APPVEYOR_PULL_REQUEST_NUMBER --prBranch=$env:APPVEYOR_REPO_BRANCH
|
node script/doc-only-change.js --prNumber=$env:APPVEYOR_PULL_REQUEST_NUMBER
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
Write-warning "Skipping build for doc only change"; Exit-AppveyorBuild
|
Write-warning "Skipping build for doc only change"; Exit-AppveyorBuild
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,57 +3,40 @@ const { Octokit } = require('@octokit/rest');
|
||||||
const octokit = new Octokit();
|
const octokit = new Octokit();
|
||||||
|
|
||||||
async function checkIfDocOnlyChange () {
|
async function checkIfDocOnlyChange () {
|
||||||
if (args.prNumber || args.prBranch || args.prURL) {
|
let { prNumber, prURL } = args;
|
||||||
|
|
||||||
|
if (prNumber || prURL) {
|
||||||
try {
|
try {
|
||||||
let pullRequestNumber = args.prNumber;
|
// CircleCI doesn't provide the PR number except on forked PRs,
|
||||||
if (!pullRequestNumber || isNaN(pullRequestNumber)) {
|
// so to cover all cases we just extract it from the PR URL.
|
||||||
|
if (!prNumber || isNaN(prNumber)) {
|
||||||
if (args.prURL) {
|
if (args.prURL) {
|
||||||
// CircleCI doesn't provide the PR number for branch builds, but it does provide the PR URL
|
prNumber = prURL.split('/').pop();
|
||||||
const pullRequestParts = args.prURL.split('/');
|
|
||||||
pullRequestNumber = pullRequestParts[pullRequestParts.length - 1];
|
|
||||||
} else if (args.prBranch) {
|
|
||||||
// AppVeyor doesn't provide a PR number for branch builds - figure it out from the branch
|
|
||||||
const prsForBranch = await octokit.pulls.list({
|
|
||||||
owner: 'electron',
|
|
||||||
repo: 'electron',
|
|
||||||
state: 'open',
|
|
||||||
head: `electron:${args.prBranch}`
|
|
||||||
});
|
|
||||||
if (prsForBranch.data.length === 1) {
|
|
||||||
pullRequestNumber = prsForBranch.data[0].number;
|
|
||||||
} else {
|
|
||||||
// If there are 0 PRs or more than one PR on a branch, just assume that this is more than a doc change
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const filesChanged = await octokit.paginate(octokit.pulls.listFiles.endpoint.merge({
|
const filesChanged = await octokit.paginate(octokit.pulls.listFiles.endpoint.merge({
|
||||||
owner: 'electron',
|
owner: 'electron',
|
||||||
repo: 'electron',
|
repo: 'electron',
|
||||||
pull_number: pullRequestNumber,
|
pull_number: prNumber,
|
||||||
per_page: 100
|
per_page: 100
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('Changed Files:', filesChanged.map(fileInfo => fileInfo.filename));
|
console.log('Changed Files: ', filesChanged.map(fileInfo => fileInfo.filename));
|
||||||
|
|
||||||
const nonDocChange = filesChanged.find((fileInfo) => {
|
const nonDocChange = filesChanged.length === 0 || filesChanged.find(({ filename }) => {
|
||||||
const fileDirs = fileInfo.filename.split('/');
|
const fileDirs = filename.split('/');
|
||||||
if (fileDirs[0] !== 'docs') {
|
if (fileDirs[0] !== 'docs') return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (nonDocChange || filesChanged.length === 0) {
|
|
||||||
process.exit(1);
|
process.exit(nonDocChange ? 1 : 0);
|
||||||
} else {
|
} catch (error) {
|
||||||
process.exit(0);
|
console.error('Error getting list of files changed: ', error);
|
||||||
}
|
|
||||||
} catch (ex) {
|
|
||||||
console.error('Error getting list of files changed: ', ex);
|
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error(`Check if only the docs were changed for a commit.
|
console.error(`Check if only the docs were changed for a commit.
|
||||||
Usage: doc-only-change.js --prNumber=PR_NUMBER || --prBranch=PR_BRANCH || --prURL=PR_URL`);
|
Usage: doc-only-change.js --prNumber=PR_NUMBER || --prURL=PR_URL`);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue