garbage-collect-aws cli can iterate over aws resources and cli scans all ts files
parent
fb5cd96729
commit
de5d58a3e5
|
|
@ -405,13 +405,54 @@ exports["default"] = Cache;
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 8731:
|
/***/ 8731:
|
||||||
/***/ ((__unused_webpack_module, exports) => {
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.GetAllCliModes = exports.GetCliFunctions = exports.CliFunction = void 0;
|
exports.GetAllCliModes = exports.GetCliFunctions = exports.CliFunction = exports.RequireAll = exports.ThroughDirectory = void 0;
|
||||||
|
const fs_1 = __importDefault(__nccwpck_require__(57147));
|
||||||
|
const path_1 = __importDefault(__nccwpck_require__(71017));
|
||||||
const targets = new Array();
|
const targets = new Array();
|
||||||
|
const Files = [];
|
||||||
|
function ThroughDirectory(Directory) {
|
||||||
|
for (const File of fs_1.default.readdirSync(Directory)) {
|
||||||
|
const Absolute = path_1.default.join(Directory, File);
|
||||||
|
if (Absolute.includes(`__`)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Absolute.includes('.test.ts')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Absolute.includes('jest')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Absolute === __dirname) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (fs_1.default.statSync(Absolute).isDirectory()) {
|
||||||
|
ThroughDirectory(Absolute);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Absolute.endsWith('.ts')) {
|
||||||
|
Files.push(Absolute);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return Files;
|
||||||
|
}
|
||||||
|
exports.ThroughDirectory = ThroughDirectory;
|
||||||
|
function RequireAll(folder) {
|
||||||
|
const files = ThroughDirectory(folder);
|
||||||
|
for (const element of files) {
|
||||||
|
require(path_1.default.relative(__dirname, element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.RequireAll = RequireAll;
|
||||||
function CliFunction(key, description) {
|
function CliFunction(key, description) {
|
||||||
return function (target, propertyKey, descriptor) {
|
return function (target, propertyKey, descriptor) {
|
||||||
targets.push({
|
targets.push({
|
||||||
|
|
@ -496,6 +537,7 @@ const action_yaml_1 = __nccwpck_require__(11091);
|
||||||
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
|
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
|
||||||
const cli_decorator_1 = __nccwpck_require__(8731);
|
const cli_decorator_1 = __nccwpck_require__(8731);
|
||||||
const cloud_runner_query_override_1 = __importDefault(__nccwpck_require__(31011));
|
const cloud_runner_query_override_1 = __importDefault(__nccwpck_require__(31011));
|
||||||
|
const path_1 = __importDefault(__nccwpck_require__(71017));
|
||||||
class CLI {
|
class CLI {
|
||||||
static get cliMode() {
|
static get cliMode() {
|
||||||
return CLI.options !== undefined && CLI.options.mode !== undefined && CLI.options.mode !== '';
|
return CLI.options !== undefined && CLI.options.mode !== undefined && CLI.options.mode !== '';
|
||||||
|
|
@ -535,6 +577,9 @@ class CLI {
|
||||||
yield cloud_runner_query_override_1.default.PopulateQueryOverrideInput();
|
yield cloud_runner_query_override_1.default.PopulateQueryOverrideInput();
|
||||||
}
|
}
|
||||||
CLI.logInput();
|
CLI.logInput();
|
||||||
|
if (require.main && require.main.filename.endsWith('.ts')) {
|
||||||
|
cli_decorator_1.RequireAll(path_1.default.dirname(require.main.filename));
|
||||||
|
}
|
||||||
const results = cli_decorator_1.GetCliFunctions(CLI.options.mode);
|
const results = cli_decorator_1.GetCliFunctions(CLI.options.mode);
|
||||||
cloud_runner_logger_1.default.log(`Entrypoint: ${results.key}`);
|
cloud_runner_logger_1.default.log(`Entrypoint: ${results.key}`);
|
||||||
CLI.options.versioning = 'None';
|
CLI.options.versioning = 'None';
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,44 @@
|
||||||
|
import FS from 'fs';
|
||||||
|
import Path from 'path';
|
||||||
|
|
||||||
const targets = new Array();
|
const targets = new Array();
|
||||||
|
const Files: any[] = [];
|
||||||
|
|
||||||
|
export function ThroughDirectory(Directory) {
|
||||||
|
for (const File of FS.readdirSync(Directory)) {
|
||||||
|
const Absolute = Path.join(Directory, File);
|
||||||
|
if (Absolute.includes(`__`)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Absolute.includes('.test.ts')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Absolute.includes('jest')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Absolute === __dirname) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (FS.statSync(Absolute).isDirectory()) {
|
||||||
|
ThroughDirectory(Absolute);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Absolute.endsWith('.ts')) {
|
||||||
|
Files.push(Absolute);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return Files;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RequireAll(folder) {
|
||||||
|
const files = ThroughDirectory(folder);
|
||||||
|
for (const element of files) {
|
||||||
|
require(Path.relative(__dirname, element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function CliFunction(key: string, description: string) {
|
export function CliFunction(key: string, description: string) {
|
||||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||||
targets.push({
|
targets.push({
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ import { BuildParameters, CloudRunner, ImageTag, Input } from '..';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { ActionYamlReader } from '../input-readers/action-yaml';
|
import { ActionYamlReader } from '../input-readers/action-yaml';
|
||||||
import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger';
|
import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger';
|
||||||
import { CliFunction, GetAllCliModes, GetCliFunctions } from './cli-decorator';
|
import { CliFunction, GetAllCliModes, GetCliFunctions, RequireAll } from './cli-decorator';
|
||||||
import CloudRunnerQueryOverride from '../cloud-runner/services/cloud-runner-query-override';
|
import CloudRunnerQueryOverride from '../cloud-runner/services/cloud-runner-query-override';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
export class CLI {
|
export class CLI {
|
||||||
public static options;
|
public static options;
|
||||||
|
|
@ -50,6 +51,9 @@ export class CLI {
|
||||||
await CloudRunnerQueryOverride.PopulateQueryOverrideInput();
|
await CloudRunnerQueryOverride.PopulateQueryOverrideInput();
|
||||||
}
|
}
|
||||||
CLI.logInput();
|
CLI.logInput();
|
||||||
|
if (require.main && require.main.filename.endsWith('.ts')) {
|
||||||
|
RequireAll(path.dirname(require.main.filename));
|
||||||
|
}
|
||||||
const results = GetCliFunctions(CLI.options.mode);
|
const results = GetCliFunctions(CLI.options.mode);
|
||||||
CloudRunnerLogger.log(`Entrypoint: ${results.key}`);
|
CloudRunnerLogger.log(`Entrypoint: ${results.key}`);
|
||||||
CLI.options.versioning = 'None';
|
CLI.options.versioning = 'None';
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,25 @@ export class AWSCLICommands {
|
||||||
@CliFunction(`garbage-collect-aws`, `garbage collect aws`)
|
@CliFunction(`garbage-collect-aws`, `garbage collect aws`)
|
||||||
static async garbageCollectAws() {
|
static async garbageCollectAws() {
|
||||||
process.env.AWS_REGION = Input.region;
|
process.env.AWS_REGION = Input.region;
|
||||||
|
CloudRunnerLogger.log(`Cloud Formation stacks`);
|
||||||
const CF = new AWS.CloudFormation();
|
const CF = new AWS.CloudFormation();
|
||||||
|
const stacks =
|
||||||
const stacks = (await CF.listStacks().promise()).StackSummaries?.filter(
|
(await CF.listStacks().promise()).StackSummaries?.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE') || [];
|
||||||
(_x) => _x.StackStatus !== 'DELETE_COMPLETE',
|
for (const element of stacks) {
|
||||||
);
|
CloudRunnerLogger.log(JSON.stringify(element, undefined, 4));
|
||||||
|
if (Input.cloudRunnerTests) await CF.deleteStack({ StackName: element.StackName }).promise();
|
||||||
|
}
|
||||||
|
CloudRunnerLogger.log(`ECS Clusters`);
|
||||||
|
const ecs = new AWS.ECS();
|
||||||
|
const clusters = (await ecs.listClusters().promise()).clusterArns || [];
|
||||||
if (stacks === undefined) {
|
if (stacks === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CloudRunnerLogger.log(`Cloud Formation stacks`);
|
for (const element of clusters) {
|
||||||
for (const element of stacks) {
|
const input: AWS.ECS.ListTasksRequest = {
|
||||||
CloudRunnerLogger.log(JSON.stringify(element, undefined, 4));
|
cluster: element,
|
||||||
await CF.deleteStack({ StackName: element.StackName }).promise();
|
};
|
||||||
|
CloudRunnerLogger.log(JSON.stringify(await ecs.listTasks(input).promise(), undefined, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudRunnerLogger.log(`ECS Clusters`);
|
|
||||||
const ecs = new AWS.ECS();
|
|
||||||
CloudRunnerLogger.log(JSON.stringify(await ecs.listClusters().promise(), undefined, 4));
|
|
||||||
CloudRunnerLogger.log(JSON.stringify(await ecs.describeClusters().promise(), undefined, 4));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,18 @@ describe('Cloud Runner', () => {
|
||||||
};
|
};
|
||||||
Input.githubInputEnabled = false;
|
Input.githubInputEnabled = false;
|
||||||
const buildParameter = await BuildParameters.create();
|
const buildParameter = await BuildParameters.create();
|
||||||
Input.githubInputEnabled = true;
|
|
||||||
const baseImage = new ImageTag(buildParameter);
|
const baseImage = new ImageTag(buildParameter);
|
||||||
const results = await CloudRunner.run(buildParameter, baseImage.toString());
|
const results = await CloudRunner.run(buildParameter, baseImage.toString());
|
||||||
const libraryString = 'Rebuilding Library because the asset database could not be found!';
|
const libraryString = 'Rebuilding Library because the asset database could not be found!';
|
||||||
|
const buildSucceededString = 'Build succeeded';
|
||||||
expect(results).toContain(libraryString);
|
expect(results).toContain(libraryString);
|
||||||
|
expect(results).toContain(buildSucceededString);
|
||||||
const buildParameter2 = await BuildParameters.create();
|
const buildParameter2 = await BuildParameters.create();
|
||||||
const baseImage2 = new ImageTag(buildParameter2);
|
const baseImage2 = new ImageTag(buildParameter2);
|
||||||
const results2 = await CloudRunner.run(buildParameter2, baseImage2.toString());
|
const results2 = await CloudRunner.run(buildParameter2, baseImage2.toString());
|
||||||
|
expect(results2).toContain(buildSucceededString);
|
||||||
expect(results2).toEqual(expect.not.stringContaining(libraryString));
|
expect(results2).toEqual(expect.not.stringContaining(libraryString));
|
||||||
|
Input.githubInputEnabled = true;
|
||||||
delete CLI.options;
|
delete CLI.options;
|
||||||
}, 1000000);
|
}, 1000000);
|
||||||
it('All build parameters sent to cloud runner as env vars', async () => {
|
it('All build parameters sent to cloud runner as env vars', async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue