Skip to content

Commit

Permalink
feat: allow forcing latest tag (#1070)
Browse files Browse the repository at this point in the history
* feat: allow forcing latest tag

* fix test snapshot

Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
chingor13 and bcoe committed Sep 24, 2021
1 parent 59f3094 commit 0549a30
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
15 changes: 15 additions & 0 deletions __snapshots__/cli.js
Expand Up @@ -49,6 +49,11 @@ Options:
<email@example.com>"). [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
Expand Down Expand Up @@ -110,6 +115,11 @@ Options:
<email@example.com>"). [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'] = `
Expand Down Expand Up @@ -212,4 +222,9 @@ Options:
<email@example.com>"). [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]
`
12 changes: 12 additions & 0 deletions src/bin/release-please.ts
Expand Up @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion src/factory.ts
Expand Up @@ -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,
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -122,6 +122,7 @@ export interface ReleasePRConstructorOptions
ReleaserConstructorOptions {
labels?: string[];
skipDependencyUpdates?: boolean;
latestTag?: GitHubTag;
}

// GitHubRelease Constructor options
Expand Down Expand Up @@ -152,6 +153,9 @@ export interface ReleasePRFactoryOptions
GitHubFactoryOptions,
ReleaserFactory {
label?: string;
latestTagName?: string;
latestTagSha?: string;
latestTagVersion?: string;
}

// GitHubRelease factory/builder options
Expand Down
6 changes: 6 additions & 0 deletions src/release-pr.ts
Expand Up @@ -89,6 +89,7 @@ export class ReleasePR {
extraFiles: string[];
forManifestReleaser: boolean;
enableSimplePrereleaseParsing = false;
latestTagOverride?: GitHubTag;
signoff?: string;

constructor(options: ReleasePRConstructorOptions) {
Expand All @@ -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
Expand Down Expand Up @@ -603,6 +605,10 @@ export class ReleasePR {
prefix?: string,
preRelease = false
): Promise<GitHubTag | undefined> {
if (this.latestTagOverride) {
return this.latestTagOverride;
}

const branchPrefix = prefix?.endsWith('-')
? prefix.replace(/-$/, '')
: prefix;
Expand Down

0 comments on commit 0549a30

Please sign in to comment.