From 472508c042835e90d7408aa72ffce6252f2c81aa Mon Sep 17 00:00:00 2001 From: Stephen Cefali Date: Fri, 9 Oct 2020 09:23:42 -0700 Subject: [PATCH 1/6] adds commit option --- __tests__/main.test.ts | 40 ++++++++++++++++++++++++++++++++-------- src/main.ts | 7 +++++-- src/validate.ts | 18 ++++++++++++++++++ 3 files changed, 55 insertions(+), 10 deletions(-) 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..c45dfc4 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`); + 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. */ From 3ecd67d87a18b96c96e86708c9acd418f58ccbc2 Mon Sep 17 00:00:00 2001 From: Stephen Cefali Date: Fri, 9 Oct 2020 09:42:38 -0700 Subject: [PATCH 2/6] update debug message --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index c45dfc4..6c7c341 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,8 +19,8 @@ import * as validate from './validate'; core.debug(`Version is ${version}`); await cli.new(version); + core.debug(`Setting commits with option ${setCommitsOption}`); if (setCommitsOption !== 'skip') { - core.debug(`Setting commits`); await cli.setCommits(version, {auto: true}); } From bffdc259f954c540ba7eee9fa1f5b91c66927fc8 Mon Sep 17 00:00:00 2001 From: Stephen Cefali Date: Fri, 9 Oct 2020 09:49:23 -0700 Subject: [PATCH 3/6] use dockerfile --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 38190f1..2ab5911 100644 --- a/action.yml +++ b/action.yml @@ -22,7 +22,7 @@ inputs: required: false runs: using: 'docker' - image: 'docker://sentryintegrations/sentry-github-action-release:latest' + image: 'Dockerfile' branding: icon: 'triangle' color: 'purple' From e26754a2f17db728a4870dc8cdcf95089334fb9b Mon Sep 17 00:00:00 2001 From: Stephen Cefali Date: Fri, 9 Oct 2020 09:51:26 -0700 Subject: [PATCH 4/6] change debug --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 6c7c341..3cc9641 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,7 +19,7 @@ import * as validate from './validate'; core.debug(`Version is ${version}`); await cli.new(version); - core.debug(`Setting commits with option ${setCommitsOption}`); + core.debug(`Setting commits with option '${setCommitsOption}'`); if (setCommitsOption !== 'skip') { await cli.setCommits(version, {auto: true}); } From 43dc8f05b54aef4bd0746b2dd46d52a1517e5da2 Mon Sep 17 00:00:00 2001 From: Stephen Cefali Date: Fri, 9 Oct 2020 09:55:38 -0700 Subject: [PATCH 5/6] revert action change --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2ab5911..38190f1 100644 --- a/action.yml +++ b/action.yml @@ -22,7 +22,7 @@ inputs: required: false runs: using: 'docker' - image: 'Dockerfile' + image: 'docker://sentryintegrations/sentry-github-action-release:latest' branding: icon: 'triangle' color: 'purple' From 294705049f2e5d8460c95a5160fb0f94c8c4bd51 Mon Sep 17 00:00:00 2001 From: Stephen Cefali Date: Fri, 9 Oct 2020 13:28:50 -0700 Subject: [PATCH 6/6] update debuug message --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 3cc9641..b7e5aed 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,8 +19,8 @@ import * as validate from './validate'; core.debug(`Version is ${version}`); await cli.new(version); - core.debug(`Setting commits with option '${setCommitsOption}'`); if (setCommitsOption !== 'skip') { + core.debug(`Setting commits with option '${setCommitsOption}'`); await cli.setCommits(version, {auto: true}); }