Skip to content

Commit e96ef20

Browse files
feat: Add support for setting manual commit range (#291)
* Add support for "manual" in set-commits * Run yarn commands * Update the API per PR conversations * Remove input_commit_range * Add yarn-build changes * Refactor to add repo, commit and previous_commit options * Limit perimissions for e2e tests * Add changelog entry * Add missing auth token * Set e2e test as mock --------- Co-authored-by: Trevor White <[email protected]>
1 parent d54ba90 commit e96ef20

File tree

8 files changed

+240
-90
lines changed

8 files changed

+240
-90
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ jobs:
143143
matrix:
144144
os: [ubuntu-latest, windows-latest, macos-latest]
145145
runs-on: ${{ matrix.os }}
146+
permissions:
147+
contents: read
146148
name: Test current action
147149
steps:
148150
- uses: actions/checkout@v4
@@ -160,6 +162,8 @@ jobs:
160162
test-runs-on-container:
161163
needs: docker-build
162164
runs-on: ubuntu-latest
165+
permissions:
166+
contents: read
163167
container:
164168
image: node:20.19.2
165169

@@ -183,6 +187,8 @@ jobs:
183187
os: [ubuntu-latest, windows-latest, macos-latest]
184188
runs-on: ${{ matrix.os }}
185189
name: Mock a release
190+
permissions:
191+
contents: read
186192
steps:
187193
- uses: actions/checkout@v4
188194
with:
@@ -202,6 +208,8 @@ jobs:
202208
os: [ubuntu-latest, windows-latest, macos-latest]
203209
runs-on: ${{ matrix.os }}
204210
name: Mock a release in a different working directory
211+
permissions:
212+
contents: read
205213
steps:
206214
- name: Checkout directory we'll be running from
207215
uses: actions/checkout@v4
@@ -231,6 +239,8 @@ jobs:
231239
node-version: ['20.x', '22.x']
232240
runs-on: ${{ matrix.os }}
233241
name: Test Node version preserved on ${{ matrix.os }} with Node ${{ matrix.node-version }}
242+
permissions:
243+
contents: read
234244
steps:
235245
- uses: actions/checkout@v4
236246
with:
@@ -266,4 +276,33 @@ jobs:
266276
echo "ERROR: Node version changed from ${{ steps.node_before.outputs.VERSION }} to $VERSION_AFTER"
267277
exit 1
268278
fi
279+
269280
echo "SUCCESS: Node version preserved"
281+
282+
test-manual-commit-range:
283+
needs: docker-build
284+
285+
strategy:
286+
matrix:
287+
os: [ubuntu-latest, windows-latest, macos-latest]
288+
runs-on: ${{ matrix.os }}
289+
name: Test manual commit range
290+
permissions:
291+
contents: read
292+
steps:
293+
- uses: actions/checkout@v4
294+
with:
295+
fetch-depth: 0
296+
297+
- name: Create a release with manual commit range
298+
uses: ./
299+
env:
300+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
301+
SENTRY_LOG_LEVEL: debug
302+
MOCK: true
303+
with:
304+
environment: production
305+
set_commits: manual
306+
repo: getsentry/action-release
307+
commit: ${{ github.sha }}
308+
previous_commit: ${{ github.sha }}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# Changelog
22

3+
## 3.4.0
4+
5+
- feat: Add support for setting manual commit range (#291) by @andreiborza
6+
7+
Work in this release was contributed by @trevorkwhite. Thank you for your contribution!
8+
39
## 3.3.0
410

511
### Various fixes & improvements
612

713
- chore: pin cache action (#290) by @saibotk
814
- chore: Set docker tag for master [skip ci] (ae1d1cd5) by @getsantry[bot]
915

16+
Work in this release was contributed by @saibotk. Thank you for your contribution!
17+
1018
## 3.2.0
1119

1220
### Various fixes & improvements

README.md

Lines changed: 85 additions & 73 deletions
Large diffs are not rendered by default.

__tests__/main.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getProjects,
1212
getUrlPrefixOption,
1313
getWorkingDirectory,
14+
getSetCommitsManualOptions,
1415
} from '../src/options';
1516

1617
describe('options', () => {
@@ -196,13 +197,37 @@ describe('options', () => {
196197
process.env['INPUT_SET_COMMITS'] = 'skip';
197198
expect(getSetCommitsOption()).toBe('skip');
198199
});
200+
it('manual', () => {
201+
process.env['INPUT_SET_COMMITS'] = 'manual';
202+
expect(getSetCommitsOption()).toBe('manual');
203+
});
199204
it('bad option', () => {
200-
const errorMessage = 'set_commits must be "auto" or "skip"';
205+
const errorMessage = 'set_commits must be "auto", "skip" or "manual"';
201206
process.env['INPUT_SET_COMMITS'] = 'bad';
202207
expect(() => getSetCommitsOption()).toThrow(errorMessage);
203208
});
204209
});
205210

211+
describe('getSetCommitsManualOptions', () => {
212+
afterEach(() => {
213+
delete process.env['INPUT_SET_COMMITS'];
214+
delete process.env['INPUT_REPO'];
215+
delete process.env['INPUT_COMMIT'];
216+
delete process.env['INPUT_PREVIOUS_COMMIT'];
217+
});
218+
it('manual', () => {
219+
process.env['INPUT_SET_COMMITS'] = 'manual';
220+
process.env['INPUT_REPO'] = 'repo';
221+
process.env['INPUT_COMMIT'] = 'commit';
222+
process.env['INPUT_PREVIOUS_COMMIT'] = 'previous-commit';
223+
expect(getSetCommitsManualOptions()).toEqual({
224+
repo: 'repo',
225+
commit: 'commit',
226+
previousCommit: 'previous-commit',
227+
});
228+
});
229+
});
230+
206231
describe('getProjects', () => {
207232
afterEach(() => {
208233
delete process.env['SENTRY_PROJECT'];

action.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,23 @@ inputs:
7676
set_commits:
7777
description: |-
7878
Specify whether to set commits for the release.
79-
One of: "auto", "skip"
79+
When "manual", you need to provide the repository, commit, and previous commit.
80+
One of: "auto", "skip", "manual"
81+
required: false
82+
repo:
83+
description: |-
84+
The repository to set commits for in "repo-owner/repo-name" format.
85+
Only used when "set_commits" is "manual".
86+
required: false
87+
commit:
88+
description: |-
89+
The commit SHA of the current release you are creating.
90+
Only used when "set_commits" is "manual".
91+
required: false
92+
previous_commit:
93+
description: |-
94+
The commit SHA of the previous release.
95+
Required when "set_commits" is "manual".
8096
required: false
8197
projects:
8298
description: |-
@@ -142,13 +158,16 @@ runs:
142158
INPUT_VERSION_PREFIX: ${{ inputs.version_prefix }}
143159
INPUT_RELEASE_PREFIX: ${{ inputs.release_prefix }}
144160
INPUT_SET_COMMITS: ${{ inputs.set_commits }}
161+
INPUT_REPO: ${{ inputs.repo }}
162+
INPUT_COMMIT: ${{ inputs.commit }}
163+
INPUT_PREVIOUS_COMMIT: ${{ inputs.previous_commit }}
145164
INPUT_PROJECTS: ${{ inputs.projects }}
146165
INPUT_URL_PREFIX: ${{ inputs.url_prefix }}
147166
INPUT_STRIP_COMMON_PREFIX: ${{ inputs.strip_common_prefix }}
148167
INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }}
149168
INPUT_DISABLE_TELEMETRY: ${{ inputs.disable_telemetry }}
150169
INPUT_DISABLE_SAFE_DIRECTORY: ${{ inputs.disable_safe_directory }}
151-
uses: docker://ghcr.io/getsentry/action-release-image:master
170+
uses: docker://ghcr.io/getsentry/action-release-image:ab-add-manual-commit-range
152171

153172
# For actions running on macos or windows runners, we use a composite
154173
# action approach which allows us to install the arch specific sentry-cli
@@ -204,6 +223,9 @@ runs:
204223
INPUT_VERSION_PREFIX: ${{ inputs.version_prefix }}
205224
INPUT_RELEASE_PREFIX: ${{ inputs.release_prefix }}
206225
INPUT_SET_COMMITS: ${{ inputs.set_commits }}
226+
INPUT_REPO: ${{ inputs.repo }}
227+
INPUT_COMMIT: ${{ inputs.commit }}
228+
INPUT_PREVIOUS_COMMIT: ${{ inputs.previous_commit }}
207229
INPUT_PROJECTS: ${{ inputs.projects }}
208230
INPUT_URL_PREFIX: ${{ inputs.url_prefix }}
209231
INPUT_STRIP_COMMON_PREFIX: ${{ inputs.strip_common_prefix }}

dist/index.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122752,11 +122752,21 @@ const telemetry_1 = __nccwpck_require__(12417);
122752122752
if (setCommitsOption !== 'skip') {
122753122753
yield (0, telemetry_1.traceStep)('set-commits', () => __awaiter(void 0, void 0, void 0, function* () {
122754122754
core.debug(`Setting commits with option '${setCommitsOption}'`);
122755-
yield (0, cli_1.getCLI)().setCommits(release, {
122756-
auto: true,
122757-
ignoreMissing,
122758-
ignoreEmpty,
122759-
});
122755+
if (setCommitsOption === 'auto') {
122756+
yield (0, cli_1.getCLI)().setCommits(release, {
122757+
auto: true,
122758+
ignoreMissing,
122759+
ignoreEmpty,
122760+
});
122761+
}
122762+
else if (setCommitsOption === 'manual') {
122763+
const { repo, commit, previousCommit } = options.getSetCommitsManualOptions();
122764+
if (!repo || !commit) {
122765+
throw new Error('Options `repo` and `commit` are required when `set_commits` is `manual`');
122766+
}
122767+
yield (0, cli_1.getCLI)().setCommits(release, Object.assign({ auto: false, repo,
122768+
commit }, (previousCommit && { previousCommit })));
122769+
}
122760122770
}));
122761122771
}
122762122772
Sentry.setTag('sourcemaps', sourcemaps.length > 0);
@@ -122860,7 +122870,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
122860122870
return (mod && mod.__esModule) ? mod : { "default": mod };
122861122871
};
122862122872
Object.defineProperty(exports, "__esModule", ({ value: true }));
122863-
exports.getWorkingDirectory = exports.getUrlPrefixOption = exports.getProjects = exports.checkEnvironmentVariables = exports.getSetCommitsOption = exports.getBooleanOption = exports.getDist = exports.getSourcemaps = exports.getStartedAt = exports.getEnvironment = exports.getRelease = void 0;
122873+
exports.getWorkingDirectory = exports.getUrlPrefixOption = exports.getProjects = exports.checkEnvironmentVariables = exports.getSetCommitsManualOptions = exports.getSetCommitsOption = exports.getBooleanOption = exports.getDist = exports.getSourcemaps = exports.getStartedAt = exports.getEnvironment = exports.getRelease = void 0;
122864122874
const core = __importStar(__nccwpck_require__(42186));
122865122875
const path_1 = __importDefault(__nccwpck_require__(71017));
122866122876
const cli_1 = __nccwpck_require__(56733);
@@ -122993,11 +123003,20 @@ const getSetCommitsOption = () => {
122993123003
return 'auto';
122994123004
case 'skip':
122995123005
return 'skip';
123006+
case 'manual':
123007+
return 'manual';
122996123008
default:
122997-
throw Error('set_commits must be "auto" or "skip"');
123009+
throw Error('set_commits must be "auto", "skip" or "manual"');
122998123010
}
122999123011
};
123000123012
exports.getSetCommitsOption = getSetCommitsOption;
123013+
const getSetCommitsManualOptions = () => {
123014+
const repo = core.getInput('repo');
123015+
const commit = core.getInput('commit');
123016+
const previousCommit = core.getInput('previous_commit');
123017+
return { repo, commit, previousCommit };
123018+
};
123019+
exports.getSetCommitsManualOptions = getSetCommitsManualOptions;
123001123020
/**
123002123021
* Check for required environment variables.
123003123022
*/

src/main.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,27 @@ withTelemetry(
5050
if (setCommitsOption !== 'skip') {
5151
await traceStep('set-commits', async () => {
5252
core.debug(`Setting commits with option '${setCommitsOption}'`);
53-
await getCLI().setCommits(release, {
54-
auto: true,
55-
ignoreMissing,
56-
ignoreEmpty,
57-
});
53+
54+
if (setCommitsOption === 'auto') {
55+
await getCLI().setCommits(release, {
56+
auto: true,
57+
ignoreMissing,
58+
ignoreEmpty,
59+
});
60+
} else if (setCommitsOption === 'manual') {
61+
const { repo, commit, previousCommit } = options.getSetCommitsManualOptions();
62+
63+
if (!repo || !commit) {
64+
throw new Error('Options `repo` and `commit` are required when `set_commits` is `manual`');
65+
}
66+
67+
await getCLI().setCommits(release, {
68+
auto: false,
69+
repo,
70+
commit,
71+
...(previousCommit && { previousCommit }),
72+
});
73+
}
5874
});
5975
}
6076

src/options.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const getBooleanOption = (input: string, defaultValue: boolean): boolean
127127
throw Error(`${input} is not a boolean`);
128128
};
129129

130-
export const getSetCommitsOption = (): 'auto' | 'skip' => {
130+
export const getSetCommitsOption = (): 'auto' | 'skip' | 'manual' => {
131131
let setCommitOption = core.getInput('set_commits');
132132
// default to auto
133133
if (!setCommitOption) {
@@ -140,11 +140,20 @@ export const getSetCommitsOption = (): 'auto' | 'skip' => {
140140
return 'auto';
141141
case 'skip':
142142
return 'skip';
143+
case 'manual':
144+
return 'manual';
143145
default:
144-
throw Error('set_commits must be "auto" or "skip"');
146+
throw Error('set_commits must be "auto", "skip" or "manual"');
145147
}
146148
};
147149

150+
export const getSetCommitsManualOptions = (): { repo: string; commit: string; previousCommit: string } => {
151+
const repo = core.getInput('repo');
152+
const commit = core.getInput('commit');
153+
const previousCommit = core.getInput('previous_commit');
154+
155+
return { repo, commit, previousCommit };
156+
};
148157
/**
149158
* Check for required environment variables.
150159
*/

0 commit comments

Comments
 (0)