From 9e67b49712c5ff58cf1684191082fcd5563ab0a5 Mon Sep 17 00:00:00 2001 From: Petr Rusanov Date: Fri, 26 May 2023 15:33:04 +0200 Subject: [PATCH] feat: return git tag and head commit in the output (#1359) * feat: return git tag and head commit in the output * test: fix tests * test: fix tests * style: fix format --- action.yml | 4 ++++ src/utilities/outputParsers.spec.ts | 20 +++++++++++++------- src/utilities/outputParsers.ts | 5 +++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index fb78d5ee..a065e7df 100644 --- a/action.yml +++ b/action.yml @@ -50,6 +50,10 @@ inputs: outputs: build: description: Build component of the released version. + git-head: + description: The Git checksum of the last commit of the release. + git-tag: + description: The Git tag of the release. level: description: Released level (major, minor or patch). major: diff --git a/src/utilities/outputParsers.spec.ts b/src/utilities/outputParsers.spec.ts index e49c5a68..5708e1bb 100644 --- a/src/utilities/outputParsers.spec.ts +++ b/src/utilities/outputParsers.spec.ts @@ -7,18 +7,18 @@ const setOutputSpy = jest.spyOn(actionsCore, 'setOutput').mockImplementation(); describe('reportResults', (): void => { it('sets output based on nextRelease', (): void => { - expect.assertions(7); + expect.assertions(9); const input: Result = { commits: [], lastRelease: { - gitHead: 'refs/heads/master', - gitTag: '1.1.0', + gitHead: 'ca39a3ee5e6b4b0d3255bfef95601890afd80708', + gitTag: 'v1.1.0', version: '1.1.0', }, nextRelease: { - gitHead: 'refs/heads/master', - gitTag: '1.1.1', + gitHead: 'da39a3ee5e6b4b0d3255bfef95601890afd80709', + gitTag: 'v1.1.1', notes: 'Note', type: 'patch', version: '1.1.1', @@ -28,7 +28,7 @@ describe('reportResults', (): void => { reportResults(input); - expect(setOutputSpy).toHaveBeenCalledTimes(6); + expect(setOutputSpy).toHaveBeenCalledTimes(8); expect(setOutputSpy).toHaveBeenCalledWith( 'version', input.nextRelease.version, @@ -39,6 +39,12 @@ describe('reportResults', (): void => { expect(setOutputSpy).toHaveBeenCalledWith('major', '1'); expect(setOutputSpy).toHaveBeenCalledWith('minor', '1'); expect(setOutputSpy).toHaveBeenCalledWith('patch', '1'); + + expect(setOutputSpy).toHaveBeenCalledWith( + 'git-head', + 'da39a3ee5e6b4b0d3255bfef95601890afd80709', + ); + expect(setOutputSpy).toHaveBeenCalledWith('git-tag', 'v1.1.1'); }); it('sets prerelease and meta outputs if they are included in the version', (): void => { @@ -63,7 +69,7 @@ describe('reportResults', (): void => { reportResults(input); - expect(setOutputSpy).toHaveBeenCalledTimes(8); + expect(setOutputSpy).toHaveBeenCalledTimes(10); expect(setOutputSpy).toHaveBeenCalledWith('pre-release', 'prerelease'); expect(setOutputSpy).toHaveBeenCalledWith('build', 'build'); }); diff --git a/src/utilities/outputParsers.ts b/src/utilities/outputParsers.ts index ec0d37db..c7ee2891 100644 --- a/src/utilities/outputParsers.ts +++ b/src/utilities/outputParsers.ts @@ -3,6 +3,8 @@ import { Result } from 'semantic-release'; enum OutputParameters { Build = 'build', + GitHead = 'git-head', + GitTag = 'git-tag', Level = 'level', Major = 'major', Minor = 'minor', @@ -31,6 +33,7 @@ const extractVersionComponents = (version: string): SemVerComponents => { return groups as unknown as SemVerComponents; }; +// eslint-disable-next-line max-statements export const reportResults = (result: Result): void => { if (result === false) { setOutput(OutputParameters.Released, 'false'); @@ -60,4 +63,6 @@ export const reportResults = (result: Result): void => { setOutput(OutputParameters.Released, 'true'); setOutput(OutputParameters.Version, nextRelease.version); + setOutput(OutputParameters.GitHead, nextRelease.gitHead); + setOutput(OutputParameters.GitTag, nextRelease.gitTag); };