Skip to content

Commit

Permalink
feat: return git tag and head commit in the output (#1359)
Browse files Browse the repository at this point in the history
* feat: return git tag and head commit in the output

* test: fix tests

* test: fix tests

* style: fix format
  • Loading branch information
xtazz authored May 26, 2023
1 parent f3412b2 commit 9e67b49
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 13 additions & 7 deletions src/utilities/outputParsers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -28,7 +28,7 @@ describe('reportResults', (): void => {

reportResults(input);

expect(setOutputSpy).toHaveBeenCalledTimes(6);
expect(setOutputSpy).toHaveBeenCalledTimes(8);
expect(setOutputSpy).toHaveBeenCalledWith(
'version',
input.nextRelease.version,
Expand All @@ -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 => {
Expand All @@ -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');
});
Expand Down
5 changes: 5 additions & 0 deletions src/utilities/outputParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
};

0 comments on commit 9e67b49

Please sign in to comment.