mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
make logging of git diff unconditional, remove parameter
This commit is contained in:
parent
6fb8550919
commit
91ec427695
15
README.md
15
README.md
@ -362,21 +362,6 @@ be needed. (use with care).
|
||||
_**required:** `false`_
|
||||
_**default:** false_
|
||||
|
||||
#### logDiffIfDirty
|
||||
|
||||
Print a summary of changed files if the branch is determined to be dirty.
|
||||
This can be useful in debugging the reason your project files changed unexpectedly.
|
||||
This option works independently of `allowDirtyBuild`.
|
||||
|
||||
```yaml
|
||||
- uses: webbertakken/unity-builder@<version>
|
||||
with:
|
||||
logDiffIfDirty: true
|
||||
```
|
||||
|
||||
_**required:** `false`_
|
||||
_**default:** false_
|
||||
|
||||
#### customParameters
|
||||
|
||||
Custom parameters to configure the build.
|
||||
|
@ -79,14 +79,7 @@ inputs:
|
||||
Note that it is generally bad practice to modify your branch
|
||||
in a CI Pipeline. However there are exceptions where this might
|
||||
be needed. (use with care).
|
||||
logDiffIfDirty:
|
||||
required: false
|
||||
default: ''
|
||||
description: >
|
||||
Print a summary of changed files if the branch is determined to be dirty.
|
||||
|
||||
This can be useful in debugging the reason your project files changed unexpectedly.
|
||||
This option works independently of allowDirtyBuild.
|
||||
outputs: {}
|
||||
branding:
|
||||
icon: 'box'
|
||||
|
File diff suppressed because one or more lines are too long
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user