Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow forcing latest tag #1070

Merged
merged 4 commits into from Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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