chore: rewrite core and exec imports to deno style

pull/413/head
Webber 2022-06-08 23:54:32 +02:00
parent b62407866b
commit f360ad6045
21 changed files with 77 additions and 49 deletions

View File

@ -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,
};

View File

@ -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';

View File

@ -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) {

View File

@ -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';

View File

@ -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 {

View File

@ -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,

View File

@ -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) {

View File

@ -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++) {

View File

@ -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) {

View File

@ -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 {

View File

@ -1,4 +1,4 @@
import * as core from '../../../node_modules/@actions/core';
import { core } from '../../dependencies.ts';
class CloudRunnerLogger {
private static timestamp: number;

View File

@ -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';

View File

@ -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 {

View File

@ -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.

View File

@ -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 {

View File

@ -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';

View File

@ -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(() => {});

View File

@ -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(() => {});

View File

@ -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) {

View File

@ -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';

View File

@ -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';