From ead035dd7f4e56270fc9c6a2970aad8faa87c1c5 Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Mon, 11 Dec 2023 14:59:10 -0700 Subject: [PATCH] Instead of fs copying, just change key on AWS upload --- src/bin/vip-deploy-app.ts | 18 +++++++++--------- src/lib/manual-deploy/manual-deploy.ts | 23 ----------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/bin/vip-deploy-app.ts b/src/bin/vip-deploy-app.ts index 2069db4fa..4fa5f50fb 100755 --- a/src/bin/vip-deploy-app.ts +++ b/src/bin/vip-deploy-app.ts @@ -23,7 +23,7 @@ import { WithId, UploadArguments, } from '../lib/client-file-uploader'; -import { gates, renameFile } from '../lib/manual-deploy/manual-deploy'; +import { gates } from '../lib/manual-deploy/manual-deploy'; import { trackEventWithEnv } from '../lib/tracker'; const appQuery = ` @@ -121,6 +121,14 @@ export async function deployAppCmd( arg: string[] = [], opts: Record< string, un await track( 'deploy_app_command_execute' ); + // Upload file as different name to avoid overwriting existing same named files + const datePrefix = new Date() + .toISOString() + // eslint-disable-next-line no-useless-escape + .replace( /[\-T:\.Z]/g, '' ) + .slice( 0, 14 ); + fileMeta.basename = `${ datePrefix }-${ fileMeta.basename }`; + const deployMessage = ( opts.message as string ) ?? ''; const forceDeploy = opts.force; @@ -179,14 +187,6 @@ Processing the file for deployment to your environment... progressTracker.setUploadPercentage( percentage ); }; - try { - fileMeta = await renameFile( fileMeta ); - } catch ( err ) { - throw new Error( - `Unable to copy file to temporary working directory: ${ ( err as Error ).message }` - ); - } - const appInput = { id: appId } as WithId; const envInput = { id: envId } as WithId; const uploadParams: UploadArguments = { diff --git a/src/lib/manual-deploy/manual-deploy.ts b/src/lib/manual-deploy/manual-deploy.ts index fd67ecfbb..f5bfc49a4 100644 --- a/src/lib/manual-deploy/manual-deploy.ts +++ b/src/lib/manual-deploy/manual-deploy.ts @@ -83,26 +83,3 @@ export async function gates( app: App, env: AppEnvironment, fileMeta: FileMeta ) ); } } - -/** - * Rename file so it doesn't get overwritten. - * @param {FileMeta} fileMeta - The metadata of the file to be renamed. - * @returns {FileMeta} The updated file metadata after renaming. - */ -export async function renameFile( fileMeta: FileMeta ) { - const tmpDir = await mkdtemp( path.join( os.tmpdir(), 'vip-manual-deploys' ) ); - - const datePrefix = new Date() - .toISOString() - // eslint-disable-next-line no-useless-escape - .replace( /[\-T:\.Z]/g, '' ) - .slice( 0, 14 ); - const newFileBasename = `${ datePrefix }-${ fileMeta.basename }`; - const newFileName = `${ tmpDir }/${ newFileBasename }`; - - fs.copyFileSync( fileMeta.fileName, newFileName ); - fileMeta.fileName = newFileName; - fileMeta.basename = newFileBasename; - - return fileMeta; -}