Skip to content
Permalink
Browse files
feat: allow forcing latest tag (#1070)
* 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 0549a3035c8348c62958d2f1f037226bf2a0ce21
Showing with 55 additions and 2 deletions.
  1. +15 −0 __snapshots__/cli.js
  2. +12 −0 src/bin/release-please.ts
  3. +17 −1 src/factory.ts
  4. +5 −1 src/index.ts
  5. +6 −0 src/release-pr.ts
@@ -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
@@ -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'] = `
@@ -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]
`
@@ -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) {
@@ -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,
});
}
@@ -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
@@ -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<GitHubTag | undefined> {
if (this.latestTagOverride) {
return this.latestTagOverride;
}

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

0 comments on commit 0549a30

Please sign in to comment.