diff --git a/.ng-dev-config.ts b/.ng-dev-config.ts index 3950d40f26f1..e028981d40d9 100644 --- a/.ng-dev-config.ts +++ b/.ng-dev-config.ts @@ -1,6 +1,6 @@ import {MergeConfig} from '@angular/dev-infra-private/pr/merge/config'; +import {determineMergeBranches} from '@angular/dev-infra-private/pr/merge/determine-merge-branches'; import {GithubConfig} from '@angular/dev-infra-private/utils/config'; -import {determineMergeBranches} from './scripts/determine-merge-branches'; /** * Github configuration for the ng-dev command. This repository is @@ -16,7 +16,11 @@ const github: GithubConfig = { * are respected by the merge script (e.g. the target labels). */ const merge = (): MergeConfig => { - const {minor, patch} = determineMergeBranches(github.owner, github.name); + const currentVersion = require('./package.json').version; + // We use the `@angular/cdk` as source of truth for the latest published version in NPM. + // Any package from the monorepo could technically work and result in the same version. + const {minor, patch} = determineMergeBranches(currentVersion, '@angular/cdk'); + return { // By default, the merge script merges locally with `git cherry-pick` and autosquash. // This has the downside of pull requests showing up as `Closed` instead of `Merged`. diff --git a/package.json b/package.json index d0391f446fcd..d11a088db235 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "resync-caretaker-app": "ts-node --project scripts/tsconfig.json scripts/caretaking/resync-caretaker-app-prs.ts", "ts-circular-deps:check": "yarn -s ts-circular-deps check --config ./src/circular-deps-test.conf.js", "ts-circular-deps:approve": "yarn -s ts-circular-deps approve --config ./src/circular-deps-test.conf.js", - "ng-dev": "ts-node -O {\\\"module\\\":\\\"commonjs\\\"} ./node_modules/@angular/dev-infra-private/cli.js", "merge": "ng-dev pr merge", "approve-api": "node ./scripts/approve-api-golden.js" }, @@ -71,7 +70,7 @@ "@angular-devkit/schematics": "^10.0.0-next.6", "@angular/bazel": "^10.0.0-rc.0", "@angular/compiler-cli": "^10.0.0-rc.0", - "@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#7f3e1227d199a55943152aac6119d40e1bbb028f", + "@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#2ac83eb462cb25c46a761d34dec030e360055016", "@angular/platform-browser-dynamic": "^10.0.0-rc.0", "@angular/platform-server": "^10.0.0-rc.0", "@angular/router": "^10.0.0-rc.0", diff --git a/scripts/determine-merge-branches.ts b/scripts/determine-merge-branches.ts deleted file mode 100644 index ce52120d0182..000000000000 --- a/scripts/determine-merge-branches.ts +++ /dev/null @@ -1,66 +0,0 @@ -import {join} from 'path'; -import * as semver from 'semver'; -import {exec} from 'shelljs'; - -/** Regular expression that matches remote head refs. */ -const UPSTREAM_HEAD_REF = /refs\/heads\/(.*)$/; - -/** Determines merge branches based on the current project version. */ -export function determineMergeBranches( - owner: string, name: string): {minor: string, patch: string} { - const projectRoot = join(__dirname, '../'); - const currentVersion = semver.parse(require('../package.json').version); - - if (currentVersion === null) { - throw Error('Cannot parse version set in project "package.json" file.'); - } - - const {major, minor, patch, prerelease} = currentVersion; - const isMajor = minor === 0 && patch === 0; - const isMinor = minor !== 0 && patch === 0; - - // If there is no prerelease, then we compute patch and minor branches based - // on the current version major and minor. - if (prerelease.length === 0) { - return {minor: `${major}.x`, patch: `${major}.${minor}.x`}; - } - - // If current version is set to a minor prerelease, we can compute the merge branches - // statically. e.g. if we are set to `9.3.0-next.0`, then our merge branches should - // be set to `9.x` and `9.2.x`. - if (isMinor) { - return {minor: `${major}.x`, patch: `${major}.${minor - 1}.x`}; - } else if (!isMajor) { - throw Error('Unexpected version. Cannot have prerelease for patch version.'); - } - - // If we are set to a major prerelease, we cannot statically determine the stable - // patch branch (as the latest minor segment is unknown). We determine it by looking - // for existing patch branches upstream. - const upstreamRefs = exec( - `git ls-remote --heads https://github.com/${owner}/${name}.git`, - {silent: true, cwd: projectRoot}) - .trim() - .split('\n'); - - // Iterate over retrieved upstream refs in reverse. Git sorts them lexicographically ascending. - // We are interested in the greatest semver version starting with the given prefix. - for (let i = upstreamRefs.length - 1; i >= 0; i--) { - const matches = upstreamRefs[i].match(UPSTREAM_HEAD_REF); - if (matches === null) { - continue; - } - const branchName = matches[1]; - const branchVersion = branchName.split('.'); - - // Look for the most recent stable branch that has been created before the new major - // prerelease version. e.g. if the current major is `10.0.0-next.0`, then we need to - // look for a previous patch branch that matches `9.{minor}.x`. - if (branchVersion[0] === `${major - 1}` && branchVersion[1] !== 'x' && - branchVersion[2] === 'x') { - return {minor: `${major - 1}.x`, patch: branchName}; - } - } - - throw Error('Could not determine merge branches.'); -} diff --git a/yarn.lock b/yarn.lock index b3988afda0a8..81fe82875185 100644 --- a/yarn.lock +++ b/yarn.lock @@ -92,9 +92,9 @@ dependencies: tslib "^1.9.0" -"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#7f3e1227d199a55943152aac6119d40e1bbb028f": +"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#2ac83eb462cb25c46a761d34dec030e360055016": version "0.0.0" - resolved "https://github.com/angular/dev-infra-private-builds.git#7f3e1227d199a55943152aac6119d40e1bbb028f" + resolved "https://github.com/angular/dev-infra-private-builds.git#2ac83eb462cb25c46a761d34dec030e360055016" dependencies: "@octokit/graphql" "^4.3.1" chalk "^2.3.1" @@ -103,6 +103,7 @@ inquirer "^7.1.0" minimatch "^3.0.4" multimatch "^4.0.0" + semver "^6.3.0" shelljs "^0.8.3" typed-graphqlify "^2.3.0" yaml "^1.7.2"