Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/action.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('packaged action with local git repositories', () => {
);
});

it.skip('reads commit messages from real GitHub push payload objects (#122)', () => {
it('reads commit messages from real GitHub push payload objects (#122)', () => {
const fixture = run({
version: '1.2.3',
commits: ['feat: add login'],
Expand Down
3 changes: 2 additions & 1 deletion src/toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as github from '@actions/github';
import fs from 'fs/promises';
import type { Commit } from './version';

type Payload = {
commits?: string[];
commits?: Commit[];
};

const inputNames = [
Expand Down
25 changes: 25 additions & 0 deletions src/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,31 @@ describe('version', () => {
});
});

it('should read commit messages from GitHub push payload objects', () => {
const commits = [
{ message: 'fix: did something' },
{ message: 'feat: added user login' },
];
const build = bumpBuild(commits, currentVersion);

expect(build).toEqual({
code: 10300,
name: '1.3.0',
version: {
major: 1,
minor: 3,
patch: 0,
},
});
});

it('should ignore malformed commit payload entries', () => {
const commits = [{ message: undefined }, { message: 42 }];
const build = bumpBuild(commits, currentVersion);

expect(build.name).toBe('1.2.4');
});

it('should bump patch, and keep major & minor the same', () => {
const commits: string[] = ['chore: did something'];
const build = bumpBuild(commits, currentVersion);
Expand Down
11 changes: 9 additions & 2 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type Build = {
code: number;
};

export type Commit = string | { message?: unknown };

const getCommitIntent = (message: string): string => {
const [commitIntent] = message.toLowerCase().split(':');

Expand Down Expand Up @@ -87,11 +89,16 @@ export const getBuildFromVersion = (version: Version): Build => {
};

export const bumpBuild = (
commits: string[],
commits: Commit[],
currentVersion: Version,
buildNumber?: string | number,
): Build => {
const semanticCommits = commits.filter(isSemanticCommit);
const semanticCommits = commits
.map((commit) => (typeof commit === 'string' ? commit : commit.message))
.filter(
(message): message is string =>
typeof message === 'string' && isSemanticCommit(message),
);
const isMajor = semanticCommits.some(isMajorBump);

if (isMajor) {
Expand Down