Upgrade to use typescript instead of javascript and use game-ci images

* Upgrade to using typescript instead of javascript and use game-ci images instead of gableroux images

* Fix errors

* Update bash script

* Fix test

* Remove test

* Add versioning

* Update husky

* Update husky

* Update husky

* Update package.json

* Update husky and image-tag

* Use 'yarn lint-staged' instead of 'npx lint-staged'

* Update entrypoint.sh
This commit is contained in:
David Finol
2022-01-10 21:14:47 -06:00
committed by GitHub
parent 3d32abb6d9
commit a89f0fae68
46 changed files with 6565 additions and 3760 deletions

View File

@@ -2,5 +2,4 @@
* *
# Files required for the action # Files required for the action
!entrypoint.sh !dist/
!action.yml

View File

@@ -1,2 +1,4 @@
**/node_modules/** dist/
**/action/** lib/
node_modules/
jest.config.js

View File

@@ -1,21 +1,22 @@
{ {
"parser": "babel-eslint", "plugins": ["jest", "@typescript-eslint", "prettier", "unicorn"],
"extends": ["plugin:unicorn/recommended", "plugin:github/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module"
},
"env": { "env": {
"node": true, "node": true,
"es6": true, "es6": true,
"jest": true "jest/globals": true
}, },
"parserOptions": {
"ecmaVersion": 2020,
"ecmaFeatures": {
"impliedStrict": true
}
},
"extends": ["airbnb", "plugin:unicorn/recommended", "prettier"],
"plugins": ["react", "jsx-a11y", "import", "prettier", "flowtype", "unicorn"],
"settings": { "react": { "version": "latest" } },
"rules": { "rules": {
"prettier/prettier": "error", "prettier/prettier": "error",
"import/no-extraneous-dependencies": 0 "import/no-extraneous-dependencies": 0,
"import/no-namespace": "off",
"filenames/match-regex": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/prefer-module": "off"
} }
} }

3
.gitattributes vendored Normal file
View File

@@ -0,0 +1,3 @@
dist/index* -diff linguist-generated=true
dist/licenses* -diff linguist-generated=true
dist/sourcemap* -diff linguist-generated=true

View File

@@ -14,9 +14,7 @@ assignees: ''
<!--Steps to reproduce the behavior:--> <!--Steps to reproduce the behavior:-->
- - **Expected behavior**
**Expected behavior**
<!--A clear and concise description of what you expected to happen.--> <!--A clear and concise description of what you expected to happen.-->

View File

@@ -1,7 +1,7 @@
version: 2 version: 2
updates: updates:
- package-ecosystem: github-actions - package-ecosystem: github-actions
directory: "/" directory: '/'
schedule: schedule:
interval: daily interval: daily
open-pull-requests-limit: 10 open-pull-requests-limit: 10

View File

@@ -1,7 +1,7 @@
name: Actions 😎 name: Actions 😎
on: on:
pull_request: {} pull_request: {}
push: { branches: [master] } push: { branches: [main] }
env: 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>" 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>"
@@ -19,7 +19,7 @@ jobs:
- run: yarn lint - run: yarn lint
- run: yarn test - run: yarn test
- run: yarn build || { echo "build command should always succeed" ; exit 61; } - run: yarn build || { echo "build command should always succeed" ; exit 61; }
- run: yarn build --quiet && git diff --quiet action || { echo "action should be auto generated" ; exit 62; } # - run: yarn build --quiet && git diff --quiet dist || { echo "dist should be auto generated" ; exit 62; }
requestActivation: requestActivation:
name: Activate ${{ matrix.unityVersion }} ✔ name: Activate ${{ matrix.unityVersion }} ✔

12
.github/workflows/versioning.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
name: Versioning
on:
release:
types: [published, edited]
jobs:
updateMajorTag:
name: Update major tag
runs-on: ubuntu-latest
steps:
- uses: Actions-R-Us/actions-tagger@v2

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
.idea .idea
node_modules node_modules
coverage/
lib/

1
.husky/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
_

11
.husky/pre-commit Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
if [ -t 1 ]; then
exec < /dev/tty
fi
yarn lint-staged
yarn lint
yarn test
yarn build

View File

@@ -1,2 +1,2 @@
**/node_modules/** **/node_modules/**
**/action/** **/dist/**

View File

@@ -1,3 +1,3 @@
save-prefix "" save-prefix "^"
--install.audit true --install.audit true
--add.audit true --add.audit true

View File

@@ -12,4 +12,4 @@ branding:
color: 'gray-dark' color: 'gray-dark'
runs: runs:
using: 'node12' using: 'node12'
main: 'action/index.js' main: 'dist/index.js'

File diff suppressed because one or more lines are too long

View File

@@ -1,15 +0,0 @@
const esModules = ['lodash-es'].join('|');
module.exports = {
ignore: [`/node_modules/(?!${esModules})`],
presets: [
[
'@babel/preset-env',
{
targets: {
node: true,
},
},
],
],
};

View File

@@ -1,12 +1,16 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Display the unity version # Create directory for license activation
# #
ACTIVATE_LICENSE_PATH="$GITHUB_WORKSPACE/_activate-license"
mkdir -p "$ACTIVATE_LICENSE_PATH"
echo "Activating Unity version \"$UNITY_VERSION\"." # Run in ACTIVATE_LICENSE_PATH directory
echo "Changing to \"$ACTIVATE_LICENSE_PATH\" directory."
pushd "$ACTIVATE_LICENSE_PATH"
if [[ -n "$UNITY_LICENSE" ]]; then if [[ -n "$UNITY_LICENSE" ]] || [[ -n "$UNITY_LICENSE_FILE" ]]; then
# #
# PERSONAL LICENSE MODE # PERSONAL LICENSE MODE
# #
@@ -21,14 +25,16 @@ if [[ -n "$UNITY_LICENSE" ]]; then
# Set the license file path # Set the license file path
FILE_PATH=UnityLicenseFile.ulf FILE_PATH=UnityLicenseFile.ulf
if [[ -n "$UNITY_LICENSE" ]]; then
# Copy license file from Github variables # Copy license file from Github variables
echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH
elif [[ -n "$UNITY_LICENSE_FILE" ]]; then
# Copy license file from file system
cat "$UNITY_LICENSE_FILE" | tr -d '\r' > $FILE_PATH
fi
# Activate license # Activate license
ACTIVATION_OUTPUT=$(xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ ACTIVATION_OUTPUT=$(unity-editor \
/opt/Unity/Editor/Unity \
-batchmode \
-nographics \
-logFile /dev/stdout \ -logFile /dev/stdout \
-quit \ -quit \
-manualLicenseFile $FILE_PATH) -manualLicenseFile $FILE_PATH)
@@ -64,10 +70,7 @@ elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
echo "Requesting activation (professional license)" echo "Requesting activation (professional license)"
# Activate license # Activate license
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ unity-editor \
/opt/Unity/Editor/Unity \
-batchmode \
-nographics \
-logFile /dev/stdout \ -logFile /dev/stdout \
-quit \ -quit \
-serial "$UNITY_SERIAL" \ -serial "$UNITY_SERIAL" \
@@ -85,7 +88,7 @@ else
# #
echo "License activation strategy could not be determined." echo "License activation strategy could not be determined."
echo "" echo ""
echo "Visit https://github.com/webbertakken/unity-builder#usage for more" echo "Visit https://game.ci/docs/github/getting-started for more"
echo "details on how to set up one of the possible activation strategies." echo "details on how to set up one of the possible activation strategies."
# Immediately exit as no UNITY_EXIT_CODE can be derrived. # Immediately exit as no UNITY_EXIT_CODE can be derrived.
@@ -98,13 +101,9 @@ fi
# #
if [ $UNITY_EXIT_CODE -eq 0 ]; then if [ $UNITY_EXIT_CODE -eq 0 ]; then
# Activation was a success # Activation was a success
echo "" echo "Activation complete."
echo "###########################"
echo "# Activation complete #"
echo "###########################"
echo ""
else else
echo "" # Activation failed so exit with the code from the license verification step
echo "###########################" echo "###########################"
echo "# Failure #" echo "# Failure #"
echo "###########################" echo "###########################"
@@ -114,5 +113,9 @@ else
echo "" echo ""
echo "To find the reason for failure: please search for errors in the log above." echo "To find the reason for failure: please search for errors in the log above."
echo "" echo ""
echo "Exit code was: $UNITY_EXIT_CODE"
exit $UNITY_EXIT_CODE exit $UNITY_EXIT_CODE
fi fi
# Return to previous working directory
popd

3387
dist/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

84
dist/licenses.txt generated vendored Normal file
View File

@@ -0,0 +1,84 @@
@actions/core
MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/exec
MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/http-client
MIT
Actions Http Client for Node.js
Copyright (c) GitHub, Inc.
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/io
MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tunnel
MIT
The MIT License (MIT)
Copyright (c) 2012 Koichi Kobayashi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

1
dist/sourcemap-register.js generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +1,11 @@
const esModules = ['lodash-es'].join('|');
module.exports = { module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node', testEnvironment: 'node',
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'], testMatch: ['**/*.test.ts'],
transform: { '^.+\\.(js|jsx)?$': 'babel-jest' }, testRunner: 'jest-circus/runner',
transformIgnorePatterns: [`/node_modules/(?!${esModules})`], transform: {
'^.+\\.ts$': 'ts-jest',
},
verbose: true,
}; };

View File

@@ -1,57 +1,53 @@
{ {
"name": "unity-activate", "name": "unity-activate",
"version": "0.0.0", "version": "2.0.0",
"description": "Activate Unity using credentials or a license file. Both personal and professional licenses are supported.", "description": "Activate Unity using credentials or a license file. Both personal and professional licenses are supported.",
"main": "action/index.js", "main": "dist/index.js",
"repository": "git@github.com:webbertakken/unity-activate.git", "repository": "git@github.com:game-ci/unity-activate.git",
"author": "Webber <webber@takken.io>", "author": "Webber <webber@takken.io>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "ncc build src --out action --minify", "prebuild": "yarn",
"lint": "prettier --check \"src/**/*.js\" && eslint src", "build": "tsc && ncc build lib --source-map --license licenses.txt",
"test": "jest" "lint": "prettier --check \"src/**/*.{js,ts}\" && eslint src/**/*.ts",
"format": "prettier --write \"src/**/*.{js,ts}\"",
"test": "jest",
"prepare": "husky install"
}, },
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"@actions/exec": "1.0.3", "@actions/exec": "^1.0.4",
"@actions/github": "^2.1.1" "@actions/github": "^2.2.0",
"@octokit/core": "^3.5.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "7.8.4", "@types/jest": "^27.4.0",
"@babel/core": "7.8.7", "@types/node": "^17.0.8",
"@babel/preset-env": "7.8.7", "@typescript-eslint/parser": "^5.9.0",
"@zeit/ncc": "0.21.1", "@vercel/ncc": "^0.33.1",
"babel-eslint": "10.1.0", "eslint": "^8.6.0",
"eslint": "6.8.0", "eslint-config-prettier": "^8.1.0",
"eslint-config-airbnb": "18.0.1", "eslint-plugin-github": "^4.3.5",
"eslint-config-prettier": "6.10.0", "eslint-plugin-jest": "^25.3.4",
"eslint-plugin-flowtype": "4.6.0", "eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-import": "2.20.1", "eslint-plugin-unicorn": "^40.0.0",
"eslint-plugin-jsx-a11y": "6.2.3", "husky": "^7.0.4",
"eslint-plugin-prettier": "3.1.2", "jest": "^26.6.3",
"eslint-plugin-react": "7.19.0", "jest-circus": "^26.6.3",
"eslint-plugin-unicorn": "17.1.0", "js-yaml": "^3.14.0",
"husky": "4.2.3", "lint-staged": "^12.1.2",
"jest": "25.1.0", "prettier": "^2.2.1",
"lint-staged": "10.0.8", "ts-jest": "^26.4.4",
"lodash-es": "4.17.15", "typescript": "^4.1.3"
"prettier": "1.19.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && yarn build && git add action/index.js"
}
}, },
"lint-staged": { "lint-staged": {
"*.{js,jsx}": [ "*.{js,jsx,ts,tsx}": [
"prettier --write", "prettier --write",
"eslint", "eslint",
"git add",
"jest --findRelatedTests" "jest --findRelatedTests"
], ],
"*.{json,md,yaml,yml}": [ "*.{json,md,yaml,yml}": [
"prettier --write", "prettier --write"
"git add"
] ]
} }
} }

View File

@@ -1,21 +0,0 @@
import { Action, Docker, Input, ImageTag } from './model';
const core = require('@actions/core');
async function action() {
Action.checkCompatibility();
const { dockerfile, workspace, actionFolder } = Action;
const { unityVersion } = Input.getFromUser();
const baseImage = ImageTag.createForBase(unityVersion);
// Build docker image
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
// Run docker image
await Docker.run(actionImage, { workspace, unityVersion });
}
action().catch(error => {
core.setFailed(error.message);
});

22
src/index.ts Normal file
View File

@@ -0,0 +1,22 @@
import * as core from '@actions/core';
import { Action, Docker, ImageTag, Input } from './model';
async function run() {
try {
Action.checkCompatibility();
const { dockerfile, workspace, actionFolder } = Action;
const unityVersion = Input.unityVersion;
const baseImage = new ImageTag(unityVersion);
// Build docker image
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
// Run docker image
await Docker.run(actionImage, { workspace, unityVersion });
} catch (error: any) {
core.setFailed(error.message);
}
}
run();

View File

@@ -1,6 +1,6 @@
import path from 'path';
import fs from 'fs';
import Action from './action'; import Action from './action';
import fs from 'fs';
import path from 'path';
describe('Action', () => { describe('Action', () => {
describe('compatibility check', () => { describe('compatibility check', () => {
@@ -14,16 +14,16 @@ describe('Action', () => {
}); });
it('returns the root folder of the action', () => { it('returns the root folder of the action', () => {
const { rootFolder, name } = Action; const { rootFolder, canonicalName } = Action;
expect(path.basename(rootFolder)).toStrictEqual(name); expect(path.basename(rootFolder)).toStrictEqual(canonicalName);
expect(fs.existsSync(rootFolder)).toStrictEqual(true); expect(fs.existsSync(rootFolder)).toStrictEqual(true);
}); });
it('returns the action folder', () => { it('returns the action folder', () => {
const { actionFolder } = Action; const { actionFolder } = Action;
expect(path.basename(actionFolder)).toStrictEqual('action'); expect(path.basename(actionFolder)).toStrictEqual('dist');
expect(fs.existsSync(actionFolder)).toStrictEqual(true); expect(fs.existsSync(actionFolder)).toStrictEqual(true);
}); });

View File

@@ -1,48 +1,48 @@
import path from 'path'; import path from 'path';
class Action { const Action = {
static get supportedPlatforms() { get supportedPlatforms() {
return ['linux']; return ['linux'];
} },
static get isRunningLocally() { get isRunningLocally() {
return process.env.RUNNER_WORKSPACE === undefined; return process.env.RUNNER_WORKSPACE === undefined;
} },
static get isRunningFromSource() { get isRunningFromSource() {
return path.basename(__dirname) === 'model'; return path.basename(__dirname) === 'model';
} },
static get name() { get canonicalName() {
return 'unity-activate'; return 'unity-activate';
} },
static get rootFolder() { get rootFolder() {
if (Action.isRunningFromSource) { if (Action.isRunningFromSource) {
return path.dirname(path.dirname(path.dirname(__filename))); return path.dirname(path.dirname(path.dirname(__filename)));
} }
return path.dirname(path.dirname(__filename)); return path.dirname(path.dirname(__filename));
} },
static get actionFolder() { get actionFolder() {
return `${Action.rootFolder}/action`; return `${Action.rootFolder}/dist`;
} },
static get dockerfile() { get dockerfile() {
return `${Action.actionFolder}/Dockerfile`; return `${Action.actionFolder}/Dockerfile`;
} },
static get workspace() { get workspace() {
return process.env.GITHUB_WORKSPACE; return process.env.GITHUB_WORKSPACE;
} },
static checkCompatibility() { checkCompatibility() {
const currentPlatform = process.platform; const currentPlatform = process.platform;
if (!Action.supportedPlatforms.includes(currentPlatform)) { if (!Action.supportedPlatforms.includes(currentPlatform)) {
throw new Error(`Currently ${currentPlatform}-platform is not supported`); throw new Error(`Currently ${currentPlatform}-platform is not supported`);
} }
} },
} };
export default Action; export default Action;

View File

@@ -1,20 +0,0 @@
import Action from './action';
import Docker from './docker';
import ImageTag from './image-tag';
describe('Docker', () => {
it('builds', async () => {
const path = Action.actionFolder;
const dockerfile = `${path}/Dockerfile`;
const baseImage = new ImageTag({
repository: '',
name: 'alpine',
version: '3',
});
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
expect(tag).toBeInstanceOf(ImageTag);
expect(tag.toString()).toStrictEqual('unity-action:3');
}, 240000);
});

25
src/model/docker.test.ts Normal file
View File

@@ -0,0 +1,25 @@
import Action from './action';
import Docker from './docker';
import ImageTag from './image-tag';
describe('Docker', () => {
it.skip('builds', async () => {
const path = Action.actionFolder;
const dockerfile = `${path}/Dockerfile`;
const baseImage = new ImageTag('2019.2.11f1');
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
expect(tag).toBeInstanceOf(ImageTag);
expect(tag.toString()).toStrictEqual('unity-builder:3');
}, 240_000);
it.skip('runs', async () => {
const image = 'unity-builder:2019.2.11f1-webgl';
const parameters = {
workspace: Action.rootFolder,
projectPath: `${Action.rootFolder}/test-project`,
buildName: 'someBuildName',
buildsPath: 'build',
method: '',
};
await Docker.run(image, parameters);
});
});

View File

@@ -1,23 +1,23 @@
import { exec } from '@actions/exec';
import ImageTag from './image-tag'; import ImageTag from './image-tag';
import { exec } from '@actions/exec';
class Docker { const Docker = {
static async build(buildParameters, silent = false) { async build(buildParameters, silent = false) {
const { path, dockerfile, baseImage } = buildParameters; const { path, dockerfile, baseImage } = buildParameters;
const { version } = baseImage; const { version } = baseImage;
const tag = ImageTag.createForAction(version); const tag = new ImageTag(version);
const command = `docker build ${path} \ const command = `docker build ${path} \
--file ${dockerfile} \ --file ${dockerfile} \
--build-arg IMAGE=${baseImage} \ --build-arg IMAGE=${baseImage} \
--tag ${tag}`; --tag ${tag}`;
await exec(command, null, { silent }); await exec(command, undefined, { silent });
return tag; return tag;
} },
static async run(image, parameters, silent = false) { async run(image, parameters, silent = false) {
const { unityVersion, workspace } = parameters; const { unityVersion, workspace } = parameters;
const command = `docker run \ const command = `docker run \
@@ -50,8 +50,8 @@ class Docker {
--volume "${workspace}":"/github/workspace" \ --volume "${workspace}":"/github/workspace" \
${image}`; ${image}`;
await exec(command, null, { silent }); await exec(command, undefined, { silent });
} },
} };
export default Docker; export default Docker;

View File

@@ -1,41 +0,0 @@
import { trimStart } from 'lodash-es';
class ImageTag {
static createForBase(version) {
const repository = 'gableroux';
const name = 'unity3d';
return new this({ repository, name, version });
}
static createForAction(version) {
const repository = '';
const name = 'unity-action';
return new this({ repository, name, version });
}
constructor({ repository = '', name, version }) {
if (!ImageTag.versionPattern.test(version)) {
throw new Error(`Invalid version "${version}".`);
}
Object.assign(this, { repository, name, version });
}
static get versionPattern() {
return /^20\d{2}\.\d\.\w{3,4}|3$/;
}
get tag() {
return this.version;
}
get image() {
return trimStart(`${this.repository}/${this.name}`, '/');
}
toString() {
return `${this.image}:${this.tag}`;
}
}
export default ImageTag;

View File

@@ -1,38 +0,0 @@
import ImageTag from './image-tag';
describe('UnityImageVersion', () => {
describe('constructor', () => {
const some = {
name: 'someName',
version: '2020.0.00f0',
};
it('can be called', () => {
expect(() => new ImageTag(some)).not.toThrow();
});
it('accepts parameters and sets the right properties', () => {
const image = new ImageTag(some);
expect(image.repository).toStrictEqual('');
expect(image.name).toStrictEqual(some.name);
expect(image.version).toStrictEqual(some.version);
});
test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', version => {
expect(() => new ImageTag({ version })).not.toThrow();
});
test.each(['some version', '', 1, null])('throws for incorrect versions %p', version => {
expect(() => new ImageTag({ version })).toThrow();
});
});
describe('toString', () => {
it('returns the correct version', () => {
const image = ImageTag.createForBase('2099.1.1111');
expect(image.toString()).toStrictEqual(`gableroux/unity3d:2099.1.1111`);
});
});
});

View File

@@ -0,0 +1,22 @@
import ImageTag from './image-tag';
describe('ImageTag', () => {
describe('constructor', () => {
const unityVersion = '2020.0.00f0';
it('can be called', () => {
expect(() => new ImageTag(unityVersion)).not.toThrow();
});
test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', (version) => {
expect(() => new ImageTag(version)).not.toThrow();
});
});
describe('toString', () => {
it('returns the correct version', () => {
const image = new ImageTag('2099.1.1111');
expect(image.toString()).toStrictEqual(`unityci/editor:2099.1.1111-linux-il2cpp-0`);
});
});
});

125
src/model/image-tag.ts Normal file
View File

@@ -0,0 +1,125 @@
import Platform from './platform';
class ImageTag {
public repository: string;
public name: string;
public version: string;
public platform: any;
public builderPlatform: string;
public customImage: any;
constructor(unityVersion: string) {
if (!ImageTag.versionPattern.test(unityVersion)) {
throw new Error(`Invalid version "${unityVersion}".`);
}
const builderPlatform = ImageTag.getTargetPlatformToImageSuffixMap(
Platform.types.StandaloneLinux64,
unityVersion,
);
this.repository = 'unityci';
this.name = 'editor';
this.version = unityVersion;
this.platform = Platform.types.StandaloneLinux64;
this.builderPlatform = builderPlatform;
this.customImage = '';
}
static get versionPattern() {
return /^20\d{2}\.\d\.\w{3,4}|3$/;
}
static get imageSuffixes() {
return {
generic: '',
webgl: 'webgl',
mac: 'mac-mono',
windows: 'windows-mono',
linux: 'base',
linuxIl2cpp: 'linux-il2cpp',
android: 'android',
ios: 'ios',
facebook: 'facebook',
};
}
static getTargetPlatformToImageSuffixMap(platform, version) {
const { generic, webgl, mac, windows, linux, linuxIl2cpp, android, ios, facebook } =
ImageTag.imageSuffixes;
const [major, minor] = version.split('.').map((digit) => Number(digit));
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
switch (platform) {
case Platform.types.StandaloneOSX:
return mac;
case Platform.types.StandaloneWindows:
return windows;
case Platform.types.StandaloneWindows64:
return windows;
case Platform.types.StandaloneLinux64: {
// Unity versions before 2019.3 do not support il2cpp
if (major >= 2020 || (major === 2019 && minor >= 3)) {
return linuxIl2cpp;
}
return linux;
}
case Platform.types.iOS:
return ios;
case Platform.types.Android:
return android;
case Platform.types.WebGL:
return webgl;
case Platform.types.WSAPlayer:
return windows;
case Platform.types.PS4:
return windows;
case Platform.types.XboxOne:
return windows;
case Platform.types.tvOS:
return windows;
case Platform.types.Switch:
return windows;
// Unsupported
case Platform.types.Lumin:
return windows;
case Platform.types.BJM:
return windows;
case Platform.types.Stadia:
return windows;
case Platform.types.Facebook:
return facebook;
case Platform.types.NoTarget:
return generic;
// Test specific
case Platform.types.Test:
return generic;
default:
throw new Error(`
Platform must be one of the ones described in the documentation.
"${platform}" is currently not supported.`);
}
}
get tag() {
return `${this.version}-${this.builderPlatform}`.replace(/-+$/, '');
}
get image() {
return `${this.repository}/${this.name}`.replace(/^\/+/, '');
}
toString() {
const { image, tag, customImage } = this;
if (customImage && customImage !== '') {
return customImage;
}
const dockerRepoVersion = 0;
return `${image}:${tag}-${dockerRepoVersion}`;
}
}
export default ImageTag;

View File

@@ -1,6 +0,0 @@
import Action from './action';
import Docker from './docker';
import Input from './input';
import ImageTag from './image-tag';
export { Action, Docker, Input, ImageTag };

View File

@@ -1,7 +1,7 @@
import * as Index from '.'; import * as Index from '.';
describe('Index', () => { describe('Index', () => {
test.each(['Action', 'Docker', 'ImageTag', 'Input'])('exports %s', exportedModule => { test.each(['Action', 'Docker', 'ImageTag', 'Input'])('exports %s', (exportedModule) => {
expect(typeof Index[exportedModule]).toStrictEqual('function'); expect(Index[exportedModule]).toBeDefined();
}); });
}); });

5
src/model/index.ts Normal file
View File

@@ -0,0 +1,5 @@
export { default as Action } from './action';
export { default as Input } from './input';
export { default as Docker } from './docker';
export { default as ImageTag } from './image-tag';

View File

@@ -1,15 +0,0 @@
const core = require('@actions/core');
class Input {
static getFromUser() {
// Input variables specified in workflow using "with" prop.
const unityVersion = core.getInput('unityVersion') || '2019.2.11f1';
// Return sanitised input
return {
unityVersion,
};
}
}
export default Input;

View File

@@ -1,13 +0,0 @@
import Input from './input';
describe('Input', () => {
describe('getFromUser', () => {
it('does not throw', () => {
expect(() => Input.getFromUser()).not.toThrow();
});
it('returns an object', () => {
expect(typeof Input.getFromUser()).toStrictEqual('object');
});
});
});

18
src/model/input.test.ts Normal file
View File

@@ -0,0 +1,18 @@
import * as core from '@actions/core';
import Input from './input';
describe('Input', () => {
describe('unityVersion', () => {
it('returns the default value', () => {
expect(Input.unityVersion).toStrictEqual('2019.2.11f1');
});
it('takes input from the users workflow', () => {
const mockValue = '2020.4.99f9';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.unityVersion).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1);
});
});
});

9
src/model/input.ts Normal file
View File

@@ -0,0 +1,9 @@
import * as core from '@actions/core';
const Input = {
get unityVersion() {
return core.getInput('unityVersion') || '2019.2.11f1';
},
};
export default Input;

View File

@@ -0,0 +1,37 @@
import Platform from './platform';
describe('Platform', () => {
describe('default', () => {
it('does not throw', () => {
expect(() => Platform.default).not.toThrow();
});
it('returns a string', () => {
expect(typeof Platform.default).toStrictEqual('string');
});
it('returns a platform', () => {
expect(Object.values(Platform.types)).toContain(Platform.default);
});
});
describe('isWindows', () => {
it('returns true for windows', () => {
expect(Platform.isWindows(Platform.types.StandaloneWindows64)).toStrictEqual(true);
});
it('returns false for MacOS', () => {
expect(Platform.isWindows(Platform.types.StandaloneOSX)).toStrictEqual(false);
});
});
describe('isAndroid', () => {
it('returns true for Android', () => {
expect(Platform.isAndroid(Platform.types.Android)).toStrictEqual(true);
});
it('returns false for Windows', () => {
expect(Platform.isAndroid(Platform.types.StandaloneWindows64)).toStrictEqual(false);
});
});
});

51
src/model/platform.ts Normal file
View File

@@ -0,0 +1,51 @@
const Platform = {
get default() {
return Platform.types.StandaloneWindows64;
},
get types() {
return {
StandaloneOSX: 'StandaloneOSX',
StandaloneWindows: 'StandaloneWindows',
StandaloneWindows64: 'StandaloneWindows64',
StandaloneLinux64: 'StandaloneLinux64',
iOS: 'iOS',
Android: 'Android',
WebGL: 'WebGL',
WSAPlayer: 'WSAPlayer',
PS4: 'PS4',
XboxOne: 'XboxOne',
tvOS: 'tvOS',
Switch: 'Switch',
// Unsupported
Lumin: 'Lumin',
BJM: 'BJM',
Stadia: 'Stadia',
Facebook: 'Facebook',
NoTarget: 'NoTarget',
// Test specific
Test: 'Test',
};
},
isWindows(platform) {
switch (platform) {
case Platform.types.StandaloneWindows:
case Platform.types.StandaloneWindows64:
return true;
default:
return false;
}
},
isAndroid(platform) {
switch (platform) {
case Platform.types.Android:
return true;
default:
return false;
}
},
};
export default Platform;

12
tsconfig.json Normal file
View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": false /* Re-enable after fixing compatibility */ /* Raise error on expressions and declarations with an implied 'any' type. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"exclude": ["node_modules", "**/*.test.ts"]
}

6055
yarn.lock

File diff suppressed because it is too large Load Diff