mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
Fix versioning for push event.
This commit is contained in:
parent
40564afbaf
commit
d01e844eea
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -2,7 +2,7 @@ name: Actions 😎
|
||||
|
||||
on:
|
||||
pull_request: {}
|
||||
push: { branches: [master] }
|
||||
push: { branches: [master, debug-push-pipeline] }
|
||||
|
||||
env:
|
||||
UNITY_LICENSE: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>\n <License id=\"Terms\">\n <MachineBindings>\n <Binding Key=\"1\" Value=\"d39b8e2f4d364b2e98b06afa0c6e08c5\"/>\n <Binding Key=\"2\" Value=\"d39b8e2f4d364b2e98b06afa0c6e08c5\"/>\n </MachineBindings>\n <MachineID Value=\"Xxo1ZKbdPu/IATrc0mPBYANJFF0=\"/>\n <SerialHash Value=\"1efd68fa935192b6090ac03c77d289a9f588c55a\"/>\n <Features>\n <Feature Value=\"33\"/>\n <Feature Value=\"1\"/>\n <Feature Value=\"12\"/>\n <Feature Value=\"2\"/>\n <Feature Value=\"24\"/>\n <Feature Value=\"3\"/>\n <Feature Value=\"36\"/>\n <Feature Value=\"17\"/>\n <Feature Value=\"19\"/>\n <Feature Value=\"62\"/>\n </Features>\n <DeveloperData Value=\"AQAAAEY0LUg2WFMtUE00NS1SM0M4LUUyWlotWkdWOA==\"/>\n <SerialMasked Value=\"F4-H6XS-PM45-R3C8-E2ZZ-XXXX\"/>\n <StartDate Value=\"2018-05-02T00:00:00\"/>\n <UpdateDate Value=\"2019-11-25T18:23:38\"/>\n <InitialActivationDate Value=\"2018-05-02T14:21:28\"/>\n <LicenseVersion Value=\"6.x\"/>\n <ClientProvidedVersion Value=\"2019.2.11f1\"/>\n <AlwaysOnline Value=\"false\"/>\n <Entitlements>\n <Entitlement Ns=\"unity_editor\" Tag=\"UnityPersonal\" Type=\"EDITOR\" ValidTo=\"9999-12-31T00:00:00\"/>\n </Entitlements>\n </License>\n<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/><Reference URI=\"#Terms\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>JHdOBFmBNq2H8BrGFzir/StLoYo=</DigestValue></Reference></SignedInfo><SignatureValue>aENLHd37a51RtP2/g7YU0Pexf5mx0/ENXYGtrPzqwZ8NQt2AsSdxGnl0CUB45/GuNXfJVDt2HWot\ncNYZB2OylVBn1WHQbKZlPmm8gEAMz0MYbr4Isb5i5buryBrZlmbEOjnRI+pEg1CBwlgMo6xdtjjE\n/d7cC293QIUO91kdzRXftYou1dNaUyuPL9ZH65vdB2pDXGRNxgUVD+GnnqZA7b5L2HXqNQclcWAK\n5Yd1BeF3VzR1iLw9G/SmH5oOhnpXSmqbL4qk7LVP2/mgXpFk5kP4X8VC3z47obNhBIGq40dwWyEe\nUYk5/nRAOkZawDT+tcu96e06gPC9Cxk5PdbRbA==</SignatureValue></Signature></root>"
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,10 +1,11 @@
|
||||
import * as core from '@actions/core';
|
||||
import Unity from './unity';
|
||||
import Input from './input';
|
||||
import Action from './action';
|
||||
|
||||
class Project {
|
||||
static get relativePath() {
|
||||
const projectPath = Input.getFromUser().then(result => result.projectPath);
|
||||
// Todo - properly use Input for this.
|
||||
const projectPath = core.getInput('projectPath') || '.';
|
||||
|
||||
return `${projectPath}`;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import * as core from '@actions/core';
|
||||
import { exec } from '@actions/exec';
|
||||
|
||||
class System {
|
||||
static async run(command, arguments_, options) {
|
||||
let result = '';
|
||||
let error = '';
|
||||
let debug = '';
|
||||
|
||||
const listeners = {
|
||||
stdout: dataBuffer => {
|
||||
@ -12,13 +14,29 @@ class System {
|
||||
stderr: dataBuffer => {
|
||||
error += dataBuffer.toString();
|
||||
},
|
||||
debug: dataString => {
|
||||
debug += dataString.toString();
|
||||
},
|
||||
};
|
||||
|
||||
const exitCode = await exec(command, arguments_, { ...options, listeners });
|
||||
|
||||
if (debug !== '') {
|
||||
core.debug(debug);
|
||||
}
|
||||
|
||||
if (result !== '') {
|
||||
core.info(result);
|
||||
}
|
||||
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(error);
|
||||
}
|
||||
|
||||
if (error !== '') {
|
||||
core.warning(error);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ export default class Versioning {
|
||||
* @See: https://semver.org/
|
||||
*/
|
||||
static async generateSemanticVersion() {
|
||||
await this.fetchAll();
|
||||
await this.fetch();
|
||||
|
||||
if (await this.isDirty()) {
|
||||
throw new Error('Branch is dirty. Refusing to base semantic version on uncommitted changes');
|
||||
@ -128,8 +128,11 @@ export default class Versioning {
|
||||
}
|
||||
}
|
||||
|
||||
static async fetchAll() {
|
||||
await System.run('git', ['fetch', '--all']);
|
||||
/**
|
||||
* Retrieves refs from the configured remote, unshallow (based on actions/checkout@v2+)
|
||||
*/
|
||||
static async fetch() {
|
||||
await System.run('git', ['fetch', '--unshallow']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,7 +144,14 @@ export default class Versioning {
|
||||
* identifies the current commit.
|
||||
*/
|
||||
static async getVersionDescription() {
|
||||
return System.run('git', ['describe', '--long', '--tags', '--always', `origin/${this.branch}`]);
|
||||
return System.run('git', [
|
||||
'describe',
|
||||
'--long',
|
||||
'--tags',
|
||||
'--always',
|
||||
'--debug',
|
||||
`origin/${this.branch}`,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,4 @@
|
||||
import * as core from '@actions/core';
|
||||
import NotImplementedException from './error/not-implemented-exception';
|
||||
import System from './system';
|
||||
import Versioning from './versioning';
|
||||
@ -194,10 +195,46 @@ describe('Versioning', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchAll', () => {
|
||||
describe('fetch', () => {
|
||||
it('awaits the command', async () => {
|
||||
jest.spyOn(System, 'run').mockResolvedValue(null);
|
||||
await expect(Versioning.fetchAll()).resolves.not.toThrow();
|
||||
await expect(Versioning.fetch()).resolves.not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateSemanticVersion', () => {
|
||||
it('returns a proper version from description', async () => {
|
||||
jest.spyOn(System, 'run').mockResolvedValue(null);
|
||||
jest.spyOn(core, 'info').mockImplementation(() => {});
|
||||
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(false);
|
||||
jest.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(true);
|
||||
jest.spyOn(Versioning, 'getTotalNumberOfCommits').mockResolvedValue(2);
|
||||
jest.spyOn(Versioning, 'parseSemanticVersion').mockResolvedValue({
|
||||
match: '0.1-2-g1b345678',
|
||||
tag: '0.1',
|
||||
commits: '2',
|
||||
hash: '1b345678',
|
||||
});
|
||||
|
||||
await expect(Versioning.generateSemanticVersion()).resolves.toStrictEqual('0.1.2');
|
||||
});
|
||||
|
||||
it('throws when dirty', async () => {
|
||||
jest.spyOn(System, 'run').mockResolvedValue(null);
|
||||
jest.spyOn(core, 'info').mockImplementation(() => {});
|
||||
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(true);
|
||||
await expect(Versioning.generateSemanticVersion()).rejects.toThrowError();
|
||||
});
|
||||
|
||||
it('falls back to commits only, when no tags are present', async () => {
|
||||
const commits = Math.round(Math.random() * 10);
|
||||
jest.spyOn(System, 'run').mockResolvedValue(null);
|
||||
jest.spyOn(core, 'info').mockImplementation(() => {});
|
||||
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(false);
|
||||
jest.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(false);
|
||||
jest.spyOn(Versioning, 'getTotalNumberOfCommits').mockResolvedValue(commits);
|
||||
|
||||
await expect(Versioning.generateSemanticVersion()).resolves.toStrictEqual(`0.0.${commits}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user