diff --git a/action.yml b/action.yml index 573331e2..8ced9857 100644 --- a/action.yml +++ b/action.yml @@ -76,7 +76,7 @@ inputs: set_commits: description: |- Specify whether to set commits for the release. - One of: "auto", "skip" + One of: "auto", "skip", "repo-owner/repo-name@commit", "repo-owner/repo-name@.." required: false projects: description: |- @@ -148,7 +148,7 @@ runs: INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }} INPUT_DISABLE_TELEMETRY: ${{ inputs.disable_telemetry }} INPUT_DISABLE_SAFE_DIRECTORY: ${{ inputs.disable_safe_directory }} - uses: docker://ghcr.io/getsentry/action-release-image:master + uses: docker://ghcr.io/getsentry/action-release-image:feature-add-manual-commit-range # For actions running on macos or windows runners, we use a composite # action approach which allows us to install the arch specific sentry-cli diff --git a/dist/index.js b/dist/index.js index c1b31187..f701504d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -122748,8 +122748,15 @@ const telemetry_1 = __nccwpck_require__(12417); } core.debug(`Release version is ${release}`); yield (0, cli_1.getCLI)().new(release, { projects }); - Sentry.setTag('set-commits', setCommitsOption); - if (setCommitsOption !== 'skip') { + Sentry.setTag('set-commits', setCommitsOption.get('mode')); + if (setCommitsOption.get('mode') === 'manual') { + yield (0, telemetry_1.traceStep)('set-commits', () => __awaiter(void 0, void 0, void 0, function* () { + core.debug(`Setting commits with options '${setCommitsOption}'`); + const previousCommit = setCommitsOption.get('previous_commit'); + yield (0, cli_1.getCLI)().setCommits(release, Object.assign({ auto: false, repo: setCommitsOption.get('repo'), commit: setCommitsOption.get('commit') }, (previousCommit && { previousCommit }))); + })); + } + else if (setCommitsOption.get('mode') !== 'skip') { yield (0, telemetry_1.traceStep)('set-commits', () => __awaiter(void 0, void 0, void 0, function* () { core.debug(`Setting commits with option '${setCommitsOption}'`); yield (0, cli_1.getCLI)().setCommits(release, { @@ -122982,20 +122989,47 @@ const getBooleanOption = (input, defaultValue) => { exports.getBooleanOption = getBooleanOption; const getSetCommitsOption = () => { let setCommitOption = core.getInput('set_commits'); - // default to auto + // Default to "auto" if the input is empty or undefined if (!setCommitOption) { - return 'auto'; + return new Map([['mode', 'auto']]); } - // convert to lower case - setCommitOption = setCommitOption.toLowerCase(); + // Convert input to lower case for uniformity + setCommitOption = setCommitOption.trim().toLowerCase(); + // Create a map for the output structure + const result = new Map(); + // Handle the different cases for set_commits switch (setCommitOption) { case 'auto': - return 'auto'; + result.set('mode', 'auto'); + break; case 'skip': - return 'skip'; - default: - throw Error('set_commits must be "auto" or "skip"'); + result.set('mode', 'skip'); + break; + default: { + // Handle repo-owner/repo-name@commit or commit range + const regex = /^([\w\-]+\/[\w\-]+)@([\w\-.]+(?:\.\.|@[\w\-.]+)?)$/; + const match = regex.exec(setCommitOption); + if (!match) { + throw new Error('Invalid value for set_commits. Expected "auto", "skip", or "repo-owner/repo-name@commit" / "repo-owner/repo-name@..".'); + } + // Parse repo and commit(s) from the input + const [, repository, commitRange] = match; + result.set('mode', 'manual'); + result.set('repository', repository); + if (commitRange.includes('..')) { + // Handle commit range + const [previousCommit, currentCommit] = commitRange.split('..'); + result.set('previous_commit', previousCommit); + result.set('commit', currentCommit); + } + else { + // Single commit + result.set('commit', commitRange); + } + break; + } } + return result; }; exports.getSetCommitsOption = getSetCommitsOption; /** diff --git a/src/main.ts b/src/main.ts index daff77ce..c9c313e8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -45,9 +45,20 @@ withTelemetry( core.debug(`Release version is ${release}`); await getCLI().new(release, { projects }); - Sentry.setTag('set-commits', setCommitsOption); + Sentry.setTag('set-commits', setCommitsOption.get('mode')); - if (setCommitsOption !== 'skip') { + if (setCommitsOption.get('mode') === 'manual') { + await traceStep('set-commits', async () => { + core.debug(`Setting commits with options '${setCommitsOption}'`); + const previousCommit = setCommitsOption.get('previous_commit'); + await getCLI().setCommits(release, { + auto: false, + repo: setCommitsOption.get('repo'), + commit: setCommitsOption.get('commit'), + ...(previousCommit && { previousCommit }), + }); + }); + } else if (setCommitsOption.get('mode') !== 'skip') { await traceStep('set-commits', async () => { core.debug(`Setting commits with option '${setCommitsOption}'`); await getCLI().setCommits(release, { diff --git a/src/options.ts b/src/options.ts index a1afad80..3b09783d 100644 --- a/src/options.ts +++ b/src/options.ts @@ -127,22 +127,58 @@ export const getBooleanOption = (input: string, defaultValue: boolean): boolean throw Error(`${input} is not a boolean`); }; -export const getSetCommitsOption = (): 'auto' | 'skip' => { +export const getSetCommitsOption = (): Map => { let setCommitOption = core.getInput('set_commits'); - // default to auto + + // Default to "auto" if the input is empty or undefined if (!setCommitOption) { - return 'auto'; + return new Map([['mode', 'auto']]); } - // convert to lower case - setCommitOption = setCommitOption.toLowerCase(); + + // Convert input to lower case for uniformity + setCommitOption = setCommitOption.trim().toLowerCase(); + + // Create a map for the output structure + const result = new Map(); + + // Handle the different cases for set_commits switch (setCommitOption) { case 'auto': - return 'auto'; + result.set('mode', 'auto'); + break; case 'skip': - return 'skip'; - default: - throw Error('set_commits must be "auto" or "skip"'); + result.set('mode', 'skip'); + break; + default: { + // Handle repo-owner/repo-name@commit or commit range + const regex = /^([\w\-]+\/[\w\-]+)@([\w\-.]+(?:\.\.|@[\w\-.]+)?)$/; + const match = regex.exec(setCommitOption); + + if (!match) { + throw new Error( + 'Invalid value for set_commits. Expected "auto", "skip", or "repo-owner/repo-name@commit" / "repo-owner/repo-name@..".' + ); + } + + // Parse repo and commit(s) from the input + const [, repository, commitRange] = match; + result.set('mode', 'manual'); + result.set('repository', repository); + + if (commitRange.includes('..')) { + // Handle commit range + const [previousCommit, currentCommit] = commitRange.split('..'); + result.set('previous_commit', previousCommit); + result.set('commit', currentCommit); + } else { + // Single commit + result.set('commit', commitRange); + } + break; + } } + + return result; }; /**