diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b64977d..a32275f 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -6,11 +6,12 @@ import { getSourcemaps, getStartedAt, getVersion, -} from '../src/validate' + getSetCommitsOption, +} from '../src/validate'; describe('validate', () => { beforeAll(() => { - process.env['MOCK'] = "true"; + process.env['MOCK'] = 'true'; }); describe('getShouldFinalize', () => { @@ -50,7 +51,8 @@ describe('validate', () => { }); describe('getStartedAt', () => { - const errorMessage = 'started_at not in valid format. Unix timestamp or ISO 8601 date expected'; + const errorMessage = + 'started_at not in valid format. Unix timestamp or ISO 8601 date expected'; afterEach(() => { delete process.env['INPUT_STARTED_AT']; }); @@ -86,7 +88,7 @@ describe('validate', () => { }); describe('getVersion', () => { - const MOCK_VERSION = "releases propose-version"; + const MOCK_VERSION = 'releases propose-version'; afterEach(() => { delete process.env['INPUT_VERSION']; delete process.env['INPUT_VERSION_PREFIX']; @@ -94,21 +96,43 @@ describe('validate', () => { test('should strip refs from version', async () => { process.env['INPUT_VERSION'] = 'refs/tags/v1.0.0'; - expect(await getVersion()).toBe('v1.0.0') + expect(await getVersion()).toBe('v1.0.0'); }); test('should get version from inputs', async () => { process.env['INPUT_VERSION'] = 'v1.0.0'; - expect(await getVersion()).toBe('v1.0.0') + expect(await getVersion()).toBe('v1.0.0'); }); test('should propose-version when version is omitted', async () => { - expect(await getVersion()).toBe(MOCK_VERSION) + expect(await getVersion()).toBe(MOCK_VERSION); }); test('should include prefix in version', async () => { process.env['INPUT_VERSION_PREFIX'] = 'prefix-'; - expect(await getVersion()).toBe(`prefix-${MOCK_VERSION}`) + expect(await getVersion()).toBe(`prefix-${MOCK_VERSION}`); + }); + }); + describe('getSetCommitsOption', () => { + afterEach(() => { + delete process.env['INPUT_SET_COMMITS']; + }); + + it('no option', () => { + expect(getSetCommitsOption()).toBe('auto'); + }); + it('auto', () => { + process.env['INPUT_SET_COMMITS'] = 'auto'; + expect(getSetCommitsOption()).toBe('auto'); + }); + it('skip', () => { + process.env['INPUT_SET_COMMITS'] = 'skip'; + expect(getSetCommitsOption()).toBe('skip'); + }); + it('bad option', () => { + const errorMessage = 'set-commits must be "auto" or "skip"'; + process.env['INPUT_SET_COMMITS'] = 'bad'; + expect(() => getSetCommitsOption()).toThrow(errorMessage); }); }); }); diff --git a/src/main.ts b/src/main.ts index a91bcaf..b7e5aed 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,14 +12,17 @@ import * as validate from './validate'; const sourcemaps = validate.getSourcemaps(); const shouldFinalize = validate.getShouldFinalize(); const deployStartedAtOption = validate.getStartedAt(); + const setCommitsOption = validate.getSetCommitsOption(); const version = await validate.getVersion(); core.debug(`Version is ${version}`); await cli.new(version); - core.debug(`Setting commits`); - await cli.setCommits(version, {auto: true}); + if (setCommitsOption !== 'skip') { + core.debug(`Setting commits with option '${setCommitsOption}'`); + await cli.setCommits(version, {auto: true}); + } if (sourcemaps) { core.debug(`Adding sourcemaps`); diff --git a/src/validate.ts b/src/validate.ts index 8d91021..0fdf9f6 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -104,6 +104,24 @@ export const getShouldFinalize = (): boolean => { throw Error('finalize is not a boolean'); }; +export const getSetCommitsOption = (): 'auto' | 'skip' => { + let setCommitOption = core.getInput('set_commits'); + // default to auto + if (!setCommitOption) { + return 'auto'; + } + // convert to lower case + setCommitOption = setCommitOption.toLowerCase(); + switch (setCommitOption) { + case 'auto': + return 'auto'; + case 'skip': + return 'skip'; + default: + throw Error('set-commits must be "auto" or "skip"'); + } +}; + /** * Check for required environment variables. */