From b62407866b4ff1b0895c8917d84318621bbb78fb Mon Sep 17 00:00:00 2001 From: Webber Date: Wed, 8 Jun 2022 23:26:30 +0200 Subject: [PATCH] chore: rewrite more imports to deno style --- .eslintrc.json | 3 ++ deno.json | 31 +++++++++++++ deno.ts | 3 -- package.json | 1 - src/dependencies.ts | 24 ++++++++++ src/devDependencies.ts | 6 +++ src/integrity.test.ts | 4 +- src/model/action.test.ts | 3 +- src/model/action.ts | 8 ++-- src/model/build-parameters.test.ts | 2 +- src/model/build-parameters.ts | 10 ++--- src/model/cache.ts | 5 +-- src/model/cli/cli.ts | 2 +- .../providers/aws/aws-job-stack.ts | 6 +-- .../aws/commands/aws-cli-commands.ts | 8 ++-- src/model/cloud-runner/providers/aws/index.ts | 2 +- .../providers/k8s/kubernetes-storage.ts | 8 ++-- .../remote-client/caching.test.ts | 10 ++--- .../cloud-runner/remote-client/caching.ts | 10 ++--- src/model/cloud-runner/remote-client/index.ts | 8 ++-- .../services/cloud-runner-folders.ts | 2 +- .../services/cloud-runner-guid.ts | 4 +- .../cloud-runner/services/lfs-hashing.ts | 4 +- src/model/docker.ts | 8 ++-- src/model/image-environment-factory.ts | 38 ++++++++-------- src/model/input-readers/action-yaml.ts | 4 +- src/model/input-readers/git-repo.ts | 10 ++--- .../input-readers/test-license-reader.ts | 4 +- src/model/input.ts | 3 +- src/model/platform-setup/setup-mac.ts | 44 +++++++++---------- src/model/platform-setup/setup-windows.ts | 5 +-- .../platform-validation/validate-windows.ts | 4 +- src/model/system.integration.test.ts | 2 +- src/model/unity-versioning.ts | 4 +- src/model/versioning.ts | 6 +-- yarn.lock | 5 --- 36 files changed, 166 insertions(+), 135 deletions(-) create mode 100644 deno.json delete mode 100644 deno.ts create mode 100644 src/dependencies.ts create mode 100644 src/devDependencies.ts diff --git a/.eslintrc.json b/.eslintrc.json index 3b958602..f42c5e31 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -16,6 +16,9 @@ "es6": true, "jest/globals": true }, + "globals": { + "Deno": true + }, "rules": { // Error out for code formatting errors "prettier/prettier": "error", diff --git a/deno.json b/deno.json new file mode 100644 index 00000000..c26439c7 --- /dev/null +++ b/deno.json @@ -0,0 +1,31 @@ +{ + "compilerOptions": { + "allowJs": true, + "lib": ["deno.window"], + "strict": true + }, + "lint": { + "files": { + "include": ["src/"], + "exclude": [] + }, + "rules": { + "tags": ["recommended"], + "include": ["ban-untagged-todo"], + "exclude": ["no-unused-vars"] + } + }, + "fmt": { + "files": { + "include": ["src/"], + "exclude": [] + }, + "options": { + "useTabs": false, + "lineWidth": 120, + "indentWidth": 2, + "singleQuote": true, + "proseWrap": "preserve" + } + } +} diff --git a/deno.ts b/deno.ts deleted file mode 100644 index bfef6f64..00000000 --- a/deno.ts +++ /dev/null @@ -1,3 +0,0 @@ -// These are the packages from Deno that replace the ones from Node. -import * as fs from 'https://deno.land/std@0.142.0/node/fs/promises.ts'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; diff --git a/package.json b/package.json index d60ea916..c636a919 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "devDependencies": { "@arkweid/lefthook": "^0.7.7", "@types/jest": "^27.4.1", - "@types/node": "^17.0.23", "@types/semver": "^7.3.9", "@typescript-eslint/parser": "4.8.1", "@vercel/ncc": "^0.33.3", diff --git a/src/dependencies.ts b/src/dependencies.ts new file mode 100644 index 00000000..f8a9d5c3 --- /dev/null +++ b/src/dependencies.ts @@ -0,0 +1,24 @@ +// These are the packages from Deno that replace the ones from Node. +import * as fs from 'https://deno.land/std@0.142.0/node/fs/promises.ts'; +import * as fsSync from 'https://deno.land/std@0.142.0/node/fs/mod.ts'; +import * as path from 'https://deno.land/std@0.142.0/path/mod.ts'; +import * as core from 'https://deno.land/x/deno_actions_core/mod.ts'; +import { v4 as uuid } from 'https://deno.land/std@0.142.0/uuid/mod.ts'; +import * as assert from 'https://deno.land/std@0.142.0/testing/mod.ts'; +import * as YAML from 'https://deno.land/x/yaml@v2.1.1/mod.ts'; +import * as aws from 'https://deno.land/x/aws_sdk@v3.32.0-1/mod.ts'; +import * as k8s from 'https://deno.land/x/kubernetes_client/mod.ts'; +import * as nanoid from 'https://deno.land/x/nanoid/mod.ts'; + +const exec = () => { + throw new Error('exec is not implemented'); // @actions/exec' +}; + +const getUnityChangeSet = () => { + throw new Error('getUnityChangeSet is not implemented'); // unity-changeset' +}; + +const __filename = path.fromFileUrl(import.meta.url); +const __dirname = path.dirname(path.fromFileUrl(import.meta.url)); + +export { fs, fsSync, path, core, exec, uuid, assert, YAML, __filename, __dirname, getUnityChangeSet, aws, k8s, nanoid }; diff --git a/src/devDependencies.ts b/src/devDependencies.ts new file mode 100644 index 00000000..3894a993 --- /dev/null +++ b/src/devDependencies.ts @@ -0,0 +1,6 @@ +import * as asserts from 'https://deno.land/std@0.142.0/testing/mod.ts'; + +// Dev dependencies also include all prod dependencies. +export * from './dependencies.ts'; + +export { asserts }; diff --git a/src/integrity.test.ts b/src/integrity.test.ts index b93f5627..ccd00911 100644 --- a/src/integrity.test.ts +++ b/src/integrity.test.ts @@ -1,9 +1,9 @@ -import { stat } from 'https://deno.land/std@0.142.0/node/fs/promises/mod.ts'; +import { fs } from '../dependencies.ts'; describe('Integrity tests', () => { describe('package-lock.json', () => { it('does not exist', async () => { - await expect(stat(`${process.cwd()}/package-lock.json`)).rejects.toThrowError(); + await expect(fs.stat(`${process.cwd()}/package-lock.json`)).rejects.toThrowError(); }); }); }); diff --git a/src/model/action.test.ts b/src/model/action.test.ts index a7760329..2e40f2ea 100644 --- a/src/model/action.test.ts +++ b/src/model/action.test.ts @@ -1,5 +1,4 @@ -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; -import fs from '../../../node_modules/fs'; +import { fs, path } from '../dependencies.ts'; import Action from './action.ts'; describe('Action', () => { diff --git a/src/model/action.ts b/src/model/action.ts index fa7b91b1..fe2ea21d 100644 --- a/src/model/action.ts +++ b/src/model/action.ts @@ -1,4 +1,4 @@ -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; +import { path, __dirname } from '../dependencies.ts'; class Action { static get supportedPlatforms() { @@ -6,11 +6,11 @@ class Action { } static get isRunningLocally() { - return process.env.RUNNER_WORKSPACE === undefined; + return Deno.env.get('RUNNER_WORKSPACE') === undefined; } static get isRunningFromSource() { - return path.basename(__dirname) === "model"; + return path.basename(__dirname) === 'model'; } static get canonicalName() { @@ -30,7 +30,7 @@ class Action { } static get workspace() { - return process.env.GITHUB_WORKSPACE; + return Deno.env.get('GITHUB_WORKSPACE'); } static checkCompatibility() { diff --git a/src/model/build-parameters.test.ts b/src/model/build-parameters.test.ts index 4295ef76..24cc4aa5 100644 --- a/src/model/build-parameters.test.ts +++ b/src/model/build-parameters.test.ts @@ -8,7 +8,7 @@ import Platform from './platform.ts'; // Todo - Don't use process.env directly, that's what the input model class is for. const testLicense = '\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \nm0Db8UK+ktnOLJBtHybkfetpcKo=o/pUbSQAukz7+ZYAWhnA0AJbIlyyCPL7bKVEM2lVqbrXt7cyey+umkCXamuOgsWPVUKBMkXtMH8L\n5etLmD0getWIhTGhzOnDCk+gtIPfL4jMo9tkEuOCROQAXCci23VFscKcrkB+3X6h4wEOtA2APhOY\nB+wvC794o8/82ffjP79aVAi57rp3Wmzx+9pe9yMwoJuljAy2sc2tIMgdQGWVmOGBpQm3JqsidyzI\nJWG2kjnc7pDXK9pwYzXoKiqUqqrut90d+kQqRyv7MSZXR50HFqD/LI69h68b7P8Bjo3bPXOhNXGR\n9YCoemH6EkfCJxp2gIjzjWW+l2Hj2EsFQi8YXw=='; -process.env.UNITY_LICENSE = testLicense; +Deno.env.set('UNITY_LICENSE', testLicense); const determineVersion = jest.spyOn(Versioning, 'determineBuildVersion').mockImplementation(async () => '1.3.37'); const determineUnityVersion = jest diff --git a/src/model/build-parameters.ts b/src/model/build-parameters.ts index 5ee12d8f..155acb3c 100644 --- a/src/model/build-parameters.ts +++ b/src/model/build-parameters.ts @@ -76,17 +76,17 @@ class BuildParameters { // Todo - Don't use process.env directly, that's what the input model class is for. // --- let unitySerial = ''; - if (!process.env.UNITY_SERIAL && Input.githubInputEnabled) { + if (!Deno.env.get('UNITY_SERIAL') && Input.githubInputEnabled) { // No serial was present, so it is a personal license that we need to convert - if (!process.env.UNITY_LICENSE) { + if (!Deno.env.get('UNITY_LICENSE')) { throw new Error(`Missing Unity License File and no Serial was found. If this is a personal license, make sure to follow the activation steps and set the UNITY_LICENSE GitHub secret or enter a Unity serial number inside the UNITY_SERIAL GitHub secret.`); } - unitySerial = this.getSerialFromLicenseFile(process.env.UNITY_LICENSE); + unitySerial = this.getSerialFromLicenseFile(Deno.env.get('UNITY_LICENSE')); } else { - unitySerial = process.env.UNITY_SERIAL!; + unitySerial = Deno.env.get('UNITY_SERIAL')!; } return { @@ -94,7 +94,7 @@ class BuildParameters { customImage: Input.customImage, unitySerial, - runnerTempPath: process.env.RUNNER_TEMP, + runnerTempPath: Deno.env.get('RUNNER_TEMP'), targetPlatform: Input.targetPlatform, projectPath: Input.projectPath, buildName: Input.buildName, diff --git a/src/model/cache.ts b/src/model/cache.ts index 59f6860b..0b392754 100644 --- a/src/model/cache.ts +++ b/src/model/cache.ts @@ -1,11 +1,10 @@ -import * as core from '../../../node_modules/@actions/core'; -import fs from '../../../node_modules/fs'; +import { fsSync, core } from '../dependencies.ts'; import Action from './action.ts'; import Project from './project.ts'; class Cache { static verify() { - if (!fs.existsSync(Project.libraryFolder)) { + if (!fsSync.existsSync(Project.libraryFolder)) { this.notifyAboutCachingPossibility(); } } diff --git a/src/model/cli/cli.ts b/src/model/cli/cli.ts index f21e1713..776aeb68 100644 --- a/src/model/cli/cli.ts +++ b/src/model/cli/cli.ts @@ -1,6 +1,6 @@ import { Command } from '../../../node_modules/commander-ts'; import { BuildParameters, CloudRunner, ImageTag, Input } from '../index.ts'; -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; import { ActionYamlReader } from '../input-readers/action-yaml.ts'; import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger.ts'; import CloudRunnerQueryOverride from '../cloud-runner/services/cloud-runner-query-override.ts'; diff --git a/src/model/cloud-runner/providers/aws/aws-job-stack.ts b/src/model/cloud-runner/providers/aws/aws-job-stack.ts index b19f75ef..ec5a1cbc 100644 --- a/src/model/cloud-runner/providers/aws/aws-job-stack.ts +++ b/src/model/cloud-runner/providers/aws/aws-job-stack.ts @@ -1,4 +1,4 @@ -import * as SDK from 'aws-sdk'; +import { aws } from '../../../../dependencies.ts'; import CloudRunnerAWSTaskDef from './cloud-runner-aws-task-def.ts'; import CloudRunnerSecret from '../../services/cloud-runner-secret.ts'; import { AWSCloudFormationTemplates } from './aws-cloud-formation-templates.ts'; @@ -13,7 +13,7 @@ export class AWSJobStack { } public async setupCloudFormations( - CF: SDK.CloudFormation, + CF: aws.CloudFormation, buildGuid: string, image: string, entrypoint: string[], @@ -118,7 +118,7 @@ export class AWSJobStack { } } } - const createStackInput: SDK.CloudFormation.CreateStackInput = { + const createStackInput: aws.CloudFormation.CreateStackInput = { StackName: taskDefStackName, TemplateBody: taskDefCloudFormation, Capabilities: ['CAPABILITY_IAM'], diff --git a/src/model/cloud-runner/providers/aws/commands/aws-cli-commands.ts b/src/model/cloud-runner/providers/aws/commands/aws-cli-commands.ts index 56a4e4f6..87379a9d 100644 --- a/src/model/cloud-runner/providers/aws/commands/aws-cli-commands.ts +++ b/src/model/cloud-runner/providers/aws/commands/aws-cli-commands.ts @@ -33,7 +33,7 @@ export class AwsCliCommands { } @CliFunction(`aws-list-stacks`, `List stacks`) static async awsListStacks(perResultCallback: any = false, verbose: boolean = false) { - process.env.AWS_REGION = Input.region; + Deno.env.set('AWS_REGION', Input.region); const CF = new AWS.CloudFormation(); const stacks = (await CF.listStacks().promise()).StackSummaries?.filter( @@ -71,7 +71,7 @@ export class AwsCliCommands { } @CliFunction(`aws-list-tasks`, `List tasks`) static async awsListTasks(perResultCallback: any = false) { - process.env.AWS_REGION = Input.region; + Deno.env.set('AWS_REGION', Input.region); const ecs = new AWS.ECS(); const clusters = (await ecs.listClusters().promise()).clusterArns || []; CloudRunnerLogger.log(`Clusters ${clusters.length}`); @@ -105,7 +105,7 @@ export class AwsCliCommands { } @CliFunction(`aws-list-log-groups`, `List tasks`) static async awsListLogGroups(perResultCallback: any = false, verbose: boolean = false) { - process.env.AWS_REGION = Input.region; + Deno.env.set('AWS_REGION', Input.region); const ecs = new AWS.CloudWatchLogs(); let logStreamInput: AWS.CloudWatchLogs.DescribeLogGroupsRequest = { /* logGroupNamePrefix: 'game-ci' */ @@ -138,7 +138,7 @@ export class AwsCliCommands { } private static async cleanup(deleteResources = false, OneDayOlderOnly: boolean = false) { - process.env.AWS_REGION = Input.region; + Deno.env.set('AWS_REGION', Input.region); const CF = new AWS.CloudFormation(); const ecs = new AWS.ECS(); const cwl = new AWS.CloudWatchLogs(); diff --git a/src/model/cloud-runner/providers/aws/index.ts b/src/model/cloud-runner/providers/aws/index.ts index 64995bf7..a974bf87 100644 --- a/src/model/cloud-runner/providers/aws/index.ts +++ b/src/model/cloud-runner/providers/aws/index.ts @@ -46,7 +46,7 @@ class AWSBuildEnvironment implements ProviderInterface { environment: CloudRunnerEnvironmentVariable[], secrets: CloudRunnerSecret[], ): Promise { - process.env.AWS_REGION = Input.region; + Deno.env.set('AWS_REGION', Input.region); const ECS = new SDK.ECS(); const CF = new SDK.CloudFormation(); CloudRunnerLogger.log(`AWS Region: ${CF.config.region}`); diff --git a/src/model/cloud-runner/providers/k8s/kubernetes-storage.ts b/src/model/cloud-runner/providers/k8s/kubernetes-storage.ts index a2817fc5..1019b678 100644 --- a/src/model/cloud-runner/providers/k8s/kubernetes-storage.ts +++ b/src/model/cloud-runner/providers/k8s/kubernetes-storage.ts @@ -1,9 +1,7 @@ +import { k8s, core, YAML } from '../../../../dependencies.ts'; import waitUntil from 'async-wait-until'; -import * as core from '../../../node_modules/@actions/core'; -import * as k8s from '@kubernetes/client-node'; import BuildParameters from '../../../build-parameters.ts'; import CloudRunnerLogger from '../../services/cloud-runner-logger.ts'; -import YAML from '../../../node_modules/yaml'; import { IncomingMessage } from '../../../node_modules/http'; class KubernetesStorage { @@ -95,8 +93,8 @@ class KubernetesStorage { }, }, }; - if (process.env.K8s_STORAGE_PVC_SPEC) { - YAML.parse(process.env.K8s_STORAGE_PVC_SPEC); + if (Deno.env.get('K8s_STORAGE_PVC_SPEC')) { + YAML.parse(Deno.env.get('K8s_STORAGE_PVC_SPEC')); } const result = await kubeClient.createNamespacedPersistentVolumeClaim(namespace, pvc); diff --git a/src/model/cloud-runner/remote-client/caching.test.ts b/src/model/cloud-runner/remote-client/caching.test.ts index 873c93d4..7add5a7d 100644 --- a/src/model/cloud-runner/remote-client/caching.test.ts +++ b/src/model/cloud-runner/remote-client/caching.test.ts @@ -1,13 +1,11 @@ -import fs from '../../../node_modules/fs'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; +import { fs, uuid, path, __dirname } from '../../../dependencies.ts'; import BuildParameters from '../../build-parameters.ts'; import { Cli } from '../../cli/cli.ts'; import Input from '../../input.ts'; import UnityVersioning from '../../unity-versioning.ts'; -import CloudRunner from '../cloud-runner'; -import { CloudRunnerSystem } from '../services/cloud-runner-system'; +import CloudRunner from '../cloud-runner.ts'; +import { CloudRunnerSystem } from '../services/cloud-runner-system/index.ts'; import { Caching } from './caching.ts'; -import { v4 as uuidv4 } from '../../../node_modules/uuid'; describe('Cloud Runner Caching', () => { it('responds', () => {}); @@ -20,7 +18,7 @@ describe('Cloud Runner Caching', () => { projectPath: 'test-project', unityVersion: UnityVersioning.read('test-project'), targetPlatform: 'StandaloneLinux64', - cacheKey: `test-case-${uuidv4()}`, + cacheKey: `test-case-${uuid()}`, }; Input.githubInputEnabled = false; const buildParameter = await BuildParameters.create(); diff --git a/src/model/cloud-runner/remote-client/caching.ts b/src/model/cloud-runner/remote-client/caching.ts index 50e063d3..5e773d1d 100644 --- a/src/model/cloud-runner/remote-client/caching.ts +++ b/src/model/cloud-runner/remote-client/caching.ts @@ -1,6 +1,4 @@ -import { assert } from '../../../node_modules/console'; -import fs from '../../../node_modules/fs'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; +import { fs, path, assert } from '../../../dependencies.ts'; import CloudRunner from '../cloud-runner.ts'; import CloudRunnerLogger from '../services/cloud-runner-logger.ts'; import { CloudRunnerFolders } from '../services/cloud-runner-folders.ts'; @@ -16,7 +14,7 @@ export class Caching { @CliFunction(`cache-push`, `push to cache`) static async cachePush() { try { - const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}'); + const buildParameter = JSON.parse(Deno.env.get('BUILD_PARAMETERS') || '{}'); CloudRunner.buildParameters = buildParameter; await Caching.PushToCache( Cli.options['cachePushTo'], @@ -31,7 +29,7 @@ export class Caching { @CliFunction(`cache-pull`, `pull from cache`) static async cachePull() { try { - const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}'); + const buildParameter = JSON.parse(Deno.env.get('BUILD_PARAMETERS') || '{}'); CloudRunner.buildParameters = buildParameter; await Caching.PullFromCache( Cli.options['cachePushFrom'], @@ -164,7 +162,7 @@ export class Caching { } public static async handleCachePurging() { - if (process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined) { + if (Deno.env.get('PURGE_REMOTE_BUILDER_CACHE') !== undefined) { RemoteClientLogger.log(`purging ${CloudRunnerFolders.purgeRemoteCaching}`); fs.promises.rmdir(CloudRunnerFolders.cacheFolder, { recursive: true }); } diff --git a/src/model/cloud-runner/remote-client/index.ts b/src/model/cloud-runner/remote-client/index.ts index 24b01763..75085123 100644 --- a/src/model/cloud-runner/remote-client/index.ts +++ b/src/model/cloud-runner/remote-client/index.ts @@ -1,11 +1,9 @@ -import fs from '../../../node_modules/fs'; +import { fs, assert, path } from '../../../dependencies.ts'; import CloudRunner from '../cloud-runner.ts'; import { CloudRunnerFolders } from '../services/cloud-runner-folders.ts'; import { Caching } from './caching.ts'; import { LfsHashing } from '../services/lfs-hashing.ts'; import { RemoteClientLogger } from './remote-client-logger.ts'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; -import { assert } from '../../../node_modules/console'; import CloudRunnerLogger from '../services/cloud-runner-logger.ts'; import { CliFunction } from '../../cli/cli-functions-repository.ts'; import { CloudRunnerSystem } from '../services/cloud-runner-system.ts'; @@ -70,7 +68,7 @@ export class RemoteClient { RemoteClientLogger.log(`${CloudRunner.buildParameters.branch}`); await CloudRunnerSystem.Run(`git checkout ${CloudRunner.buildParameters.branch}`); assert(fs.existsSync(path.join(`.git`, `lfs`)), 'LFS folder should not exist before caching'); - RemoteClientLogger.log(`Checked out ${process.env.GITHUB_SHA}`); + RemoteClientLogger.log(`Checked out ${Deno.env.get('GITHUB_SHA')}`); } catch (error) { throw error; } @@ -87,7 +85,7 @@ export class RemoteClient { @CliFunction(`remote-cli`, `sets up a repository, usually before a game-ci build`) static async runRemoteClientJob() { - const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}'); + const buildParameter = JSON.parse(Deno.env.get('BUILD_PARAMETERS') || '{}'); RemoteClientLogger.log(`Build Params: ${JSON.stringify(buildParameter, undefined, 4)} `); diff --git a/src/model/cloud-runner/services/cloud-runner-folders.ts b/src/model/cloud-runner/services/cloud-runner-folders.ts index 38a2075c..be2d0fc3 100644 --- a/src/model/cloud-runner/services/cloud-runner-folders.ts +++ b/src/model/cloud-runner/services/cloud-runner-folders.ts @@ -44,7 +44,7 @@ export class CloudRunnerFolders { } public static get purgeRemoteCaching(): boolean { - return process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined; + return Deno.env.get('PURGE_REMOTE_BUILDER_CACHE') !== undefined; } public static get lfsCacheFolderFull() { diff --git a/src/model/cloud-runner/services/cloud-runner-guid.ts b/src/model/cloud-runner/services/cloud-runner-guid.ts index 9e82312d..a24a7696 100644 --- a/src/model/cloud-runner/services/cloud-runner-guid.ts +++ b/src/model/cloud-runner/services/cloud-runner-guid.ts @@ -1,9 +1,9 @@ -import { customAlphabet } from '../../../node_modules/nanoid'; +import { nanoid } from '../../../dependencies.ts'; import CloudRunnerConstants from './cloud-runner-constants.ts'; class CloudRunnerNamespace { static generateGuid(runNumber: string | number, platform: string) { - const nanoid = customAlphabet(CloudRunnerConstants.alphabet, 4); + const nanoid = nanoid.customAlphabet(CloudRunnerConstants.alphabet, 4); return `${runNumber}-${platform.toLowerCase().replace('standalone', '')}-${nanoid()}`; } diff --git a/src/model/cloud-runner/services/lfs-hashing.ts b/src/model/cloud-runner/services/lfs-hashing.ts index 132f62aa..49bb7b9f 100644 --- a/src/model/cloud-runner/services/lfs-hashing.ts +++ b/src/model/cloud-runner/services/lfs-hashing.ts @@ -1,8 +1,6 @@ -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; import { CloudRunnerFolders } from './cloud-runner-folders.ts'; import { CloudRunnerSystem } from './cloud-runner-system.ts'; -import fs from '../../../node_modules/fs'; -import { assert } from '../../../node_modules/console'; +import { fsSync as fs, assert, path } from '../../../dependencies.ts'; import { Cli } from '../../cli/cli.ts'; import { CliFunction } from '../../cli/cli-functions-repository.ts'; diff --git a/src/model/docker.ts b/src/model/docker.ts index 4a0fc006..1b653f08 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -1,7 +1,5 @@ -import { exec } from '../../../node_modules/@actions/exec'; import ImageEnvironmentFactory from './image-environment-factory.ts'; -import { existsSync, mkdirSync } from '../../../node_modules/fs'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; +import { path, exec, fs } from '../dependencies.ts'; class Docker { static async run(image, parameters, silent = false) { @@ -20,9 +18,9 @@ class Docker { const { workspace, actionFolder, runnerTempPath, sshAgent, gitPrivateToken } = parameters; const githubHome = path.join(runnerTempPath, '_github_home'); - if (!existsSync(githubHome)) mkdirSync(githubHome); + if (!fs.existsSync(githubHome)) fs.mkdirSync(githubHome); const githubWorkflow = path.join(runnerTempPath, '_github_workflow'); - if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow); + if (!fs.existsSync(githubWorkflow)) fs.mkdirSync(githubWorkflow); return `docker run \ --workdir /github/workspace \ diff --git a/src/model/image-environment-factory.ts b/src/model/image-environment-factory.ts index b595125f..b870c816 100644 --- a/src/model/image-environment-factory.ts +++ b/src/model/image-environment-factory.ts @@ -26,13 +26,13 @@ class ImageEnvironmentFactory { } public static getEnvironmentVariables(parameters: BuildParameters) { const environmentVariables: Parameter[] = [ - { name: 'UNITY_LICENSE', value: process.env.UNITY_LICENSE || ReadLicense() }, - { name: 'UNITY_LICENSE_FILE', value: process.env.UNITY_LICENSE_FILE }, - { name: 'UNITY_EMAIL', value: process.env.UNITY_EMAIL }, - { name: 'UNITY_PASSWORD', value: process.env.UNITY_PASSWORD }, + { name: 'UNITY_LICENSE', value: Deno.env.get('UNITY_LICENSE') || ReadLicense() }, + { name: 'UNITY_LICENSE_FILE', value: Deno.env.get('UNITY_LICENSE_FILE') }, + { name: 'UNITY_EMAIL', value: Deno.env.get('UNITY_EMAIL') }, + { name: 'UNITY_PASSWORD', value: Deno.env.get('UNITY_PASSWORD') }, { name: 'UNITY_SERIAL', value: parameters.unitySerial }, { name: 'UNITY_VERSION', value: parameters.editorVersion }, - { name: 'USYM_UPLOAD_AUTH_TOKEN', value: process.env.USYM_UPLOAD_AUTH_TOKEN }, + { name: 'USYM_UPLOAD_AUTH_TOKEN', value: Deno.env.get('USYM_UPLOAD_AUTH_TOKEN') }, { name: 'PROJECT_PATH', value: parameters.projectPath }, { name: 'BUILD_TARGET', value: parameters.targetPlatform }, { name: 'BUILD_NAME', value: parameters.buildName }, @@ -50,21 +50,21 @@ class ImageEnvironmentFactory { { name: 'ANDROID_SDK_MANAGER_PARAMETERS', value: parameters.androidSdkManagerParameters }, { name: 'CUSTOM_PARAMETERS', value: parameters.customParameters }, { name: 'CHOWN_FILES_TO', value: parameters.chownFilesTo }, - { name: 'GITHUB_REF', value: process.env.GITHUB_REF }, - { name: 'GITHUB_SHA', value: process.env.GITHUB_SHA }, - { name: 'GITHUB_REPOSITORY', value: process.env.GITHUB_REPOSITORY }, - { name: 'GITHUB_ACTOR', value: process.env.GITHUB_ACTOR }, - { name: 'GITHUB_WORKFLOW', value: process.env.GITHUB_WORKFLOW }, - { name: 'GITHUB_HEAD_REF', value: process.env.GITHUB_HEAD_REF }, - { name: 'GITHUB_BASE_REF', value: process.env.GITHUB_BASE_REF }, - { name: 'GITHUB_EVENT_NAME', value: process.env.GITHUB_EVENT_NAME }, + { name: 'GITHUB_REF', value: Deno.env.get('GITHUB_REF') }, + { name: 'GITHUB_SHA', value: Deno.env.get('GITHUB_SHA') }, + { name: 'GITHUB_REPOSITORY', value: Deno.env.get('GITHUB_REPOSITORY') }, + { name: 'GITHUB_ACTOR', value: Deno.env.get('GITHUB_ACTOR') }, + { name: 'GITHUB_WORKFLOW', value: Deno.env.get('GITHUB_WORKFLOW') }, + { name: 'GITHUB_HEAD_REF', value: Deno.env.get('GITHUB_HEAD_REF') }, + { name: 'GITHUB_BASE_REF', value: Deno.env.get('GITHUB_BASE_REF') }, + { name: 'GITHUB_EVENT_NAME', value: Deno.env.get('GITHUB_EVENT_NAME') }, { name: 'GITHUB_WORKSPACE', value: '/github/workspace' }, - { name: 'GITHUB_ACTION', value: process.env.GITHUB_ACTION }, - { name: 'GITHUB_EVENT_PATH', value: process.env.GITHUB_EVENT_PATH }, - { name: 'RUNNER_OS', value: process.env.RUNNER_OS }, - { name: 'RUNNER_TOOL_CACHE', value: process.env.RUNNER_TOOL_CACHE }, - { name: 'RUNNER_TEMP', value: process.env.RUNNER_TEMP }, - { name: 'RUNNER_WORKSPACE', value: process.env.RUNNER_WORKSPACE }, + { name: 'GITHUB_ACTION', value: Deno.env.get('GITHUB_ACTION') }, + { name: 'GITHUB_EVENT_PATH', value: Deno.env.get('GITHUB_EVENT_PATH') }, + { name: 'RUNNER_OS', value: Deno.env.get('RUNNER_OS') }, + { name: 'RUNNER_TOOL_CACHE', value: Deno.env.get('RUNNER_TOOL_CACHE') }, + { name: 'RUNNER_TEMP', value: Deno.env.get('RUNNER_TEMP') }, + { name: 'RUNNER_WORKSPACE', value: Deno.env.get('RUNNER_WORKSPACE') }, ]; if (parameters.sshAgent) environmentVariables.push({ name: 'SSH_AUTH_SOCK', value: '/ssh-agent' }); diff --git a/src/model/input-readers/action-yaml.ts b/src/model/input-readers/action-yaml.ts index 41ece117..d98d7b51 100644 --- a/src/model/input-readers/action-yaml.ts +++ b/src/model/input-readers/action-yaml.ts @@ -1,6 +1,4 @@ -import fs from '../../../node_modules/fs'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; -import YAML from '../../../node_modules/yaml'; +import { fsSync as fs, path, YAML, __dirname } from '../../dependencies.ts'; export class ActionYamlReader { private actionYamlParsed: any; diff --git a/src/model/input-readers/git-repo.ts b/src/model/input-readers/git-repo.ts index 791ad9fb..e0235952 100644 --- a/src/model/input-readers/git-repo.ts +++ b/src/model/input-readers/git-repo.ts @@ -1,5 +1,5 @@ -// import { assert } from '../../../node_modules/console'; -// import fs from '../../../node_modules/fs'; +import { assert } from 'https://deno.land/std@0.142.0/testing/asserts.ts'; +import { fs } from '../../dependencies.ts'; import { CloudRunnerSystem } from '../cloud-runner/services/cloud-runner-system.ts'; import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger.ts'; import Input from '../input.ts'; @@ -10,10 +10,10 @@ export class GitRepoReader { if (Input.cloudRunnerCluster === 'local') { return ''; } - // assert(fs.existsSync(`.git`)); + assert(fs.existsSync(`.git`)); const value = (await CloudRunnerSystem.Run(`git remote -v`, false, true)).replace(/ /g, ``); CloudRunnerLogger.log(`value ${value}`); - // assert(value.includes('github.com')); + assert(value.includes('github.com')); return value.split('github.com/')[1].split('.git')[0]; } @@ -22,7 +22,7 @@ export class GitRepoReader { if (Input.cloudRunnerCluster === 'local') { return ''; } - // assert(fs.existsSync(`.git`)); + assert(fs.existsSync(`.git`)); return (await CloudRunnerSystem.Run(`git branch --show-current`, false, true)) .split('\n')[0] diff --git a/src/model/input-readers/test-license-reader.ts b/src/model/input-readers/test-license-reader.ts index 07c0c447..d4287ca4 100644 --- a/src/model/input-readers/test-license-reader.ts +++ b/src/model/input-readers/test-license-reader.ts @@ -1,6 +1,4 @@ -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; -import fs from '../../../node_modules/fs'; -import YAML from '../../../node_modules/yaml'; +import { fsSync as fs, path, YAML, __dirname } from '../../dependencies.ts'; import Input from '../input.ts'; export function ReadLicense() { diff --git a/src/model/input.ts b/src/model/input.ts index 5203a916..97ed3788 100644 --- a/src/model/input.ts +++ b/src/model/input.ts @@ -1,5 +1,4 @@ -import fs from '../../../node_modules/fs'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; +import { fs, path } from '../dependencies.ts'; import { Cli } from './cli/cli.ts'; import CloudRunnerQueryOverride from './cloud-runner/services/cloud-runner-query-override.ts'; import Platform from './platform.ts'; diff --git a/src/model/platform-setup/setup-mac.ts b/src/model/platform-setup/setup-mac.ts index 82a6e8b7..b16b9435 100644 --- a/src/model/platform-setup/setup-mac.ts +++ b/src/model/platform-setup/setup-mac.ts @@ -1,7 +1,5 @@ import { BuildParameters } from '../index.ts'; -import { getUnityChangeset } from '../../../node_modules/unity-changeset'; -import { exec } from '../../../node_modules/@actions/exec'; -import fs from '../../../node_modules/fs'; +import { fsSync as fs, exec, getUnityChangeset } from '../../dependencies.ts'; class SetupMac { static unityHubPath = `"/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"`; @@ -49,26 +47,26 @@ class SetupMac { private static async setEnvironmentVariables(buildParameters: BuildParameters, actionFolder: string) { // Need to set environment variables from here because we execute // the scripts on the host for mac - process.env.ACTION_FOLDER = actionFolder; - process.env.UNITY_VERSION = buildParameters.editorVersion; - process.env.UNITY_SERIAL = buildParameters.unitySerial; - process.env.PROJECT_PATH = buildParameters.projectPath; - process.env.BUILD_TARGET = buildParameters.targetPlatform; - process.env.BUILD_NAME = buildParameters.buildName; - process.env.BUILD_PATH = buildParameters.buildPath; - process.env.BUILD_FILE = buildParameters.buildFile; - process.env.BUILD_METHOD = buildParameters.buildMethod; - process.env.VERSION = buildParameters.buildVersion; - process.env.ANDROID_VERSION_CODE = buildParameters.androidVersionCode; - process.env.ANDROID_KEYSTORE_NAME = buildParameters.androidKeystoreName; - process.env.ANDROID_KEYSTORE_BASE64 = buildParameters.androidKeystoreBase64; - process.env.ANDROID_KEYSTORE_PASS = buildParameters.androidKeystorePass; - process.env.ANDROID_KEYALIAS_NAME = buildParameters.androidKeyaliasName; - process.env.ANDROID_KEYALIAS_PASS = buildParameters.androidKeyaliasPass; - process.env.ANDROID_TARGET_SDK_VERSION = buildParameters.androidTargetSdkVersion; - process.env.ANDROID_SDK_MANAGER_PARAMETERS = buildParameters.androidSdkManagerParameters; - process.env.CUSTOM_PARAMETERS = buildParameters.customParameters; - process.env.CHOWN_FILES_TO = buildParameters.chownFilesTo; + Deno.env.set('ACTION_FOLDER', actionFolder); + Deno.env.set('UNITY_VERSION', buildParameters.editorVersion); + Deno.env.set('UNITY_SERIAL', buildParameters.unitySerial); + Deno.env.set('PROJECT_PATH', buildParameters.projectPath); + Deno.env.set('BUILD_TARGET', buildParameters.targetPlatform); + Deno.env.set('BUILD_NAME', buildParameters.buildName); + Deno.env.set('BUILD_PATH', buildParameters.buildPath); + Deno.env.set('BUILD_FILE', buildParameters.buildFile); + Deno.env.set('BUILD_METHOD', buildParameters.buildMethod); + Deno.env.set('VERSION', buildParameters.buildVersion); + Deno.env.set('ANDROID_VERSION_CODE', buildParameters.androidVersionCode); + Deno.env.set('ANDROID_KEYSTORE_NAME', buildParameters.androidKeystoreName); + Deno.env.set('ANDROID_KEYSTORE_BASE64', buildParameters.androidKeystoreBase64); + Deno.env.set('ANDROID_KEYSTORE_PASS', buildParameters.androidKeystorePass); + Deno.env.set('ANDROID_KEYALIAS_NAME', buildParameters.androidKeyaliasName); + Deno.env.set('ANDROID_KEYALIAS_PASS', buildParameters.androidKeyaliasPass); + Deno.env.set('ANDROID_TARGET_SDK_VERSION', buildParameters.androidTargetSdkVersion); + Deno.env.set('ANDROID_SDK_MANAGER_PARAMETERS', buildParameters.androidSdkManagerParameters); + Deno.env.set('CUSTOM_PARAMETERS', buildParameters.customParameters); + Deno.env.set('CHOWN_FILES_TO', buildParameters.chownFilesTo); } } diff --git a/src/model/platform-setup/setup-windows.ts b/src/model/platform-setup/setup-windows.ts index ee268d68..ef9313a9 100644 --- a/src/model/platform-setup/setup-windows.ts +++ b/src/model/platform-setup/setup-windows.ts @@ -1,6 +1,5 @@ -import { exec } from '../../../node_modules/@actions/exec'; -import fs from '../../../node_modules/fs'; -import { BuildParameters } from '..'; +import { fsSync as fs, exec } from '../../dependencies.ts'; +import { BuildParameters } from '../index.ts'; class SetupWindows { public static async setup(buildParameters: BuildParameters) { diff --git a/src/model/platform-validation/validate-windows.ts b/src/model/platform-validation/validate-windows.ts index cf3a88b1..12da2763 100644 --- a/src/model/platform-validation/validate-windows.ts +++ b/src/model/platform-validation/validate-windows.ts @@ -1,10 +1,10 @@ -import fs from '../../../node_modules/fs'; +import { fsSync as fs } from '../../dependencies.ts'; import { BuildParameters } from '../index.ts'; class ValidateWindows { public static validate(buildParameters: BuildParameters) { ValidateWindows.validateWindowsPlatformRequirements(buildParameters.targetPlatform); - if (!(process.env.UNITY_EMAIL && process.env.UNITY_PASSWORD)) { + if (!(Deno.env.get('UNITY_EMAIL') && Deno.env.get('UNITY_PASSWORD'))) { throw new Error(`Unity email and password must be set for Windows based builds to authenticate the license. Make sure to set them inside UNITY_EMAIL and UNITY_PASSWORD in Github Secrets and pass them into the environment.`); diff --git a/src/model/system.integration.test.ts b/src/model/system.integration.test.ts index 07995b02..57913d34 100644 --- a/src/model/system.integration.test.ts +++ b/src/model/system.integration.test.ts @@ -15,7 +15,7 @@ describe('System', () => { * To ensure our integration with '@actions/exec' works as expected we run some specific tests in CI only */ describe('integration', () => { - if (!process.env.CI) { + if (!Deno.env.get('CI')) { it("doesn't run locally", () => { expect(true).toBe(true); }); diff --git a/src/model/unity-versioning.ts b/src/model/unity-versioning.ts index aaa3cc70..1ca92385 100644 --- a/src/model/unity-versioning.ts +++ b/src/model/unity-versioning.ts @@ -1,6 +1,4 @@ -import * as fs from '../../../node_modules/fs'; -import * as fs from 'https://deno.land/std@0.141.0/fs/mod.ts'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; +import { fs, path } from '../dependencies.ts'; export default class UnityVersioning { static get versionPattern() { diff --git a/src/model/versioning.ts b/src/model/versioning.ts index a58d51db..07da279f 100644 --- a/src/model/versioning.ts +++ b/src/model/versioning.ts @@ -33,21 +33,21 @@ export default class Versioning { * For pull requests we can reliably use GITHUB_HEAD_REF */ static get headRef() { - return process.env.GITHUB_HEAD_REF; + return Deno.env.get('GITHUB_HEAD_REF'); } /** * For branches GITHUB_REF will have format `refs/heads/feature-branch-1` */ static get ref() { - return process.env.GITHUB_REF; + return Deno.env.get('GITHUB_REF'); } /** * The commit SHA that triggered the workflow run. */ static get sha() { - return process.env.GITHUB_SHA; + return Deno.env.get('GITHUB_SHA'); } /** diff --git a/yarn.lock b/yarn.lock index d9f157e3..b3f42560 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1167,11 +1167,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.60.tgz#35f3d6213daed95da7f0f73e75bcc6980e90597b" integrity sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw== -"@types/node@^17.0.23": - version "17.0.23" - resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.23.tgz#3b41a6e643589ac6442bdbd7a4a3ded62f33f7da" - integrity sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw== - "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz"