diff --git a/schemas/config.json b/schemas/config.json index 4de53a92e..baa37da90 100644 --- a/schemas/config.json +++ b/schemas/config.json @@ -82,6 +82,10 @@ "description": "When tagging a release, include `v` in the tag. Defaults to `false`.", "type": "boolean" }, + "tag-head-sha": { + "description": "Tag head sha of the PR with the change. Defaults to `false`.", + "type": "boolean" + }, "changelog-type": { "description": "The type of changelog to use. Defaults to `default`.", "type": "string", @@ -496,6 +500,7 @@ "snapshot-label": true, "initial-version": true, "exclude-paths": true, - "component-no-space": false + "component-no-space": false, + "tag-head-sha": false } } diff --git a/src/bin/release-please.ts b/src/bin/release-please.ts index b3240fc69..32dfd58c3 100644 --- a/src/bin/release-please.ts +++ b/src/bin/release-please.ts @@ -431,6 +431,12 @@ function taggingOptions(yargs: yargs.Argv): yargs.Argv { 'release-please automatically adds ` ` (space) in front of parsed ${component}. Should this be disabled?', type: 'boolean', default: false, + }) + .option('tag-head-sha', { + describe: + 'tag the head of the branch with the updated code - not the squashed commit', + type: 'boolean', + default: false, }); } diff --git a/src/manifest.ts b/src/manifest.ts index 99983a12b..dea0aac0a 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -143,6 +143,8 @@ export interface ReleaserConfig { skipSnapshot?: boolean; // Manifest only excludePaths?: string[]; + + tagHeadSha?: boolean; } export interface CandidateReleasePullRequest { @@ -189,6 +191,7 @@ interface ReleaserConfigJson { 'skip-snapshot'?: boolean; // Java-only 'initial-version'?: string; 'exclude-paths'?: string[]; // manifest-only + 'tag-head-sha'?: boolean; } export interface ManifestOptions { @@ -1403,6 +1406,7 @@ function extractReleaserConfig( skipSnapshot: config['skip-snapshot'], initialVersion: config['initial-version'], excludePaths: config['exclude-paths'], + tagHeadSha: config['tag-head-sha'], }; } diff --git a/src/strategies/base.ts b/src/strategies/base.ts index dd1c1003d..4eabc1ec4 100644 --- a/src/strategies/base.ts +++ b/src/strategies/base.ts @@ -85,6 +85,7 @@ export interface BaseStrategyOptions { logger?: Logger; initialVersion?: string; extraLabels?: string[]; + tagHeadSha?: boolean; } /** @@ -114,6 +115,7 @@ export abstract class BaseStrategy implements Strategy { readonly componentNoSpace?: boolean; readonly extraFiles: ExtraFile[]; readonly extraLabels: string[]; + readonly tagHeadSha?: boolean; readonly changelogNotes: ChangelogNotes; @@ -149,6 +151,7 @@ export abstract class BaseStrategy implements Strategy { this.extraFiles = options.extraFiles || []; this.initialVersion = options.initialVersion; this.extraLabels = options.extraLabels || []; + this.tagHeadSha = options.tagHeadSha; } /** @@ -691,11 +694,18 @@ export abstract class BaseStrategy implements Strategy { component && this.includeComponentInTag ? `${component}: v${version.toString()}` : `v${version.toString()}`; + const githubSourceSha = process.env.GITHUB_SOURCE_SHA; + var newSha = '' + if (this.tagHeadSha && githubSourceSha !== undefined) { + newSha = githubSourceSha + } else { + newSha = mergedPullRequest.sha + } return { name: releaseName, tag, notes: notes || '', - sha: mergedPullRequest.sha, + sha: newSha, }; } diff --git a/src/updaters/release-please-config.ts b/src/updaters/release-please-config.ts index 4cea722fa..c199abd88 100644 --- a/src/updaters/release-please-config.ts +++ b/src/updaters/release-please-config.ts @@ -82,6 +82,7 @@ function releaserConfigToJsonConfig( 'extra-files': config.extraFiles, 'version-file': config.versionFile, 'snapshot-label': config.snapshotLabels?.join(','), // Java-only + 'tag-head-sha': config.tagHeadSha, }; return jsonConfig; }