Implement actionYamlReader

pull/310/head
Frostebite 2021-12-29 15:15:39 +00:00
parent 7880759f23
commit 01bccfcff2
7 changed files with 125 additions and 18 deletions

89
dist/index.js vendored
View File

@ -380,6 +380,7 @@ const commander_ts_1 = __webpack_require__(40451);
const __1 = __webpack_require__(41359);
const core = __importStar(__webpack_require__(42186));
const remote_client_1 = __webpack_require__(95575);
const action_yaml_1 = __webpack_require__(11091);
class CLI {
static RunCli(options) {
return __awaiter(this, void 0, void 0, function* () {
@ -414,7 +415,7 @@ class CLI {
core.info(`INPUT:`);
for (const element of properties) {
// TODO pull description from action.yml
program.option(`--${element} <${element}>`, ' ');
program.option(`--${element} <${element}>`, action_yaml_1.ActionYamlReader.Instance.GetActionYamlValue(element));
if (__1.Input[element] !== undefined && __1.Input[element] !== '') {
core.info(`${element} ${__1.Input[element]}`);
}
@ -3421,6 +3422,73 @@ const cloud_runner_1 = __importDefault(__webpack_require__(79144));
exports.CloudRunner = cloud_runner_1.default;
/***/ }),
/***/ 11091:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ActionYamlReader = void 0;
const fs_1 = __importDefault(__webpack_require__(35747));
const yaml_1 = __importDefault(__webpack_require__(13552));
class ActionYamlReader {
constructor() {
ActionYamlReader.Instance = this;
this.actionYamlParsed = yaml_1.default.parse(fs_1.default.readFileSync(`action.yml`).toString());
}
GetActionYamlValue(key) {
return this.actionYamlParsed.inputs[key];
}
}
exports.ActionYamlReader = ActionYamlReader;
/***/ }),
/***/ 24271:
/***/ ((__unused_webpack_module, exports) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.GitRepoReader = void 0;
class GitRepoReader {
static GetSha() {
return '';
}
static GetRemote() {
return '';
}
static GetBranch() {
return '';
}
}
exports.GitRepoReader = GitRepoReader;
/***/ }),
/***/ 44990:
/***/ ((__unused_webpack_module, exports) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.GithubCliReader = void 0;
class GithubCliReader {
static GetGitHubAuthToken() {
// TODO Get from git auth status -t
return '';
}
}
exports.GithubCliReader = GithubCliReader;
/***/ }),
/***/ 91933:
@ -3432,6 +3500,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const git_repo_1 = __webpack_require__(24271);
const github_cli_1 = __webpack_require__(44990);
const platform_1 = __importDefault(__webpack_require__(9707));
const core = __webpack_require__(42186);
/**
@ -3456,8 +3526,7 @@ class Input {
return Input.getInput('region') || 'eu-west-2';
}
static get githubRepo() {
return Input.getInput('GITHUB_REPOSITORY') || 'game-ci/unity-builder';
// TODO system get repo remote?
return Input.getInput('GITHUB_REPOSITORY') || git_repo_1.GitRepoReader.GetRemote() || 'game-ci/unity-builder';
}
static get branch() {
if (Input.getInput(`REMOTE_BUILDER_CACHE`)) {
@ -3475,19 +3544,24 @@ class Input {
else if (Input.getInput('branch')) {
return Input.getInput('branch');
}
else if (github_cli_1.GithubCliReader.GetGitHubAuthToken()) {
return github_cli_1.GithubCliReader.GetGitHubAuthToken();
}
else {
return 'remote-builder/unified-providers';
}
// TODO git get branch?
//
}
static get gitSha() {
if (Input.getInput(`GITHUB_SHA`)) {
return Input.getInput(`GITHUB_SHA`);
}
if (Input.getInput(`GitSHA`)) {
else if (Input.getInput(`GitSHA`)) {
return Input.getInput(`GitSHA`);
}
// TODO git get sha?
else if (git_repo_1.GitRepoReader.GetSha()) {
return git_repo_1.GitRepoReader.GetSha();
}
}
static get runNumber() {
return Input.getInput('GITHUB_RUN_NUMBER') || '0';
@ -3556,8 +3630,7 @@ class Input {
return Input.getInput('sshAgent') || '';
}
static get gitPrivateToken() {
return core.getInput('gitPrivateToken') || '';
// TODO get from git auth status -t
return core.getInput('gitPrivateToken') || github_cli_1.GithubCliReader.GetGitHubAuthToken() || '';
}
static get chownFilesTo() {
return Input.getInput('chownFilesTo') || '';

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@ import { Command } from 'commander-ts';
import { BuildParameters, CloudRunner, ImageTag, Input } from '..';
import * as core from '@actions/core';
import { RemoteClient } from './remote-client';
import { ActionYamlReader } from '../input-readers/action-yaml';
export class CLI {
static async RunCli(options: any) {
@ -35,7 +36,7 @@ export class CLI {
core.info(`INPUT:`);
for (const element of properties) {
// TODO pull description from action.yml
program.option(`--${element} <${element}>`, ' ');
program.option(`--${element} <${element}>`, ActionYamlReader.Instance.GetActionYamlValue(element));
if (Input[element] !== undefined && Input[element] !== '') {
core.info(`${element} ${Input[element]}`);
}

View File

@ -0,0 +1,14 @@
import fs from 'fs';
import YAML from 'yaml';
export class ActionYamlReader {
public static Instance: ActionYamlReader;
private actionYamlParsed: any;
constructor() {
ActionYamlReader.Instance = this;
this.actionYamlParsed = YAML.parse(fs.readFileSync(`action.yml`).toString());
}
public GetActionYamlValue(key: string) {
return this.actionYamlParsed.inputs[key];
}
}

View File

@ -0,0 +1,11 @@
export class GitRepoReader {
static GetSha() {
return '';
}
static GetRemote() {
return '';
}
static GetBranch() {
return '';
}
}

View File

@ -0,0 +1,6 @@
export class GithubCliReader {
static GetGitHubAuthToken() {
// TODO Get from git auth status -t
return '';
}
}

View File

@ -1,3 +1,5 @@
import { GitRepoReader } from './input-readers/git-repo';
import { GithubCliReader } from './input-readers/github-cli';
import Platform from './platform';
const core = require('@actions/core');
@ -26,8 +28,7 @@ class Input {
return Input.getInput('region') || 'eu-west-2';
}
static get githubRepo(): string {
return Input.getInput('GITHUB_REPOSITORY') || 'game-ci/unity-builder';
// TODO system get repo remote?
return Input.getInput('GITHUB_REPOSITORY') || GitRepoReader.GetRemote() || 'game-ci/unity-builder';
}
static get branch() {
if (Input.getInput(`REMOTE_BUILDER_CACHE`)) {
@ -42,20 +43,22 @@ class Input {
.join('');
} else if (Input.getInput('branch')) {
return Input.getInput('branch');
} else if (GithubCliReader.GetGitHubAuthToken()) {
return GithubCliReader.GetGitHubAuthToken();
} else {
return 'remote-builder/unified-providers';
}
// TODO git get branch?
//
}
static get gitSha() {
if (Input.getInput(`GITHUB_SHA`)) {
return Input.getInput(`GITHUB_SHA`);
}
if (Input.getInput(`GitSHA`)) {
} else if (Input.getInput(`GitSHA`)) {
return Input.getInput(`GitSHA`);
} else if (GitRepoReader.GetSha()) {
return GitRepoReader.GetSha();
}
// TODO git get sha?
}
static get runNumber() {
return Input.getInput('GITHUB_RUN_NUMBER') || '0';
@ -147,8 +150,7 @@ class Input {
}
static get gitPrivateToken() {
return core.getInput('gitPrivateToken') || '';
// TODO get from git auth status -t
return core.getInput('gitPrivateToken') || GithubCliReader.GetGitHubAuthToken() || '';
}
static get chownFilesTo() {