Skip to content

Commit

Permalink
Revert "chore: cleanup stale resources in CodeBuild (#12779)" (#12853)
Browse files Browse the repository at this point in the history
This reverts commit de98654.
  • Loading branch information
jhockett committed Jun 22, 2023
1 parent b711771 commit d19d17e
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 1,727 deletions.
7 changes: 1 addition & 6 deletions codebuild_specs/cleanup_resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@ env:
phases:
build:
commands:
- cd ./scripts
- npm install -g ts-node
- npm install aws-sdk
- ts-node ./wait-for-all-codebuild.ts $CODEBUILD_RESOLVED_SOURCE_VERSION ../$WAIT_FOR_IDS_FILE_PATH AmplifyCLI-E2E-Testing
- cd ..
- source ./shared-scripts.sh && _cleanUpResources
- echo cleanup running
8 changes: 0 additions & 8 deletions codebuild_specs/e2e_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,3 @@ batch:
debug-session: true
depend-on:
- upload_pkg_binaries
- identifier: cleanup_resources
buildspec: codebuild_specs/cleanup_resources.yml
env:
compute-type: BUILD_GENERAL1_LARGE
variables:
WAIT_FOR_IDS_FILE_PATH: ./codebuild_specs/wait_for_ids_local.json
depend-on:
- upload_pkg_binaries
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/cli-test-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CLIEnvironment extends NodeEnvironment {
return this.testName;
};

this.global.getDescribeBlocks = () => {
this.global.getDescibeBlocks = () => {
return this.describeBlocks.filter((b) => b !== 'ROOT_DESCRIBE_BLOCK');
};

Expand Down
24 changes: 12 additions & 12 deletions packages/amplify-e2e-core/src/init/initProjectHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable func-style */
import { EOL } from 'os';
import { v4 as uuid } from 'uuid';
import { nspawn as spawn, getCLIPath, singleSelect, addCICleanupTags } from '..';
import { nspawn as spawn, getCLIPath, singleSelect, addCircleCITags } from '..';
import { KEY_DOWN_ARROW } from '../utils';
import { amplifyRegions } from '../configure';

Expand Down Expand Up @@ -39,7 +39,7 @@ export function initJSProjectWithProfile(cwd: string, settings?: Partial<typeof
};
}

addCICleanupTags(cwd);
addCircleCITags(cwd);

const cliArgs = ['init'];
const providerConfigSpecified = !!s.providerConfig && typeof s.providerConfig === 'object';
Expand Down Expand Up @@ -98,7 +98,7 @@ export function initJSProjectWithProfile(cwd: string, settings?: Partial<typeof
export function initAndroidProjectWithProfile(cwd: string, settings: Partial<typeof defaultSettings>): Promise<void> {
const s = { ...defaultSettings, ...settings };

addCICleanupTags(cwd);
addCircleCITags(cwd);

let env;

Expand Down Expand Up @@ -135,7 +135,7 @@ export function initAndroidProjectWithProfile(cwd: string, settings: Partial<typ
.wait(/Try "amplify add api" to create a backend API and then "amplify (push|publish)" to deploy everything/)
.run((err: Error) => {
if (!err) {
addCICleanupTags(cwd);
addCircleCITags(cwd);

resolve();
} else {
Expand All @@ -154,7 +154,7 @@ export function createRandomName(): string {
export function initIosProjectWithProfile(cwd: string, settings: Record<string, unknown>): Promise<void> {
const s = { ...defaultSettings, ...settings };

addCICleanupTags(cwd);
addCircleCITags(cwd);

let env;

Expand Down Expand Up @@ -189,7 +189,7 @@ export function initIosProjectWithProfile(cwd: string, settings: Record<string,
.wait(/Try "amplify add api" to create a backend API and then "amplify (push|publish)" to deploy everything/)
.run((err: Error) => {
if (!err) {
addCICleanupTags(cwd);
addCircleCITags(cwd);

resolve();
} else {
Expand All @@ -202,7 +202,7 @@ export function initIosProjectWithProfile(cwd: string, settings: Record<string,
export function initFlutterProjectWithProfile(cwd: string, settings: Record<string, unknown>): Promise<void> {
const s = { ...defaultSettings, ...settings };

addCICleanupTags(cwd);
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), ['init'], { cwd, stripColors: true })
Expand Down Expand Up @@ -245,7 +245,7 @@ export function initProjectWithAccessKey(
): Promise<void> {
const s = { ...defaultSettings, ...settings };

addCICleanupTags(cwd);
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), ['init'], {
Expand Down Expand Up @@ -303,7 +303,7 @@ export function initProjectWithAccessKey(
}

export function initNewEnvWithAccessKey(cwd: string, s: { envName: string; accessKeyId: string; secretAccessKey: string }): Promise<void> {
addCICleanupTags(cwd);
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), ['init'], {
Expand Down Expand Up @@ -341,7 +341,7 @@ export function initNewEnvWithAccessKey(cwd: string, s: { envName: string; acces
}

export function initNewEnvWithProfile(cwd: string, s: { envName: string }): Promise<void> {
addCICleanupTags(cwd);
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['init'], {
Expand Down Expand Up @@ -372,7 +372,7 @@ export function initNewEnvWithProfile(cwd: string, s: { envName: string }): Prom
}

export function updatedInitNewEnvWithProfile(cwd: string, s: { envName: string }): Promise<void> {
addCICleanupTags(cwd);
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['init'], {
Expand Down Expand Up @@ -409,7 +409,7 @@ export function amplifyInitSandbox(cwd: string, settings: Record<string, unknown
};
}

addCICleanupTags(cwd);
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['init'], { cwd, stripColors: true, env })
Expand Down
84 changes: 0 additions & 84 deletions packages/amplify-e2e-core/src/utils/add-ci-cleanup-tags.ts

This file was deleted.

55 changes: 55 additions & 0 deletions packages/amplify-e2e-core/src/utils/add-circleci-tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { stateManager } from '@aws-amplify/amplify-cli-core';

declare global {
/* eslint-disable @typescript-eslint/no-namespace */
namespace NodeJS {
interface Global {
getTestName?: () => string;
getHookName?: () => string;
getDescibeBlocks?: () => string[];
}
}
/* eslint-enable */
}

export const addCircleCITags = (projectPath: string): void => {
if (process.env && process.env['CIRCLECI']) {
const tags = stateManager.getProjectTags(projectPath);

const addTagIfNotExist = (key: string, value: string): void => {
if (!tags.find((t) => t.Key === key)) {
tags.push({
Key: key,
Value: value,
});
}
};

addTagIfNotExist('circleci', sanitizeTagValue(process.env['CIRCLECI'] || 'N/A'));
addTagIfNotExist('circleci:branch', sanitizeTagValue(process.env['CIRCLE_BRANCH'] || 'N/A'));
addTagIfNotExist('circleci:sha1', sanitizeTagValue(process.env['CIRCLE_SHA1'] || 'N/A'));
addTagIfNotExist('circleci:workflow_id', sanitizeTagValue(process.env['CIRCLE_WORKFLOW_ID'] || 'N/A'));
addTagIfNotExist('circleci:build_id', sanitizeTagValue(process.env['CIRCLE_BUILD_NUM'] || 'N/A'));
addTagIfNotExist('circleci:build_url', sanitizeTagValue(process.env['CIRCLE_BUILD_URL'] || 'N/A'));
addTagIfNotExist('circleci:job', sanitizeTagValue(process.env['CIRCLE_JOB'] || 'N/A'));
addTagIfNotExist('circleci:create_time', new Date().toISOString());
// exposed by custom CLI test environment
if (global.getTestName) {
addTagIfNotExist('jest:test_name', sanitizeTagValue(global.getTestName().substr(0, 255) || 'N/A'));
}
if (global.getHookName) {
addTagIfNotExist('jest:hook_name', sanitizeTagValue(global.getHookName().substr(0, 255) || 'N/A'));
}
if (global.getDescibeBlocks) {
global.getDescibeBlocks().forEach((blockName, i) => {
addTagIfNotExist(`jest:describe_${i + 1}`, sanitizeTagValue(blockName.substr(0, 255) || 'N/A'));
});
}

stateManager.setProjectFileTags(projectPath, tags);
}
};

export function sanitizeTagValue(value: string): string {
return value.replace(/[^ a-z0-9_.:/=+\-@]/gi, '');
}
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import execa from 'execa';
import { v4 as uuid } from 'uuid';
import { getLayerDirectoryName, LayerDirectoryType } from '..';

export * from './add-ci-cleanup-tags';
export * from './add-circleci-tags';
export * from './api';
export * from './appsync';
export * from './envVars';
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-e2e-core/src/utils/pinpoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Pinpoint } from 'aws-sdk';
import _ from 'lodash';
import { EOL } from 'os';
import { getCLIPath, nspawn as spawn, singleSelect, amplifyRegions, addCICleanupTags, KEY_DOWN_ARROW } from '..';
import { getCLIPath, nspawn as spawn, singleSelect, amplifyRegions, addCircleCITags, KEY_DOWN_ARROW } from '..';

const settings = {
name: EOL,
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function pinpointAppExist(pinpointProjectId: string, region: string
* initializes a project to test pinpoint
*/
export function initProjectForPinpoint(cwd: string): Promise<void> {
addCICleanupTags(cwd);
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), ['init'], {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-tests/src/cleanup-e2e-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const STALE_DURATION_MS = 2 * 60 * 60 * 1000; // 2 hours in milliseconds
*/
const handleExpiredTokenException = (): void => {
console.log('Token expired. Exiting...');
process.exit(1);
process.exit();
};

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-e2e-tests/src/init-special-cases/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { nspawn as spawn, getCLIPath, singleSelect, amplifyRegions, addCICleanupTags, KEY_DOWN_ARROW } from '@aws-amplify/amplify-e2e-core';
import { nspawn as spawn, getCLIPath, singleSelect, amplifyRegions, addCircleCITags, KEY_DOWN_ARROW } from '@aws-amplify/amplify-e2e-core';
import fs from 'fs-extra';
import os from 'os';

Expand Down Expand Up @@ -41,7 +41,7 @@ export async function initWithoutCredentialFileAndNoNewUserSetup(projRoot) {
}

async function initWorkflow(cwd: string, settings: { accessKeyId: string; secretAccessKey: string; region: string }): Promise<void> {
addCICleanupTags(cwd);
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), ['init'], {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addCICleanupTags, getCLIPath, nspawn as spawn } from '@aws-amplify/amplify-e2e-core';
import { addCircleCITags, getCLIPath, nspawn as spawn } from '@aws-amplify/amplify-e2e-core';
import { EOL } from 'os';

const defaultSettings = {
Expand Down Expand Up @@ -32,7 +32,7 @@ export function initJSProjectWithProfileV10(cwd: string, settings?: Partial<type
};
}

addCICleanupTags(cwd);
addCircleCITags(cwd);

const cliArgs = ['init'];
const providerConfigSpecified = !!s.providerConfig && typeof s.providerConfig === 'object';
Expand Down

0 comments on commit d19d17e

Please sign in to comment.