diff --git a/src/dependencies.ts b/src/dependencies.ts index f8a9d5c3..a354f4f5 100644 --- a/src/dependencies.ts +++ b/src/dependencies.ts @@ -1,14 +1,19 @@ // These are the packages from Deno that replace the ones from Node. +import * as assert from 'https://deno.land/std@0.142.0/testing/mod.ts'; +import * as aws from 'https://deno.land/x/aws_sdk@v3.32.0-1/mod.ts'; +import * as compress from 'https://deno.land/x/compress@v0.3.3/mod.ts'; +import * as core from 'https://deno.land/x/deno_actions_core/mod.ts'; 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'; +import * as path from 'https://deno.land/std@0.142.0/path/mod.ts'; +import * as process from 'https://deno.land/std@0.104.0/node/process.ts'; +import * as semver from 'https://deno.land/x/semver@v1.4.0/mod.ts'; +import * as waitUntil from 'async-wait-until'; +import * as yaml from 'https://deno.land/x/yaml@v2.1.1/mod.ts'; +import { crypto } from 'https://deno.land/std@0.142.0/crypto/mod.ts'; +import { v4 as uuid } from 'https://deno.land/std@0.142.0/uuid/mod.ts'; const exec = () => { throw new Error('exec is not implemented'); // @actions/exec' @@ -18,7 +23,43 @@ const getUnityChangeSet = () => { throw new Error('getUnityChangeSet is not implemented'); // unity-changeset' }; +const waitUntil = async (function_: () => Promise, options = {}) => { + const { timeout = 10000, interval = 1000 } = options; + if (timeout || interval) { + // TODO - do some timeout stuff here + } + + await function_(); +}; + +class Writable { + constructor() { + throw new Error('Writable is not implemented'); // stream + } +} + 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 }; +export { + __dirname, + __filename, + assert, + aws, + compress, + core, + crypto, + exec, + fs, + fsSync, + getUnityChangeSet, + k8s, + nanoid, + path, + process, + semver, + uuid, + waitUntil, + Writable, + yaml, +}; diff --git a/src/index.ts b/src/index.ts index 6f947ccc..e92cdbe7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import * as core from '../node_modules/@actions/core'; +import { core, process } from './dependencies.ts'; import { Action, BuildParameters, Cache, CloudRunner, Docker, ImageTag, Output } from './model.ts'; import { Cli } from './model/cli/cli.ts'; import MacBuilder from './model/mac-builder.ts'; diff --git a/src/model/android-versioning.ts b/src/model/android-versioning.ts index 0c8d5210..3ccf6440 100644 --- a/src/model/android-versioning.ts +++ b/src/model/android-versioning.ts @@ -1,5 +1,4 @@ -import * as core from '../../../node_modules/@actions/core'; -import * as semver from '../../../node_modules/semver'; +import { core, semver } from '../../dependencies.ts'; export default class AndroidVersioning { static determineVersionCode(version, inputVersionCode) { diff --git a/src/model/cloud-runner/cloud-runner.ts b/src/model/cloud-runner/cloud-runner.ts index e3e4c6fc..342a4c36 100644 --- a/src/model/cloud-runner/cloud-runner.ts +++ b/src/model/cloud-runner/cloud-runner.ts @@ -6,7 +6,7 @@ import { CloudRunnerStepState } from './cloud-runner-step-state.ts'; import { WorkflowCompositionRoot } from './workflows/workflow-composition-root.ts'; import { CloudRunnerError } from './error/cloud-runner-error.ts'; import { TaskParameterSerializer } from './services/task-parameter-serializer.ts'; -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; import CloudRunnerSecret from './services/cloud-runner-secret.ts'; import { ProviderInterface } from './providers/provider-interface.ts'; import CloudRunnerEnvironmentVariable from './services/cloud-runner-environment-variable.ts'; diff --git a/src/model/cloud-runner/error/cloud-runner-error.ts b/src/model/cloud-runner/error/cloud-runner-error.ts index 4756a143..c9b2a629 100644 --- a/src/model/cloud-runner/error/cloud-runner-error.ts +++ b/src/model/cloud-runner/error/cloud-runner-error.ts @@ -1,5 +1,5 @@ import CloudRunnerLogger from '../services/cloud-runner-logger.ts'; -import * as core from '../../../../node_modules/@actions/core'; +import { core } from '../../../dependencies.ts'; import CloudRunner from '../cloud-runner.ts'; export class CloudRunnerError { diff --git a/src/model/cloud-runner/providers/aws/aws-base-stack.ts b/src/model/cloud-runner/providers/aws/aws-base-stack.ts index c3f0e571..267566d3 100644 --- a/src/model/cloud-runner/providers/aws/aws-base-stack.ts +++ b/src/model/cloud-runner/providers/aws/aws-base-stack.ts @@ -1,8 +1,6 @@ import CloudRunnerLogger from '../../services/cloud-runner-logger.ts'; -import * as core from '../../../node_modules/@actions/core'; -import * as SDK from 'aws-sdk'; +import { core, aws, crypto } from '../../../../dependencies.ts'; import { BaseStackFormation } from './cloud-formations/base-stack-formation.ts'; -const crypto = require('crypto'); export class AWSBaseStack { constructor(baseStackName: string) { @@ -10,33 +8,33 @@ export class AWSBaseStack { } private baseStackName: string; - async setupBaseStack(CF: SDK.CloudFormation) { + async setupBaseStack(CF: aws.CloudFormation) { const baseStackName = this.baseStackName; const baseStack = BaseStackFormation.formation; // Cloud Formation Input - const describeStackInput: SDK.CloudFormation.DescribeStacksInput = { + const describeStackInput: aws.CloudFormation.DescribeStacksInput = { StackName: baseStackName, }; - const parametersWithoutHash: SDK.CloudFormation.Parameter[] = [ + const parametersWithoutHash: aws.CloudFormation.Parameter[] = [ { ParameterKey: 'EnvironmentName', ParameterValue: baseStackName }, ]; const parametersHash = crypto .createHash('md5') .update(baseStack + JSON.stringify(parametersWithoutHash)) .digest('hex'); - const parameters: SDK.CloudFormation.Parameter[] = [ + const parameters: aws.CloudFormation.Parameter[] = [ ...parametersWithoutHash, ...[{ ParameterKey: 'Version', ParameterValue: parametersHash }], ]; - const updateInput: SDK.CloudFormation.UpdateStackInput = { + const updateInput: aws.CloudFormation.UpdateStackInput = { StackName: baseStackName, TemplateBody: baseStack, Parameters: parameters, Capabilities: ['CAPABILITY_IAM'], }; - const createStackInput: SDK.CloudFormation.CreateStackInput = { + const createStackInput: aws.CloudFormation.CreateStackInput = { StackName: baseStackName, TemplateBody: baseStack, Parameters: parameters, diff --git a/src/model/cloud-runner/providers/aws/aws-error.ts b/src/model/cloud-runner/providers/aws/aws-error.ts index 9481fbbb..a7e3bb73 100644 --- a/src/model/cloud-runner/providers/aws/aws-error.ts +++ b/src/model/cloud-runner/providers/aws/aws-error.ts @@ -1,10 +1,9 @@ import CloudRunnerLogger from '../../services/cloud-runner-logger.ts'; -import * as SDK from 'aws-sdk'; -import * as core from '../../../node_modules/@actions/core'; +import { core, aws } from '../../dependencies.ts'; import CloudRunner from '../../cloud-runner.ts'; export class AWSError { - static async handleStackCreationFailure(error: any, CF: SDK.CloudFormation, taskDefStackName: string) { + static async handleStackCreationFailure(error: any, CF: aws.CloudFormation, taskDefStackName: string) { CloudRunnerLogger.log('aws error: '); core.error(JSON.stringify(error, undefined, 4)); if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { diff --git a/src/model/cloud-runner/providers/aws/aws-task-runner.ts b/src/model/cloud-runner/providers/aws/aws-task-runner.ts index 0a1e2ecd..7cb561e7 100644 --- a/src/model/cloud-runner/providers/aws/aws-task-runner.ts +++ b/src/model/cloud-runner/providers/aws/aws-task-runner.ts @@ -1,8 +1,7 @@ import * as AWS from 'aws-sdk'; import CloudRunnerEnvironmentVariable from '../../services/cloud-runner-environment-variable.ts'; -import * as core from '../../../node_modules/@actions/core'; +import { core, compress } from '../../dependencies.ts'; import CloudRunnerAWSTaskDef from './cloud-runner-aws-task-def.ts'; -import * as zlib from '../../../node_modules/zlib'; import CloudRunnerLogger from '../../services/cloud-runner-logger.ts'; import { Input } from '../../...ts'; import CloudRunner from '../../cloud-runner.ts'; @@ -205,7 +204,7 @@ class AWSTaskRunner { if (records.Records.length > 0 && iterator) { for (let index = 0; index < records.Records.length; index++) { const json = JSON.parse( - zlib.gunzipSync(Buffer.from(records.Records[index].Data as string, 'base64')).toString('utf8'), + compress.gunzipSync(Buffer.from(records.Records[index].Data as string, 'base64')).toString('utf8'), ); if (json.messageType === 'DATA_MESSAGE') { for (let logEventsIndex = 0; logEventsIndex < json.logEvents.length; logEventsIndex++) { diff --git a/src/model/cloud-runner/providers/k8s/index.ts b/src/model/cloud-runner/providers/k8s/index.ts index f1754e2c..8f8814ad 100644 --- a/src/model/cloud-runner/providers/k8s/index.ts +++ b/src/model/cloud-runner/providers/k8s/index.ts @@ -1,17 +1,14 @@ -import * as k8s from '../../../node_modules/@kubernetes/client-node'; import { BuildParameters, Output } from '../../../index.ts'; -import * as core from '../../../node_modules/@actions/core'; +import { core, k8s, waitUntil } from '../../dependencies.ts'; import { ProviderInterface } from '../provider-interface.ts'; import CloudRunnerSecret from '../../services/cloud-runner-secret.ts'; import KubernetesStorage from './kubernetes-storage.ts'; import CloudRunnerEnvironmentVariable from '../../services/cloud-runner-environment-variable.ts'; import KubernetesTaskRunner from './kubernetes-task-runner.ts'; import KubernetesSecret from './kubernetes-secret.ts'; -import waitUntil from '../../../node_modules/async-wait-until'; import KubernetesJobSpecFactory from './kubernetes-job-spec-factory.ts'; import KubernetesServiceAccount from './kubernetes-service-account.ts'; import CloudRunnerLogger from '../../services/cloud-runner-logger.ts'; -import { CoreV1Api } from '../../../node_modules/@kubernetes/client-node'; import DependencyOverrideService from '../../services/depdency-override-service.ts'; class Kubernetes implements ProviderInterface { @@ -190,7 +187,7 @@ class Kubernetes implements ProviderInterface { process.exit(); } - static async findPodFromJob(kubeClient: CoreV1Api, jobName: string, namespace: string) { + static async findPodFromJob(kubeClient: k8s.CoreV1Api, jobName: string, namespace: string) { const namespacedPods = await kubeClient.listNamespacedPod(namespace); const pod = namespacedPods.body.items.find((x) => x.metadata?.labels?.['job-name'] === jobName); if (pod === undefined) { diff --git a/src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts b/src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts index f99769d4..aaf36049 100644 --- a/src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts +++ b/src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts @@ -1,9 +1,7 @@ import { CoreV1Api, KubeConfig, Log } from '@kubernetes/client-node'; -import { Writable } from '../../../node_modules/stream'; import CloudRunnerLogger from '../../services/cloud-runner-logger.ts'; -import * as core from '../../../node_modules/@actions/core'; +import { core, Writable, waitUntil } from '../../../../dependencies.ts'; import { CloudRunnerStatics } from '../../cloud-runner-statics.ts'; -import waitUntil from 'async-wait-until'; import { FollowLogStreamService } from '../../services/follow-log-stream-service.ts'; class KubernetesTaskRunner { diff --git a/src/model/cloud-runner/services/cloud-runner-logger.ts b/src/model/cloud-runner/services/cloud-runner-logger.ts index a47e4d74..ff234840 100644 --- a/src/model/cloud-runner/services/cloud-runner-logger.ts +++ b/src/model/cloud-runner/services/cloud-runner-logger.ts @@ -1,4 +1,4 @@ -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; class CloudRunnerLogger { private static timestamp: number; diff --git a/src/model/cloud-runner/services/follow-log-stream-service.ts b/src/model/cloud-runner/services/follow-log-stream-service.ts index 41362876..19475d1f 100644 --- a/src/model/cloud-runner/services/follow-log-stream-service.ts +++ b/src/model/cloud-runner/services/follow-log-stream-service.ts @@ -1,5 +1,5 @@ import CloudRunnerLogger from './cloud-runner-logger.ts'; -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; import CloudRunner from '../cloud-runner.ts'; import { CloudRunnerStatics } from '../cloud-runner-statics.ts'; diff --git a/src/model/cloud-runner/workflows/build-automation-workflow.ts b/src/model/cloud-runner/workflows/build-automation-workflow.ts index 7e986500..089997f9 100644 --- a/src/model/cloud-runner/workflows/build-automation-workflow.ts +++ b/src/model/cloud-runner/workflows/build-automation-workflow.ts @@ -3,9 +3,8 @@ import { CloudRunnerFolders } from '../services/cloud-runner-folders.ts'; import { CloudRunnerStepState } from '../cloud-runner-step-state.ts'; import { CustomWorkflow } from './custom-workflow.ts'; import { WorkflowInterface } from './workflow-interface.ts'; -import * as core from '../../../../node_modules/@actions/core'; +import { core, path } from '../../../dependencies.ts'; import { CloudRunnerBuildCommandProcessor } from '../services/cloud-runner-build-command-process.ts'; -import * as path from 'https://deno.land/std@0.141.0/path/mod.ts'; import CloudRunner from '../cloud-runner.ts'; export class BuildAutomationWorkflow implements WorkflowInterface { diff --git a/src/model/input-readers/github-cli.test.ts b/src/model/input-readers/github-cli.test.ts index 751909b0..b47fc29f 100644 --- a/src/model/input-readers/github-cli.test.ts +++ b/src/model/input-readers/github-cli.test.ts @@ -1,5 +1,5 @@ import { GithubCliReader } from './github-cli.ts'; -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; describe(`github cli`, () => { // Todo - We can not assume that everyone has the GitHub cli installed locally. diff --git a/src/model/input-readers/github-cli.ts b/src/model/input-readers/github-cli.ts index 5891a0ed..fbcf7067 100644 --- a/src/model/input-readers/github-cli.ts +++ b/src/model/input-readers/github-cli.ts @@ -1,5 +1,5 @@ import { CloudRunnerSystem } from '../cloud-runner/services/cloud-runner-system.ts'; -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; import Input from '../input.ts'; export class GithubCliReader { diff --git a/src/model/input.test.ts b/src/model/input.test.ts index 5d19a75d..7a0e36b6 100644 --- a/src/model/input.test.ts +++ b/src/model/input.test.ts @@ -1,4 +1,4 @@ -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../dependencies.ts'; import Input from './input.ts'; import Platform from './platform.ts'; diff --git a/src/model/system.integration.test.ts b/src/model/system.integration.test.ts index 57913d34..f4c24aea 100644 --- a/src/model/system.integration.test.ts +++ b/src/model/system.integration.test.ts @@ -1,4 +1,4 @@ -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; import System from './system.ts'; jest.spyOn(core, 'debug').mockImplementation(() => {}); diff --git a/src/model/system.test.ts b/src/model/system.test.ts index 3020e251..b0cb3e19 100644 --- a/src/model/system.test.ts +++ b/src/model/system.test.ts @@ -1,5 +1,4 @@ -import * as core from '../../../node_modules/@actions/core'; -import * as exec from '../../../node_modules/@actions/exec'; +import { core, exec } from '../../dependencies.ts'; import System from './system.ts'; jest.spyOn(core, 'debug').mockImplementation(() => {}); diff --git a/src/model/system.ts b/src/model/system.ts index 4255e5ad..51719027 100644 --- a/src/model/system.ts +++ b/src/model/system.ts @@ -1,5 +1,4 @@ -import * as core from '../../node_modules/@actions/core'; -import { exec } from '../../node_modules/@actions/exec'; +import { core, exec } from '../dependencies.ts'; class System { static async run(command, arguments_: any = [], options = {}, shouldLog = true) { diff --git a/src/model/versioning.test.ts b/src/model/versioning.test.ts index 80eb38c0..765eed28 100644 --- a/src/model/versioning.test.ts +++ b/src/model/versioning.test.ts @@ -1,4 +1,4 @@ -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; import NotImplementedException from './error/not-implemented-exception.ts'; import System from './system.ts'; import Versioning from './versioning.ts'; diff --git a/src/model/versioning.ts b/src/model/versioning.ts index 07da279f..60b08fb2 100644 --- a/src/model/versioning.ts +++ b/src/model/versioning.ts @@ -1,4 +1,4 @@ -import * as core from '../../../node_modules/@actions/core'; +import { core } from '../../dependencies.ts'; import NotImplementedException from './error/not-implemented-exception.ts'; import ValidationError from './error/validation-error.ts'; import Input from './input.ts';