diff --git a/dist/index.js b/dist/index.js index 0710837..dbd3b0f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2399,6 +2399,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.GitHubRelease = void 0; const chalk = __webpack_require__(843); const checkpoint_1 = __webpack_require__(923); +const package_branch_prefix_1 = __webpack_require__(866); const release_pr_factory_1 = __webpack_require__(796); const github_1 = __webpack_require__(614); const semver_1 = __webpack_require__(876); @@ -2421,11 +2422,21 @@ class GitHubRelease { this.gh = this.gitHubInstance(options.octokitAPIs); } async createRelease() { + // Attempt to lookup the package name from a well known location, such + // as package.json, if none is provided: + if (!this.packageName && this.releaseType) { + this.packageName = await release_pr_factory_1.ReleasePRFactory.class(this.releaseType).lookupPackageName(this.gh, this.path); + } + if (this.packageName === undefined) { + throw Error(`could not determine package name for release repo = ${this.repoUrl}`); + } // In most configurations, createRelease() should be called close to when // a release PR is merged, e.g., a GitHub action that kicks off this // workflow on merge. For tis reason, we can pull a fairly small number of PRs: const pageSize = 25; - const gitHubReleasePR = await this.gh.findMergedReleasePR(this.labels, pageSize, this.monorepoTags ? this.packageName : undefined); + const gitHubReleasePR = await this.gh.findMergedReleasePR(this.labels, pageSize, this.monorepoTags + ? package_branch_prefix_1.packageBranchPrefix(this.packageName, this.releaseType) + : undefined); if (!gitHubReleasePR) { checkpoint_1.checkpoint('no recent release PRs found', checkpoint_1.CheckpointType.Failure); return undefined; @@ -2435,19 +2446,11 @@ class GitHubRelease { const changelogContents = (await this.gh.getFileContents(this.addPath(this.changelogPath))).parsedContent; const latestReleaseNotes = GitHubRelease.extractLatestReleaseNotes(changelogContents, version); checkpoint_1.checkpoint(`found release notes: \n---\n${chalk.grey(latestReleaseNotes)}\n---\n`, checkpoint_1.CheckpointType.Success); - // Attempt to lookup the package name from a well known location, such - // as package.json, if none is provided: - if (!this.packageName && this.releaseType) { - this.packageName = await release_pr_factory_1.ReleasePRFactory.class(this.releaseType).lookupPackageName(this.gh); - } // Go uses '/' for a tag separator, rather than '-': let tagSeparator = '-'; if (this.releaseType) { tagSeparator = release_pr_factory_1.ReleasePRFactory.class(this.releaseType).tagSeparator(); } - if (this.packageName === undefined) { - throw Error(`could not determine package name for release repo = ${this.repoUrl}`); - } const release = await this.gh.createRelease(this.packageName, this.monorepoTags ? `${this.packageName}${tagSeparator}${version}` : version, gitHubReleasePR.sha, latestReleaseNotes); @@ -3388,6 +3391,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.ReleasePR = void 0; const semver = __webpack_require__(876); const checkpoint_1 = __webpack_require__(923); +const package_branch_prefix_1 = __webpack_require__(866); const github_1 = __webpack_require__(614); // eslint-disable-next-line @typescript-eslint/no-var-requires const parseGithubRepoUrl = __webpack_require__(345); @@ -3415,6 +3419,7 @@ class ReleasePR { : undefined; this.gh = this.gitHubInstance(options.octokitAPIs); this.changelogSections = options.changelogSections; + this.releaseType = options.releaseType; } async run() { if (this.snapshot && !this.supportsSnapshots()) { @@ -3459,8 +3464,11 @@ class ReleasePR { // A releaser can implement this method to automatically detect // the release name when creating a GitHub release, for instance by returning // name in package.json, or setup.py. + static async lookupPackageName( // eslint-disable-next-line @typescript-eslint/no-unused-vars - static async lookupPackageName(gh) { + gh, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + path) { return Promise.resolve(undefined); } static tagSeparator() { @@ -3536,10 +3544,7 @@ class ReleasePR { const updates = options.updates; const version = options.version; const includePackageName = options.includePackageName; - // Do not include npm style @org/ prefixes in the branch name: - const branchPrefix = this.packageName.match(/^@[\w-]+\//) - ? this.packageName.split('/')[1] - : this.packageName; + const branchPrefix = package_branch_prefix_1.packageBranchPrefix(this.packageName, this.releaseType); const title = includePackageName ? `chore: release ${this.packageName} ${version}` : `chore: release ${version}`; @@ -3576,16 +3581,19 @@ class ReleasePR { changelogEmpty(changelogEntry) { return changelogEntry.split('\n').length === 1; } - addPath(file) { - if (this.path === undefined) { + static addPathStatic(file, path) { + if (path === undefined) { return file; } else { - const path = this.path.replace(/[/\\]$/, ''); + path = path.replace(/[/\\]$/, ''); file = file.replace(/^[/\\]/, ''); return `${path}/${file}`; } } + addPath(file) { + return ReleasePR.addPathStatic(file, this.path); + } } exports.ReleasePR = ReleasePR; ReleasePR.releaserName = 'base'; @@ -8055,7 +8063,7 @@ module.exports = Scanner /* 191 */ /***/ (function(module) { -module.exports = {"_args":[["release-please@8.2.0","/home/runner/work/release-please-action/release-please-action"]],"_from":"release-please@8.2.0","_id":"release-please@8.2.0","_inBundle":false,"_integrity":"sha512-uyd2K2X9YLwb+t7XtR268qQBDBCTarNdaSJ7zTwF7KF+rFfoHRmWcgTBylK0hM2/FS+L+4SoJ1KEBvoyjQ01uw==","_location":"/release-please","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"release-please@8.2.0","name":"release-please","escapedName":"release-please","rawSpec":"8.2.0","saveSpec":null,"fetchSpec":"8.2.0"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/release-please/-/release-please-8.2.0.tgz","_spec":"8.2.0","_where":"/home/runner/work/release-please-action/release-please-action","author":{"name":"Google Inc."},"bin":{"release-please":"build/src/bin/release-please.js"},"bugs":{"url":"https://github.com/googleapis/release-please/issues"},"dependencies":{"@conventional-commits/parser":"^0.3.0","@iarna/toml":"^2.2.5","@octokit/graphql":"^4.3.1","@octokit/request":"^5.3.4","@octokit/rest":"^18.0.4","chalk":"^4.0.0","code-suggester":"^1.4.0","conventional-changelog-conventionalcommits":"^4.4.0","conventional-changelog-writer":"^5.0.0","conventional-commits-filter":"^2.0.2","figures":"^3.0.0","parse-github-repo-url":"^1.4.1","semver":"^7.0.0","type-fest":"^0.20.0","unist-util-visit":"^2.0.3","unist-util-visit-parents":"^3.1.1","yargs":"^16.0.0"},"description":"generate release PRs based on the conventionalcommits.org spec","devDependencies":{"@octokit/types":"^6.1.0","@types/chai":"^4.1.7","@types/iarna__toml":"^2.0.1","@types/mocha":"^8.0.0","@types/node":"^11.13.6","@types/pino":"^6.3.0","@types/semver":"^7.0.0","@types/sinon":"^9.0.5","@types/yargs":"^15.0.4","c8":"^7.0.0","chai":"^4.2.0","cross-env":"^7.0.0","gts":"^2.0.0","mocha":"^8.0.0","nock":"^13.0.0","sinon":"^9.0.3","snap-shot-it":"^7.0.0","typescript":"^3.8.3"},"engines":{"node":">=10.12.0"},"files":["build/src","templates","!build/src/**/*.map"],"homepage":"https://github.com/googleapis/release-please#readme","keywords":["release","conventional-commits"],"license":"Apache-2.0","main":"./build/src/index.js","name":"release-please","repository":{"type":"git","url":"git+https://github.com/googleapis/release-please.git"},"scripts":{"api-documenter":"api-documenter yaml --input-folder=temp","api-extractor":"api-extractor run --local","clean":"gts clean","compile":"tsc -p .","docs-test":"echo add docs tests","fix":"gts fix","lint":"gts check","prepare":"npm run compile","pretest":"npm run compile","test":"cross-env ENVIRONMENT=test c8 mocha --recursive --timeout=5000 build/test","test:snap":"SNAPSHOT_UPDATE=1 npm test"},"version":"8.2.0"}; +module.exports = {"_args":[["release-please@9.0.0-candidate.0","/home/runner/work/release-please-action/release-please-action"]],"_from":"release-please@9.0.0-candidate.0","_id":"release-please@9.0.0-candidate.0","_inBundle":false,"_integrity":"sha512-Q4z3+t13zO0lQg1dk4qfddR/s4np5L5JlEi6yLZt5Xz7UKoVynjr6c0s7AesoKpqPjnz4k14V2b1Gk3rScU1Xw==","_location":"/release-please","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"release-please@9.0.0-candidate.0","name":"release-please","escapedName":"release-please","rawSpec":"9.0.0-candidate.0","saveSpec":null,"fetchSpec":"9.0.0-candidate.0"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/release-please/-/release-please-9.0.0-candidate.0.tgz","_spec":"9.0.0-candidate.0","_where":"/home/runner/work/release-please-action/release-please-action","author":{"name":"Google Inc."},"bin":{"release-please":"build/src/bin/release-please.js"},"bugs":{"url":"https://github.com/googleapis/release-please/issues"},"dependencies":{"@conventional-commits/parser":"^0.4.1","@iarna/toml":"^2.2.5","@octokit/graphql":"^4.3.1","@octokit/request":"^5.3.4","@octokit/rest":"^18.0.4","chalk":"^4.0.0","code-suggester":"^1.4.0","conventional-changelog-conventionalcommits":"^4.4.0","conventional-changelog-writer":"^5.0.0","conventional-commits-filter":"^2.0.2","figures":"^3.0.0","parse-github-repo-url":"^1.4.1","semver":"^7.0.0","type-fest":"^0.20.0","unist-util-visit":"^2.0.3","unist-util-visit-parents":"^3.1.1","yargs":"^16.0.0"},"description":"generate release PRs based on the conventionalcommits.org spec","devDependencies":{"@octokit/types":"^6.1.0","@types/chai":"^4.1.7","@types/iarna__toml":"^2.0.1","@types/mocha":"^8.0.0","@types/node":"^11.13.6","@types/pino":"^6.3.0","@types/semver":"^7.0.0","@types/sinon":"^9.0.5","@types/yargs":"^15.0.4","c8":"^7.0.0","chai":"^4.2.0","cross-env":"^7.0.0","gts":"^2.0.0","mocha":"^8.0.0","nock":"^13.0.0","sinon":"^9.0.3","snap-shot-it":"^7.0.0","typescript":"^3.8.3"},"engines":{"node":">=10.12.0"},"files":["build/src","templates","!build/src/**/*.map"],"homepage":"https://github.com/googleapis/release-please#readme","keywords":["release","conventional-commits"],"license":"Apache-2.0","main":"./build/src/index.js","name":"release-please","repository":{"type":"git","url":"git+https://github.com/googleapis/release-please.git"},"scripts":{"api-documenter":"api-documenter yaml --input-folder=temp","api-extractor":"api-extractor run --local","clean":"gts clean","compile":"tsc -p .","docs-test":"echo add docs tests","fix":"gts fix","lint":"gts check","prepare":"npm run compile","pretest":"npm run compile","test":"cross-env ENVIRONMENT=test c8 mocha --recursive --timeout=5000 build/test","test:snap":"SNAPSHOT_UPDATE=1 npm test"},"version":"9.0.0-candidate.0"}; /***/ }), /* 192 */, @@ -31003,8 +31011,8 @@ module.exports = { reqSerializer } -var rawSymbol = Symbol('pino-raw-req-ref') -var pinoReqProto = Object.create({}, { +const rawSymbol = Symbol('pino-raw-req-ref') +const pinoReqProto = Object.create({}, { id: { enumerable: true, writable: true, @@ -31052,7 +31060,7 @@ Object.defineProperty(pinoReqProto, rawSymbol, { function reqSerializer (req) { // req.info is for hapi compat. - var connection = req.info || req.connection + const connection = req.info || req.socket const _req = Object.create(pinoReqProto) _req.id = (typeof req.id === 'function' ? req.id() : (req.id || (req.info ? req.info.id : undefined))) _req.method = req.method @@ -31238,10 +31246,9 @@ const visit = __webpack_require__(263); // eslint-disable-next-line @typescript-eslint/no-var-requires const visitWithAncestors = __webpack_require__(727); const NUMBER_REGEX = /^[0-9]+$/; -// Converts conventional commit AST into conventional-changelog's -// output format, see: https://www.npmjs.com/package/conventional-commits-parser -function toConventionalChangelogFormat(ast) { - const cc = { +const parser = __webpack_require__(10); +function getBlankConventionalCommit() { + return { body: '', subject: '', type: '', @@ -31254,6 +31261,12 @@ function toConventionalChangelogFormat(ast) { header: '', footer: null, }; +} +// Converts conventional commit AST into conventional-changelog's +// output format, see: https://www.npmjs.com/package/conventional-commits-parser +function toConventionalChangelogFormat(ast) { + const commits = []; + const headerCommit = getBlankConventionalCommit(); // Separate the body and summary nodes, this simplifies the subsequent // tree walking logic: let body; @@ -31272,19 +31285,19 @@ function toConventionalChangelogFormat(ast) { visit(summary, (node) => { switch (node.type) { case 'type': - cc.type = node.value; - cc.header += node.value; + headerCommit.type = node.value; + headerCommit.header += node.value; break; case 'scope': - cc.scope = node.value; - cc.header += `(${node.value})`; + headerCommit.scope = node.value; + headerCommit.header += `(${node.value})`; break; case 'breaking-change': - cc.header += '!'; + headerCommit.header += '!'; break; case 'text': - cc.subject = node.value; - cc.header += `: ${node.value}`; + headerCommit.subject = node.value; + headerCommit.header += `: ${node.value}`; break; default: break; @@ -31292,11 +31305,8 @@ function toConventionalChangelogFormat(ast) { }); // [] if (body) { - visit(body, 'text', (node) => { - // TODO(@bcoe): once we have \n tokens in tree we can drop this: - if (cc.body !== '') - cc.body += '\n'; - cc.body += node.value; + visit(body, ['text', 'newline'], (node) => { + headerCommit.body += node.value; }); } // Extract BREAKING CHANGE notes, regardless of whether they fall in @@ -31310,37 +31320,32 @@ function toConventionalChangelogFormat(ast) { if (!parent) { return; } - let startCollecting = false; switch (parent.type) { case 'summary': - breaking.text = cc.subject; + breaking.text = headerCommit.subject; break; case 'body': breaking.text = ''; // We treat text from the BREAKING CHANGE marker forward as // the breaking change notes: - visit(parent, ['text', 'breaking-change'], (node) => { - // TODO(@bcoe): once we have \n tokens in tree we can drop this: - if (startCollecting && node.type === 'text') { - if (breaking.text !== '') - breaking.text += '\n'; - breaking.text += node.value; - } - else if (node.type === 'breaking-change') { - startCollecting = true; - } + visit(parent, ['text', 'newline'], (node) => { + breaking.text += node.value; }); break; case 'token': + // If the '!' breaking change marker is used, the breaking change + // will be identified when the footer is parsed as a commit: + if (!node.value.includes('BREAKING')) + return; parent = ancestors.pop(); - visit(parent, 'text', (node) => { + visit(parent, ['text', 'newline'], (node) => { breaking.text = node.value; }); break; } }); if (breaking.text !== '') - cc.notes.push(breaking); + headerCommit.notes.push(breaking); // Populates references array from footers: // references: [{ // action: 'Closes', @@ -31384,10 +31389,53 @@ function toConventionalChangelogFormat(ast) { }); // TODO(@bcoe): how should references like "Refs: v8:8940" work. if (hasRefSepartor && reference.issue.match(NUMBER_REGEX)) { - cc.references.push(reference); + headerCommit.references.push(reference); } }); - return cc; + /* + * Split footers that resemble commits into additional commits, e.g., + * chore: multiple commits + * chore(recaptchaenterprise): migrate recaptchaenterprise to the Java microgenerator + * Committer: @miraleung + * PiperOrigin-RevId: 345559154 + * ... + */ + visitWithAncestors(ast, ['type'], (node, ancestors) => { + let parent = ancestors.pop(); + if (!parent) { + return; + } + if (parent.type === 'token') { + parent = ancestors.pop(); + let footerText = ''; + visit(parent, ['type', 'scope', 'breaking-change', 'separator', 'text', 'newline'], (node) => { + switch (node.type) { + case 'scope': + footerText += `(${node.value})`; + break; + case 'separator': + // Footers of the form Fixes #99, should not be parsed. + if (node.value.includes('#')) + return; + footerText += `${node.value} `; + break; + default: + footerText += node.value; + break; + } + }); + try { + for (const commit of toConventionalChangelogFormat(parser.parser(footerText))) { + commits.push(commit); + } + } + catch (err) { + // Footer does not appear to be an additional commit. + } + } + }); + commits.push(headerCommit); + return commits; } exports.default = toConventionalChangelogFormat; //# sourceMappingURL=to-conventional-changelog-format.js.map @@ -31519,9 +31567,9 @@ module.exports = ltr "use strict"; -var errSerializer = __webpack_require__(621) -var reqSerializers = __webpack_require__(307) -var resSerializers = __webpack_require__(578) +const errSerializer = __webpack_require__(621) +const reqSerializers = __webpack_require__(307) +const resSerializers = __webpack_require__(578) module.exports = { err: errSerializer, @@ -36281,8 +36329,8 @@ const Scanner = __webpack_require__(188) const { isWhitespace, isNewline, isParens } = __webpack_require__(157) /* - * ::= , *, , *,