diff --git a/__snapshots__/cli.js b/__snapshots__/cli.js index 23a2e060a..9b45c0ca9 100644 --- a/__snapshots__/cli.js +++ b/__snapshots__/cli.js @@ -49,6 +49,11 @@ Options: "). [string] --changelog-path where can the CHANGELOG be found in the project? [default: "CHANGELOG.md"] + --latest-tag-version Override the detected latest tag version + [string] + --latest-tag-sha Override the detected latest tag SHA[string] + --latest-tag-name Override the detected latest tag name + [string] --draft mark release as a draft. no tag is created but tag_name and target_commitish are associated with the release for future tag @@ -110,6 +115,11 @@ Options: "). [string] --changelog-path where can the CHANGELOG be found in the project? [default: "CHANGELOG.md"] + --latest-tag-version Override the detected latest tag version + [string] + --latest-tag-sha Override the detected latest tag SHA[string] + --latest-tag-name Override the detected latest tag name + [string] ` exports['CLI flags manifest-pr flags 1'] = ` @@ -212,4 +222,9 @@ Options: "). [string] --changelog-path where can the CHANGELOG be found in the project? [default: "CHANGELOG.md"] + --latest-tag-version Override the detected latest tag version + [string] + --latest-tag-sha Override the detected latest tag SHA[string] + --latest-tag-name Override the detected latest tag name + [string] ` diff --git a/src/bin/release-please.ts b/src/bin/release-please.ts index a95af5714..d200400d8 100644 --- a/src/bin/release-please.ts +++ b/src/bin/release-please.ts @@ -104,6 +104,18 @@ function releaserCommon(ya: YargsOptionsBuilder) { default: 'CHANGELOG.md', describe: 'where can the CHANGELOG be found in the project?', }); + ya.option('latest-tag-version', { + describe: 'Override the detected latest tag version', + type: 'string', + }); + ya.option('latest-tag-sha', { + describe: 'Override the detected latest tag SHA', + type: 'string', + }); + ya.option('latest-tag-name', { + describe: 'Override the detected latest tag name', + type: 'string', + }); } function releaseType(ya: YargsOptionsBuilder, defaultType?: string) { diff --git a/src/factory.ts b/src/factory.ts index fac19aabd..90b79a544 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -261,11 +261,27 @@ function releasePR(options: ReleasePRFactoryOptions): ReleasePR { const [GHFactoryOptions, RPFactoryOptions] = getGitHubFactoryOpts(options); const github = gitHubInstance(GHFactoryOptions); - const {releaseType, label, ...RPConstructorOptions} = RPFactoryOptions; + const { + releaseType, + label, + latestTagName, + latestTagSha, + latestTagVersion, + ...RPConstructorOptions + } = RPFactoryOptions; + let latestTag: GitHubTag | undefined = undefined; + if (latestTagName && latestTagSha && latestTagVersion) { + latestTag = { + name: latestTagName, + sha: latestTagSha, + version: latestTagVersion, + }; + } const labels = getLabels(label); return new (factory.releasePRClass(releaseType))({ github, labels, + latestTag, ...RPConstructorOptions, }); } diff --git a/src/index.ts b/src/index.ts index 9bdb29bbb..b361a1c24 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {OctokitAPIs, GitHub} from './github'; +import {OctokitAPIs, GitHub, GitHubTag} from './github'; import {ReleaseType} from './releasers'; import {ReleasePR} from './release-pr'; import {ChangelogSection} from './conventional-commits'; @@ -122,6 +122,7 @@ export interface ReleasePRConstructorOptions ReleaserConstructorOptions { labels?: string[]; skipDependencyUpdates?: boolean; + latestTag?: GitHubTag; } // GitHubRelease Constructor options @@ -152,6 +153,9 @@ export interface ReleasePRFactoryOptions GitHubFactoryOptions, ReleaserFactory { label?: string; + latestTagName?: string; + latestTagSha?: string; + latestTagVersion?: string; } // GitHubRelease factory/builder options diff --git a/src/release-pr.ts b/src/release-pr.ts index 53765d832..d7caded0c 100644 --- a/src/release-pr.ts +++ b/src/release-pr.ts @@ -89,6 +89,7 @@ export class ReleasePR { extraFiles: string[]; forManifestReleaser: boolean; enableSimplePrereleaseParsing = false; + latestTagOverride?: GitHubTag; signoff?: string; constructor(options: ReleasePRConstructorOptions) { @@ -115,6 +116,7 @@ export class ReleasePR { this.signoff = options.signoff; this.extraFiles = options.extraFiles ?? []; this.forManifestReleaser = options.skipDependencyUpdates ?? false; + this.latestTagOverride = options.latestTag; } // A releaser can override this method to automatically detect the @@ -603,6 +605,10 @@ export class ReleasePR { prefix?: string, preRelease = false ): Promise { + if (this.latestTagOverride) { + return this.latestTagOverride; + } + const branchPrefix = prefix?.endsWith('-') ? prefix.replace(/-$/, '') : prefix;