mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-01-29 12:19:06 +08:00
Compare commits
8 Commits
v2.0-alpha
...
v2.0-alpha
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8202c01e7 | ||
|
|
9f510401e2 | ||
|
|
32acb22fec | ||
|
|
602b0b45d7 | ||
|
|
9c804d98a0 | ||
|
|
042fb6ae32 | ||
|
|
df7d1e1e25 | ||
|
|
9707ad7ad5 |
@@ -19,7 +19,7 @@ When fixing a bug it is fine to submit a pull request right away.
|
||||
|
||||
Steps to be performed to submit a pull request:
|
||||
|
||||
1. Fork the repository and create your branch from `master`.
|
||||
1. Fork the repository and create your branch from `main`.
|
||||
2. Run `yarn` in the repository root.
|
||||
3. If you've fixed a bug or added code that should be tested, add tests!
|
||||
4. Fill out the description, link any related issues and submit your pull request.
|
||||
|
||||
25
README.md
25
README.md
@@ -1,15 +1,12 @@
|
||||
<div align="center">
|
||||
<a href="https://github.com/marketplace/actions/unity-builder">
|
||||
<img width="800" src="media/UnityBuilder-Logo.png" alt="Unity Builder">
|
||||
</a>
|
||||
<br />
|
||||
<br />
|
||||
# Unity - Builder
|
||||
|
||||
(Not affiliated with Unity Technologies)
|
||||
|
||||
GitHub Action to
|
||||
[build Unity projects](https://github.com/marketplace/actions/unity-builder)
|
||||
for different platforms.
|
||||
|
||||
Part of the <a href="https://unity-ci.com"><img height="30" src="media/UnityCI-ReferenceLogo.png" alt="Unity CI"></a> open source project.
|
||||
Part of the <a href="https://game.ci">GameCI</a> open source project.
|
||||
<br />
|
||||
<br />
|
||||
|
||||
@@ -19,30 +16,28 @@ Part of the <a href="https://unity-ci.com"><img height="30" src="media/UnityCI-R
|
||||
<br />
|
||||
<br />
|
||||
|
||||
</div>
|
||||
|
||||
## How to use
|
||||
|
||||
Find the
|
||||
[docs](https://unity-ci.com/docs/github)
|
||||
on the Unity CI
|
||||
[website](https://unity-ci.com/).
|
||||
[docs](https://game.ci/docs)
|
||||
on the GameCI
|
||||
[website](https://game.ci/).
|
||||
|
||||
## Related actions
|
||||
|
||||
Visit the
|
||||
<a href="https://github.com/webbertakken/unity-actions"><img height="30" src="media/UnityActions-ReferenceLogo.png" alt="Unity Actions"></a>
|
||||
GameCI <a href="https://github.com/game-ci/unity-actions">Unity Actions</a>
|
||||
status repository for related Actions.
|
||||
|
||||
## Community
|
||||
|
||||
Feel free to join us on
|
||||
<a href="http://unity-ci.com/discord"><img height="30" src="media/Discord-Logo.svg" alt="Discord" /></a>
|
||||
<a href="http://game.ci/discord"><img height="30" src="media/Discord-Logo.svg" alt="Discord" /></a>
|
||||
and engage with the community.
|
||||
|
||||
## Contributing
|
||||
|
||||
To help out sharpen the documentation, please find the docs [repository](https://github.com/Unity-CI/Website).
|
||||
To help improve the documentation, please find the docs [repository](https://github.com/game-ci/documentation).
|
||||
|
||||
To contribute to Unity Builder, kindly read the [contribution guide](./CONTRIBUTING.md).
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ description: 'Build Unity projects for different platforms.'
|
||||
inputs:
|
||||
unityVersion:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'Version of unity to use for building the project.'
|
||||
default: 'auto'
|
||||
description: 'Version of unity to use for building the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt'
|
||||
customImage:
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
@@ -18,12 +18,22 @@ namespace UnityBuilderAction
|
||||
|
||||
// Gather values from project
|
||||
var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();
|
||||
|
||||
// Get all buildOptions from options
|
||||
BuildOptions buildOptions = BuildOptions.None;
|
||||
foreach (string buildOptionString in Enum.GetNames(typeof(BuildOptions))) {
|
||||
if (options.ContainsKey(buildOptionString)) {
|
||||
BuildOptions buildOptionEnum = (BuildOptions) Enum.Parse(typeof(BuildOptions), buildOptionString);
|
||||
buildOptions |= buildOptionEnum;
|
||||
}
|
||||
}
|
||||
|
||||
// Define BuildPlayer Options
|
||||
var buildOptions = new BuildPlayerOptions {
|
||||
var buildPlayerOptions = new BuildPlayerOptions {
|
||||
scenes = scenes,
|
||||
locationPathName = options["customBuildPath"],
|
||||
target = (BuildTarget) Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
|
||||
options = buildOptions
|
||||
};
|
||||
|
||||
// Set version for this build
|
||||
@@ -31,11 +41,11 @@ namespace UnityBuilderAction
|
||||
VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]);
|
||||
|
||||
// Apply Android settings
|
||||
if (buildOptions.target == BuildTarget.Android)
|
||||
if (buildPlayerOptions.target == BuildTarget.Android)
|
||||
AndroidSettings.Apply(options);
|
||||
|
||||
// Perform build
|
||||
BuildReport buildReport = BuildPipeline.BuildPlayer(buildOptions);
|
||||
BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
|
||||
// Summary
|
||||
BuildSummary summary = buildReport.summary;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -68,7 +68,7 @@ fi
|
||||
if [[ -z $ANDROID_KEYSTORE_NAME || -z $ANDROID_KEYSTORE_BASE64 ]]; then
|
||||
echo "Not creating Android keystore."
|
||||
else
|
||||
echo "$ANDROID_KEYSTORE_BASE64" | base64 --decode > "$ANDROID_KEYSTORE_NAME"
|
||||
echo "$ANDROID_KEYSTORE_BASE64" | base64 --decode > "$UNITY_PROJECT_PATH/$ANDROID_KEYSTORE_NAME"
|
||||
echo "Created Android keystore."
|
||||
fi
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 71 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 48 KiB |
@@ -1,6 +1,7 @@
|
||||
import AndroidVersioning from './android-versioning';
|
||||
import Input from './input';
|
||||
import Platform from './platform';
|
||||
import UnityVersioning from './unity-versioning';
|
||||
import Versioning from './versioning';
|
||||
|
||||
class BuildParameters {
|
||||
@@ -10,6 +11,12 @@ class BuildParameters {
|
||||
Input.targetPlatform,
|
||||
Input.androidAppBundle,
|
||||
);
|
||||
|
||||
const unityVersion = UnityVersioning.determineUnityVersion(
|
||||
Input.projectPath,
|
||||
Input.unityVersion,
|
||||
);
|
||||
|
||||
const buildVersion = await Versioning.determineVersion(
|
||||
Input.versioningStrategy,
|
||||
Input.specifiedVersion,
|
||||
@@ -21,7 +28,7 @@ class BuildParameters {
|
||||
);
|
||||
|
||||
return {
|
||||
version: Input.unityVersion,
|
||||
version: unityVersion,
|
||||
customImage: Input.customImage,
|
||||
|
||||
runnerTempPath: process.env.RUNNER_TEMP,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Versioning from './versioning';
|
||||
import UnityVersioning from './unity-versioning';
|
||||
import BuildParameters from './build-parameters';
|
||||
import Input from './input';
|
||||
import Platform from './platform';
|
||||
@@ -7,6 +8,10 @@ const determineVersion = jest
|
||||
.spyOn(Versioning, 'determineVersion')
|
||||
.mockImplementation(() => '1.3.37');
|
||||
|
||||
const determineUnityVersion = jest
|
||||
.spyOn(UnityVersioning, 'determineUnityVersion')
|
||||
.mockImplementation(() => '2019.2.11f1');
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
@@ -22,12 +27,9 @@ describe('BuildParameters', () => {
|
||||
expect(determineVersion).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('returns the version', async () => {
|
||||
const mockValue = 'someVersion';
|
||||
jest.spyOn(Input, 'unityVersion', 'get').mockReturnValue(mockValue);
|
||||
await expect(BuildParameters.create()).resolves.toEqual(
|
||||
expect.objectContaining({ version: mockValue }),
|
||||
);
|
||||
it('determines the unity version only once', async () => {
|
||||
await BuildParameters.create();
|
||||
expect(determineUnityVersion).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('returns the android version code with provided input', async () => {
|
||||
|
||||
@@ -51,7 +51,7 @@ class ImageTag {
|
||||
facebook,
|
||||
} = ImageTag.imageSuffixes;
|
||||
|
||||
const [major, minor] = version.split('.');
|
||||
const [major, minor] = version.split('.').map((digit) => Number(digit));
|
||||
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
|
||||
switch (platform) {
|
||||
case Platform.types.StandaloneOSX:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ImageTag from './image-tag';
|
||||
|
||||
describe('UnityImageVersion', () => {
|
||||
describe('ImageTag', () => {
|
||||
const some = {
|
||||
repository: 'test1',
|
||||
name: 'test2',
|
||||
|
||||
@@ -9,7 +9,7 @@ const core = require('@actions/core');
|
||||
*/
|
||||
class Input {
|
||||
static get unityVersion() {
|
||||
return core.getInput('unityVersion');
|
||||
return core.getInput('unityVersion') || 'auto';
|
||||
}
|
||||
|
||||
static get customImage() {
|
||||
|
||||
@@ -10,7 +10,7 @@ afterEach(() => {
|
||||
describe('Input', () => {
|
||||
describe('unityVersion', () => {
|
||||
it('returns the default value', () => {
|
||||
expect(Input.unityVersion).toStrictEqual('');
|
||||
expect(Input.unityVersion).toStrictEqual('auto');
|
||||
});
|
||||
|
||||
it('takes input from the users workflow', () => {
|
||||
|
||||
33
src/model/unity-versioning.js
Normal file
33
src/model/unity-versioning.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export default class UnityVersioning {
|
||||
static get versionPattern() {
|
||||
return /20\d{2}\.\d\.\w{3,4}|3/;
|
||||
}
|
||||
|
||||
static determineUnityVersion(projectPath, unityVersion) {
|
||||
if (unityVersion === 'auto') {
|
||||
return UnityVersioning.read(projectPath);
|
||||
}
|
||||
return unityVersion;
|
||||
}
|
||||
|
||||
static read(projectPath) {
|
||||
const filePath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
core.warning(`Could not find "${filePath}", keeping unityVersion as "auto"`);
|
||||
return 'auto';
|
||||
}
|
||||
return UnityVersioning.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
|
||||
static parse(projectVersionTxt) {
|
||||
const matches = projectVersionTxt.match(UnityVersioning.versionPattern);
|
||||
if (!matches || matches.length === 0) {
|
||||
throw new Error(`Failed to parse version from "${projectVersionTxt}".`);
|
||||
}
|
||||
return matches[0];
|
||||
}
|
||||
}
|
||||
35
src/model/unity-versioning.test.js
Normal file
35
src/model/unity-versioning.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import UnityVersioning from './unity-versioning';
|
||||
|
||||
describe('Unity Versioning', () => {
|
||||
describe('parse', () => {
|
||||
it('throws for empty string', () => {
|
||||
expect(() => UnityVersioning.parse('')).toThrow(Error);
|
||||
});
|
||||
|
||||
it('parses from ProjectVersion.txt', () => {
|
||||
const projectVersionContents = `m_EditorVersion: 2019.2.11f1
|
||||
m_EditorVersionWithRevision: 2019.2.11f1 (5f859a4cfee5)`;
|
||||
expect(UnityVersioning.parse(projectVersionContents)).toBe('2019.2.11f1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('read', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => UnityVersioning.read('')).not.toThrow();
|
||||
});
|
||||
|
||||
it('reads from test-project', () => {
|
||||
expect(UnityVersioning.read('./test-project')).toBe('2019.2.11f1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('determineUnityVersion', () => {
|
||||
it('defaults to parsed version', () => {
|
||||
expect(UnityVersioning.determineUnityVersion('./test-project', 'auto')).toBe('2019.2.11f1');
|
||||
});
|
||||
|
||||
it('use specified unityVersion', () => {
|
||||
expect(UnityVersioning.determineUnityVersion('./test-project', '1.2.3')).toBe('1.2.3');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user