chore: load input from user and yaml

pull/413/head
Webber 2022-06-23 22:22:08 +02:00
parent f2868f89d8
commit 931dff7df8
10 changed files with 35 additions and 27 deletions

View File

@ -3,7 +3,7 @@ import * as assert from 'https://deno.land/std@0.144.0/testing/asserts.ts';
import * as aws from 'https://deno.land/x/aws_api/client/mod.ts'; import * as aws from 'https://deno.land/x/aws_api/client/mod.ts';
import * as base64 from 'https://deno.land/std@0.145.0/encoding/base64.ts'; import * as base64 from 'https://deno.land/std@0.145.0/encoding/base64.ts';
import * as compress from 'https://deno.land/x/compress@v0.3.3/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 core from 'https://deno.land/x/deno_actions_core@0.1.3/mod.ts';
import * as fs from 'https://deno.land/std@0.142.0/node/fs/promises.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/fs/mod.ts'; import * as fsSync from 'https://deno.land/std@0.142.0/fs/mod.ts';
import * as k8s from 'https://deno.land/x/kubernetes_client/mod.ts'; import * as k8s from 'https://deno.land/x/kubernetes_client/mod.ts';
@ -17,11 +17,27 @@ import * as yaml from 'https://deno.land/std@0.145.0/encoding/yaml.ts';
import { crypto } from 'https://deno.land/std@0.142.0/crypto/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'; import { v4 as uuid } from 'https://deno.land/std@0.142.0/uuid/mod.ts';
import * as http from 'https://deno.land/std@0.145.0/node/http.ts'; import * as http from 'https://deno.land/std@0.145.0/node/http.ts';
import { Command } from 'https://deno.land/x/cmd@v1.2.0/commander/index.ts';
const core = { const core = {
setFailed: () => {}, info: console.log,
info: () => {}, error: (error) => console.error(error, error.stack),
error: () => {}, setFailed: (failure) => console.error('setFailed:', failure),
// Adapted from: https://github.com/actions/toolkit/blob/9b7bcb1567c9b7f134eb3c2d6bbf409a5106a956/packages/core/src/core.ts#L128
getInput: (name, options) => {
const val: string = Deno.env.get(`INPUT_${name.replace(/ /g, '_').toUpperCase()}`) || '';
if (options?.required && !val) {
throw new Error(`Input required and not supplied: ${name}`);
}
if (options && options.trimWhitespace === false) {
return val;
}
return val.trim();
},
}; };
const exec = () => { const exec = () => {
@ -32,26 +48,17 @@ const getUnityChangeSet = () => {
throw new Error('getUnityChangeSet is not implemented'); // unity-changeset' 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 { class Writable {
constructor() { constructor() {
throw new Error('Writable is not implemented'); // stream throw new Error('Writable is not implemented'); // stream
} }
} }
class Command { // class Command {
constructor() { // constructor() {
throw new Error('Command is not implemented'); // commander-ts // throw new Error('Command is not implemented'); // commander-ts
} // }
} // }
const __filename = path.fromFileUrl(import.meta.url); const __filename = path.fromFileUrl(import.meta.url);
const __dirname = path.dirname(path.fromFileUrl(import.meta.url)); const __dirname = path.dirname(path.fromFileUrl(import.meta.url));

View File

@ -34,6 +34,7 @@ async function runMain() {
// Set output // Set output
await Output.setBuildVersion(buildParameters.buildVersion); await Output.setBuildVersion(buildParameters.buildVersion);
} catch (error) { } catch (error) {
core.error(error);
core.setFailed((error as Error).message); core.setFailed((error as Error).message);
} }
} }

View File

@ -1,4 +1,4 @@
import { path, __dirname } from '../dependencies.ts'; import { path, __dirname, __filename } from '../dependencies.ts';
class Action { class Action {
static get supportedPlatforms() { static get supportedPlatforms() {

View File

@ -48,7 +48,7 @@ describe('Cloud Runner Caching', () => {
await CloudRunnerSystem.Run(`tree ${cacheFolder}`); await CloudRunnerSystem.Run(`tree ${cacheFolder}`);
// Compare validity to original hash // Compare validity to original hash
expect(fs.readFileSync(path.resolve(testFolder, 'test.txt'), { encoding: 'utf8' }).toString()).toContain( expect(Deno.readTextFileSync(path.resolve(testFolder, 'test.txt'), { encoding: 'utf8' }).toString()).toContain(
Cli.options.cacheKey, Cli.options.cacheKey,
); );
fs.rmdirSync(testFolder, { recursive: true }); fs.rmdirSync(testFolder, { recursive: true });

View File

@ -1,4 +1,4 @@
import { fs, assert, path } from '../../../dependencies.ts'; import { fsSync as fs, assert, path } from '../../../dependencies.ts';
import CloudRunner from '../cloud-runner.ts'; import CloudRunner from '../cloud-runner.ts';
import { CloudRunnerFolders } from '../services/cloud-runner-folders.ts'; import { CloudRunnerFolders } from '../services/cloud-runner-folders.ts';
import { Caching } from './caching.ts'; import { Caching } from './caching.ts';

View File

@ -7,7 +7,7 @@ export class ActionYamlReader {
if (!fs.existsSync(filename)) { if (!fs.existsSync(filename)) {
filename = path.join(__dirname, `..`, filename); filename = path.join(__dirname, `..`, filename);
} }
this.actionYamlParsed = yaml.parse(fs.readFileSync(filename).toString()); this.actionYamlParsed = yaml.parse(Deno.readTextFileSync(filename));
} }
public GetActionYamlValue(key: string) { public GetActionYamlValue(key: string) {
return this.actionYamlParsed.inputs[key]?.description || 'No description found in action.yml'; return this.actionYamlParsed.inputs[key]?.description || 'No description found in action.yml';

View File

@ -1,5 +1,5 @@
import { assert } from 'https://deno.land/std@0.142.0/testing/asserts.ts'; import { assert } from 'https://deno.land/std@0.142.0/testing/asserts.ts';
import { fs } from '../../dependencies.ts'; import { fsSync as fs } from '../../dependencies.ts';
import { CloudRunnerSystem } from '../cloud-runner/services/cloud-runner-system.ts'; import { CloudRunnerSystem } from '../cloud-runner/services/cloud-runner-system.ts';
import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger.ts'; import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger.ts';
import Input from '../input.ts'; import Input from '../input.ts';

View File

@ -7,5 +7,5 @@ export function ReadLicense() {
} }
const pipelineFile = path.join(__dirname, `.github`, `workflows`, `cloud-runner-k8s-pipeline.yml`); const pipelineFile = path.join(__dirname, `.github`, `workflows`, `cloud-runner-k8s-pipeline.yml`);
return fs.existsSync(pipelineFile) ? yaml.parse(fs.readFileSync(pipelineFile, 'utf8')).env.UNITY_LICENSE : ''; return fs.existsSync(pipelineFile) ? yaml.parse(Deno.readTextFileSync(pipelineFile, 'utf8')).env.UNITY_LICENSE : '';
} }

View File

@ -1,4 +1,4 @@
import { fs, path, core } from '../dependencies.ts'; import { fsSync as fs, path, core } from '../dependencies.ts';
import { Cli } from './cli/cli.ts'; import { Cli } from './cli/cli.ts';
import CloudRunnerQueryOverride from './cloud-runner/services/cloud-runner-query-override.ts'; import CloudRunnerQueryOverride from './cloud-runner/services/cloud-runner-query-override.ts';
import Platform from './platform.ts'; import Platform from './platform.ts';

View File

@ -1,4 +1,4 @@
import { fs, path } from '../dependencies.ts'; import { fsSync as fs, path } from '../dependencies.ts';
export default class UnityVersioning { export default class UnityVersioning {
static get versionPattern() { static get versionPattern() {
@ -19,7 +19,7 @@ export default class UnityVersioning {
throw new Error(`Project settings file not found at "${filePath}". Have you correctly set the projectPath?`); throw new Error(`Project settings file not found at "${filePath}". Have you correctly set the projectPath?`);
} }
return UnityVersioning.parse(fs.readFileSync(filePath, 'utf8')); return UnityVersioning.parse(Deno.readTextFileSync(filePath, 'utf8'));
} }
static parse(projectVersionTxt) { static parse(projectVersionTxt) {