fix: make v character in version tags optional (#423)

* fix: make v character in version tags optional

* fix: cross platform regex

* fix: test regex within grep.

* fix: add semantic tags prepended with v
This commit is contained in:
Webber Takken
2022-08-04 02:09:32 +02:00
committed by GitHub
parent c068855899
commit db2d8b6dbd
7 changed files with 165 additions and 16 deletions

View File

@@ -2,6 +2,7 @@ import * as core from '@actions/core';
import NotImplementedException from './error/not-implemented-exception';
import System from './system';
import Versioning from './versioning';
import { validVersionTagInputs, invalidVersionTagInputs } from './__data__/versions';
afterEach(() => {
jest.restoreAllMocks();
@@ -34,6 +35,26 @@ describe('Versioning', () => {
});
});
describe('grepCompatibleInputVersionRegex', () => {
// eslint-disable-next-line unicorn/consistent-function-scoping
const matchInputUsingGrep = async (input) => {
const output = await System.run('sh', undefined, {
input: Buffer.from(`echo '${input}' | grep -E '${Versioning.grepCompatibleInputVersionRegex}'`),
silent: true,
});
return output.trim();
};
it.concurrent.each(validVersionTagInputs)(`accepts valid tag input '%s'`, async (input) => {
expect(await matchInputUsingGrep(input)).toStrictEqual(input);
});
it.concurrent.each(invalidVersionTagInputs)(`rejects non-version tag input '%s'`, async (input) => {
await expect(async () => matchInputUsingGrep(input)).rejects.toThrowError(/^Failed to run/);
});
});
describe('branch', () => {
it('returns headRef when set', () => {
const headReference = jest.spyOn(Versioning, 'headRef', 'get').mockReturnValue('feature-branch-1');