From f26666e8fea4817731abc346557155cca453dfd1 Mon Sep 17 00:00:00 2001 From: Esther Kim <44627152+estherkim@users.noreply.github.com> Date: Mon, 1 Mar 2021 17:55:43 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20=20Count=20all=20cherry=20picks?= =?UTF-8?q?=20when=20setting=20the=20version=20(#32689)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-system/common/git.js | 31 +------------------ build-system/compile/internal-version.js | 38 ++++-------------------- build-system/tasks/release/index.js | 3 -- 3 files changed, 6 insertions(+), 66 deletions(-) diff --git a/build-system/common/git.js b/build-system/common/git.js index 6983bf607d98..7f44bfa37832 100644 --- a/build-system/common/git.js +++ b/build-system/common/git.js @@ -179,13 +179,7 @@ function gitCommitterEmail() { * @return {!Array<{sha: string, isCherryPick: boolean}>} */ function gitCherryMaster() { - return getStdout('git cherry master') - .trim() - .split('\n') - .map((line) => ({ - isCherryPick: line.substring(0, 2) == '- ', - sha: line.substring(2), - })); + return getStdout('git cherry master').trim().split('\n'); } /** @@ -202,27 +196,6 @@ function gitCommitFormattedTime(ref = 'HEAD') { ).trim(); } -/** - * Returns the commit message of a given ref. - * @param {string} ref a Git reference (commit SHA, branch name, etc.) for the - * commit to get the time of. - * @return {string} - */ -function gitCommitMessage(ref = 'HEAD') { - return getStdout(`git log ${ref} -n 1 --pretty="%B"`); -} - -/** - * Checks if a branch contains a specific ref. - * @param {string} ref a Git reference (commit SHA, branch name, etc.) for the - * commit to get the time of. - * @param {string} branch the branch to check. - * @return {boolean} - */ -function gitBranchContains(ref, branch = 'master') { - return Boolean(getStdout(`git branch ${branch} --contains ${ref}`).trim()); -} - /** * Returns the merge base of the current branch off of master when running on * a local workspace. @@ -254,13 +227,11 @@ function gitDiffPath(path, commit) { } module.exports = { - gitBranchContains, gitBranchCreationPoint, gitBranchName, gitCherryMaster, gitCommitFormattedTime, gitCommitHash, - gitCommitMessage, gitCommitterEmail, gitDiffAddedNameOnlyMaster, gitDiffColor, diff --git a/build-system/compile/internal-version.js b/build-system/compile/internal-version.js index e5c0f7d3fccb..a8e89dc0c3b5 100644 --- a/build-system/compile/internal-version.js +++ b/build-system/compile/internal-version.js @@ -16,12 +16,7 @@ 'use strict'; const minimist = require('minimist'); -const { - gitBranchContains, - gitCherryMaster, - gitCommitMessage, - gitCommitFormattedTime, -} = require('../common/git'); +const {gitCherryMaster, gitCommitFormattedTime} = require('../common/git'); // Allow leading zeros in --version_override, e.g. 0000000000001 const argv = minimist(process.argv.slice(2), { @@ -32,11 +27,9 @@ const argv = minimist(process.argv.slice(2), { * Generates the AMP version number. * * Version numbers are determined using the following algorithm: - * - Count the number () of cherry-picked commits on this branch that came - * from the `master` branch, until reaching `master` or the first commit that - * was added directly on this branch (if the current commit is on `master`'s - * commit history, or only contains new commits that are not cherry-picked - * from `master`, then is 0). + * - Count the number () of cherry-picked commits on this branch, + * including non `master` commits. If this branch only contains new commits + * that are not cherry-picked, then is 0). * - Find the commit () before the last cherry-picked commit from the * `master` branch (if the current branch is `master`, or otherwise in * `master`'s commit history, then the current commit is ). @@ -92,28 +85,7 @@ function getVersion() { return version; } - let numberOfCherryPicks = 0; - const commitCherriesInfo = gitCherryMaster().reverse(); - for (const {isCherryPick, sha} of commitCherriesInfo) { - if (!isCherryPick) { - // Sometimes cherry-picks are mistaken for new commits. Double-check here - // by looking for the hard-coded message at the end of the commit that - // indicates that it was a cherry-pick. Requires that the cherry-pick was - // performed with the `-x` flag. - const commitMessage = gitCommitMessage(sha); - const cherryPickedMatch = /\(cherry picked from commit ([0-9a-f]{40})\)/.exec( - commitMessage - ); - if (!cherryPickedMatch) { - break; - } - - if (!gitBranchContains(cherryPickedMatch[1])) { - break; - } - } - numberOfCherryPicks++; - } + const numberOfCherryPicks = gitCherryMaster().length; if (numberOfCherryPicks > 999) { throw new Error( `This branch has ${numberOfCherryPicks} cherry-picks, which is more than 999, the maximum allowed number of cherry-picks!` diff --git a/build-system/tasks/release/index.js b/build-system/tasks/release/index.js index 95307690837d..62bd93e0cba9 100644 --- a/build-system/tasks/release/index.js +++ b/build-system/tasks/release/index.js @@ -406,9 +406,6 @@ async function cleanup_(tempDir) { } async function release() { - // TODO(#27771, danielrozenberg): fail this release quickly if there are - // commits in the tree that are not from the `master` branch. - const outputDir = path.resolve(argv.output_dir || './release'); const tempDir = path.join(outputDir, 'tmp');