From 8cbb31c08b38558d96b16fd1ca28bc558963c661 Mon Sep 17 00:00:00 2001 From: Webber Date: Fri, 15 Apr 2022 01:53:25 +0200 Subject: [PATCH] feat: introduce deno cli entrypoint --- .eslintrc.json | 4 ++- action.yml | 55 ++++++++++++++++++++++++++++++++-- cli/controller/bootstrapper.ts | 24 +++++++++++++++ cli/core/cli-options.ts | 1 + cli/core/kernel.ts | 11 +++++++ cli/core/parse-argv.ts | 51 +++++++++++++++++++++++++++++++ cli/index.ts | 7 +++++ deno.json | 31 +++++++++++++++++++ tsconfig.json | 2 +- 9 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 cli/controller/bootstrapper.ts create mode 100644 cli/core/cli-options.ts create mode 100644 cli/core/kernel.ts create mode 100644 cli/core/parse-argv.ts create mode 100644 cli/index.ts create mode 100644 deno.json diff --git a/.eslintrc.json b/.eslintrc.json index 3b958602..08001ef8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -55,6 +55,8 @@ // For this project only use kebab-case "unicorn/filename-case": ["error", { "cases": { "kebabCase": true } }], // Allow Array.from(set) mitigate TS2569 which would require '--downlevelIteration' - "unicorn/prefer-spread": "off" + "unicorn/prefer-spread": "off", + // Temporarily allow disabling for whole file + "eslint-comments/no-use": "off" } } diff --git a/action.yml b/action.yml index 1e0e6a95..68d0e63b 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,58 @@ name: 'Unity - Builder' author: Webber Takken description: 'Build Unity projects for different platforms.' +runs: + using: 'composite' + steps: + - run: echo "Using GameCI CLI to build project" + shell: bash + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + - run: | + deno run --allow-run .\src\deno-1\gameci.ts build \ + --targetPlatform="${{ inputs.targetPlatform }}" \ + --unityVersion="${{ inputs.unityVersion }}" \ + --customImage="${{ inputs.customImage }}" \ + --projectPath="${{ inputs.projectPath }}" \ + --buildName="${{ inputs.buildName }}" \ + --buildsPath="${{ inputs.buildsPath }}" \ + --buildMethod="${{ inputs.buildMethod }}" \ + --customParameters="${{ inputs.customParameters }}" \ + --versioning="${{ inputs.versioning }}" \ + --version="${{ inputs.version }}" \ + --androidVersionCode="${{ inputs.androidVersionCode }}" \ + --androidAppBundle="${{ inputs.androidAppBundle }}" \ + --androidKeystoreName="${{ inputs.androidKeystoreName }}" \ + --androidKeystoreBase64="${{ inputs.androidKeystoreBase64 }}" \ + --androidKeystorePass="${{ inputs.androidKeystorePass }}" \ + --androidKeyaliasName="${{ inputs.androidKeyaliasName }}" \ + --androidKeyaliasPass="${{ inputs.androidKeyaliasPass }}" \ + --androidTargetSdkVersion="${{ inputs.androidTargetSdkVersion }}" \ + --sshAgent="${{ inputs.sshAgent }}" \ + --gitPrivateToken="${{ inputs.gitPrivateToken }}" \ + --chownFilesTo="${{ inputs.chownFilesTo }}" \ + --allowDirtyBuild="${{ inputs.allowDirtyBuild }}" \ + --postBuildSteps="${{ inputs.postBuildSteps }}" \ + --preBuildSteps="${{ inputs.preBuildSteps }}" \ + --customJobHooks="${{ inputs.customJobHooks }}" \ + --customJob="${{ inputs.customJob }}" \ + --awsBaseStackName="${{ inputs.awsBaseStackName }}" \ + --cloudRunnerCluster="${{ inputs.cloudRunnerCluster }}" \ + --cloudRunnerCpu="${{ inputs.cloudRunnerCpu }}" \ + --cloudRunnerMemory="${{ inputs.cloudRunnerMemory }}" \ + --cachePushOverrideCommand="${{ inputs.cachePushOverrideCommand }}" \ + --cachePullOverrideCommand="${{ inputs.cachePullOverrideCommand }}" \ + --readInputFromOverrideList="${{ inputs.readInputFromOverrideList }}" \ + --readInputOverrideCommand="${{ inputs.readInputOverrideCommand }}" \ + --kubeConfig="${{ inputs.kubeConfig }}" \ + --kubeVolume="${{ inputs.kubeVolume }}" \ + --kubeStorageClass="${{ inputs.kubeStorageClass }}" \ + --kubeVolumeSize="${{ inputs.kubeVolumeSize }}" \ + --cacheKey="${{ inputs.cacheKey }}" \ + --checkDependencyHealthOverride="${{ inputs.checkDependencyHealthOverride }}" \ + --startDependenciesOverride="${{ inputs.startDependenciesOverride }}" + shell: bash inputs: targetPlatform: required: true @@ -174,6 +226,3 @@ outputs: branding: icon: 'box' color: 'gray-dark' -runs: - using: 'node12' - main: 'dist/index.js' diff --git a/cli/controller/bootstrapper.ts b/cli/controller/bootstrapper.ts new file mode 100644 index 00000000..ee109846 --- /dev/null +++ b/cli/controller/bootstrapper.ts @@ -0,0 +1,24 @@ +/* eslint-disable no-console */ +import { exec, OutputMode } from 'https://deno.land/x/exec@0.0.5/mod.ts'; +import { CliOptions } from '../core/cli-options.ts'; + +export class Bootstrapper { + private readonly options: CliOptions; + + constructor(cliOptions: CliOptions) { + this.options = cliOptions; + } + + public async run() { + console.log('using options', this.options); + + const result = await exec('docker run -it unityci/editor:2020.3.15f2-base-1 /bin/bash -c "echo test"', { + output: OutputMode.Capture, + continueOnError: true, + + // verbose: true, + }); + + console.log(result.output); + } +} diff --git a/cli/core/cli-options.ts b/cli/core/cli-options.ts new file mode 100644 index 00000000..b099a31b --- /dev/null +++ b/cli/core/cli-options.ts @@ -0,0 +1 @@ +export type CliOptions = Map; diff --git a/cli/core/kernel.ts b/cli/core/kernel.ts new file mode 100644 index 00000000..fd3b97a3 --- /dev/null +++ b/cli/core/kernel.ts @@ -0,0 +1,11 @@ +import { parseArgv } from './parse-argv.ts'; +import { Bootstrapper } from '../controller/bootstrapper.ts'; + +export class Kernel { + public async run() { + const cliOptions = parseArgv(Deno.args); + + const bootstrapper = new Bootstrapper(cliOptions); + bootstrapper.run(); + } +} diff --git a/cli/core/parse-argv.ts b/cli/core/parse-argv.ts new file mode 100644 index 00000000..4c0bfc69 --- /dev/null +++ b/cli/core/parse-argv.ts @@ -0,0 +1,51 @@ +import { CliOptions } from './cli-options.ts'; + +/** + * Parse command line arguments + * + * Usage: + * console.dir(parseArgv(Deno.args)); // Deno + * console.log(parseArgv(process.argv)); // Node + * + * Example: + * deno run my-script -test1=1 -test2 "2" -test3 -test4 false -test5 "one" -test6= -test7=9BX9 + * + * Output: + * Map { + * "test1" => 1, + * "test2" => 2, + * "test3" => true, + * "test4" => false, + * "test5" => "one", + * "test6" => "", + * "test7" => "9BX9" + * } + */ +export const parseArgv = (argv: string[] = [], { verbose = false } = {}): CliOptions => { + const providedArguments = new Map(); + + for (let current = 0, next = 1; current < argv.length; current += 1, next += 1) { + // Detect flag + if (!argv[current].startsWith('-')) continue; + let flag = argv[current].replace(/^-+/, ''); + + // Detect value + const hasNextArgument = next < argv.length && !argv[next].startsWith('-'); + let value: string | number | boolean = hasNextArgument ? argv[next] : 'true'; + + // Split combinations + const isCombination = flag.includes('='); + if (isCombination) [flag, value] = flag.split('='); + + // Parse types + if (['true', 'false'].includes(value)) value = value === 'true'; + else if (!Number.isNaN(Number(value)) && !Number.isNaN(Number.parseInt(value))) value = Number.parseInt(value); + + // Assign + // eslint-disable-next-line no-console + if (verbose) console.log(`Found flag "${flag}" with value "${value}" (${typeof value}).`); + providedArguments.set(flag, value); + } + + return providedArguments; +}; diff --git a/cli/index.ts b/cli/index.ts new file mode 100644 index 00000000..1ae8eaa0 --- /dev/null +++ b/cli/index.ts @@ -0,0 +1,7 @@ +import { Kernel } from './core/kernel.ts'; + +(async () => { + const kernel = new Kernel(); + + await kernel.run(); +})(); diff --git a/deno.json b/deno.json new file mode 100644 index 00000000..fb4c2294 --- /dev/null +++ b/deno.json @@ -0,0 +1,31 @@ +{ + "compilerOptions": { + "allowJs": true, + "lib": ["deno.window"], + "strict": true + }, + "lint": { + "files": { + "include": ["cli/"], + "exclude": [] + }, + "rules": { + "tags": ["recommended"], + "include": ["ban-untagged-todo"], + "exclude": ["no-unused-vars"] + } + }, + "fmt": { + "files": { + "include": ["cli/"], + "exclude": [] + }, + "options": { + "useTabs": false, + "lineWidth": 120, + "indentWidth": 2, + "singleQuote": true, + "proseWrap": "preserve" + } + } +} diff --git a/tsconfig.json b/tsconfig.json index e8c9118c..236ef4cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "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. */, + "rootDir": "./" /* 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'. */