make logging of git diff unconditional, remove parameter
This commit is contained in:
@@ -77,12 +77,6 @@ class Input {
|
||||
return input === 'true' ? 'true' : 'false';
|
||||
}
|
||||
|
||||
static get logDiffIfDirty() {
|
||||
const input = core.getInput('logDiffIfDirty') || 'false';
|
||||
|
||||
return input === 'true' ? 'true' : 'false';
|
||||
}
|
||||
|
||||
static get customParameters() {
|
||||
return core.getInput('customParameters') || '';
|
||||
}
|
||||
|
||||
@@ -232,24 +232,6 @@ describe('Input', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('logDiffIfDirty', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.logDiffIfDirty).toStrictEqual('false');
|
||||
});
|
||||
|
||||
it('returns true when string true is passed', () => {
|
||||
const spy = jest.spyOn(core, 'getInput').mockReturnValue('true');
|
||||
expect(Input.logDiffIfDirty).toStrictEqual('true');
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('returns false when string false is passed', () => {
|
||||
const spy = jest.spyOn(core, 'getInput').mockReturnValue('false');
|
||||
expect(Input.logDiffIfDirty).toStrictEqual('false');
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('customParameters', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.customParameters).toStrictEqual('');
|
||||
|
||||
@@ -13,10 +13,6 @@ export default class Versioning {
|
||||
return Input.allowDirtyBuild === 'true';
|
||||
}
|
||||
|
||||
static get logDiffIfDirty() {
|
||||
return Input.logDiffIfDirty === 'true';
|
||||
}
|
||||
|
||||
static get strategies() {
|
||||
return { None: 'None', Semantic: 'Semantic', Tag: 'Tag', Custom: 'Custom' };
|
||||
}
|
||||
@@ -50,6 +46,20 @@ export default class Versioning {
|
||||
return process.env.GITHUB_SHA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum number of lines to print when logging the git diff
|
||||
*/
|
||||
static get maxDiffLines() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log up to maxDiffLines of the git diff.
|
||||
*/
|
||||
static async logDiff() {
|
||||
this.git(['--no-pager', 'diff', '|', 'head', '-n', this.maxDiffLines.toString()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regex to parse version description into separate fields
|
||||
*/
|
||||
@@ -99,6 +109,8 @@ export default class Versioning {
|
||||
static async generateSemanticVersion() {
|
||||
await this.fetch();
|
||||
|
||||
await this.logDiff();
|
||||
|
||||
if ((await this.isDirty()) && !this.isDirtyAllowed) {
|
||||
throw new Error('Branch is dirty. Refusing to base semantic version on uncommitted changes');
|
||||
}
|
||||
@@ -182,12 +194,7 @@ export default class Versioning {
|
||||
static async isDirty() {
|
||||
const output = await this.git(['status', '--porcelain']);
|
||||
|
||||
const dirty = output !== '';
|
||||
if (dirty && this.logDiffIfDirty) {
|
||||
await this.git(['--no-pager', 'diff']);
|
||||
}
|
||||
|
||||
return dirty;
|
||||
return output !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -100,32 +100,26 @@ describe('Versioning', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('logDiffIfDirty', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => Versioning.logDiffIfDirty).not.toThrow();
|
||||
});
|
||||
|
||||
it('returns false by default', () => {
|
||||
expect(Versioning.logDiffIfDirty).toStrictEqual(false);
|
||||
});
|
||||
|
||||
it('does not call git diff if logDiffIfDirty is false', async () => {
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('false');
|
||||
const gitSpy = jest.spyOn(Versioning, 'git').mockReturnValue('');
|
||||
await Versioning.isDirty();
|
||||
expect(gitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(gitSpy).toBeCalledWith(['status', '--porcelain']);
|
||||
});
|
||||
|
||||
it('calls git diff if logDiffIfDirty is true', async () => {
|
||||
describe('logging git diff', () => {
|
||||
it('calls git diff', async () => {
|
||||
// allowDirtyBuild: true
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('true');
|
||||
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(false);
|
||||
jest.spyOn(Versioning, 'fetch').mockResolvedValue(undefined);
|
||||
jest.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(true);
|
||||
jest
|
||||
.spyOn(Versioning, 'parseSemanticVersion')
|
||||
.mockResolvedValue({ tag: 'mocktag', commits: 'abcdef', hash: '75822BCAF' });
|
||||
const logDiffSpy = jest.spyOn(Versioning, 'logDiff');
|
||||
const gitSpy = jest
|
||||
.spyOn(Versioning, 'git')
|
||||
.mockReturnValue('There is a diff actually! \n M My_Dirty_File.txt');
|
||||
await Versioning.isDirty();
|
||||
expect(gitSpy).toHaveBeenCalledTimes(2);
|
||||
expect(Versioning.git.mock.calls[0][0].indexOf('status')).toBeGreaterThan(-1);
|
||||
expect(Versioning.git.mock.calls[1][0].indexOf('diff')).toBeGreaterThan(-1);
|
||||
|
||||
await Versioning.generateSemanticVersion();
|
||||
|
||||
expect(logDiffSpy).toHaveBeenCalledTimes(1);
|
||||
expect(gitSpy).toHaveBeenCalledTimes(1);
|
||||
expect(Versioning.git.mock.calls[0][0].indexOf('diff')).toBeGreaterThan(-1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user