Skip to content

Commit 1f95fed

Browse files
committed
Fix package name, simplify logic
1 parent b4cf6b9 commit 1f95fed

File tree

5 files changed

+74
-37
lines changed

5 files changed

+74
-37
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"request": "launch",
77
"name": "Debug Main",
88
"program": "${workspaceFolder}/lib/main.js",
9-
"preLaunchTask": "npm: build",
9+
"preLaunchTask": "npm: build:ide",
1010
"outFiles": ["${workspaceFolder}/lib/**/*.js"],
1111
"outputCapture": "std",
1212
"env": {

dist/index.js

Lines changed: 17 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2-
"name": "github-action-aws-cloudformation",
2+
"name": "github-action-aws-s3",
33
"version": "0.0.0",
44
"private": true,
55
"description": "A GitHub Action to create/update your CloudFormation stack",
66
"main": "lib/main.js",
77
"type": "module",
88
"scripts": {
99
"build": "tsc -p tsconfig.build.json",
10+
"build:ide": "npm run build -- --sourceMap",
1011
"format": "prettier --write '**/*.{ts,json,svg,md,yml}'",
1112
"format-check": "prettier --check '**/*.{ts,json,svg,md,yml}'",
1213
"lint": "eslint src/**/*.ts",
@@ -19,7 +20,7 @@
1920
},
2021
"repository": {
2122
"type": "git",
22-
"url": "git+https://github.com/badsyntax/github-action-aws-cloudformation.git"
23+
"url": "git+https://github.com/badsyntax/github-action-aws-s3.git"
2324
},
2425
"keywords": [
2526
"actions",

src/s3.ts

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -261,39 +261,27 @@ export function generateSyncCriteria(syncStrategy: string): string[] {
261261
.filter((criteria) => !!criteria);
262262
}
263263

264-
export async function syncFilesToS3(
264+
async function getFilesToUpload(
265265
client: S3Client,
266266
s3BucketName: string,
267267
srcDir: string,
268268
filesGlob: string,
269269
prefix: S3ObjectPrefix | string,
270270
stripExtensionGlob: string,
271271
cacheControl: string,
272-
acl: PutObjectRequest['ACL'],
273272
multipartFileSizeMb: number,
274273
multipartChunkBytes: number,
275274
concurrency: number,
276-
syncStrategy: string
277-
): Promise<string[]> {
278-
const startTime = process.hrtime();
279-
280-
if (!workspace) {
281-
throw new Error('GITHUB_WORKSPACE is not defined');
282-
}
283-
info(`Syncing files from ${srcDir} with ${concurrency} concurrent processes`);
284-
275+
syncCriteria: string[],
276+
workspace: string
277+
) {
285278
const rootDir = path.join(workspace, srcDir);
286-
const files = await getFilesFromSrcDir(srcDir, filesGlob);
287-
279+
const localFiles = await getFilesFromSrcDir(srcDir, filesGlob);
288280
const filesToUpload: FileToUpload[] = [];
289281

290-
const syncCriteria = generateSyncCriteria(syncStrategy);
291-
292-
debug(`Sync criteria: ${syncCriteria.join(',')}`);
293-
294-
await new AsyncBatchQueue(
282+
return new AsyncBatchQueue(
295283
concurrency,
296-
files.map((file) => async () => {
284+
localFiles.map((file) => async () => {
297285
const s3Key = getObjectKeyFromFilePath(
298286
rootDir,
299287
file,
@@ -335,11 +323,54 @@ export async function syncFilesToS3(
335323
info(`Skipped ${s3Key} (no-change)`);
336324
}
337325
})
338-
).process();
326+
)
327+
.process()
328+
.then(() => filesToUpload);
329+
}
330+
331+
export async function syncFilesToS3(
332+
client: S3Client,
333+
s3BucketName: string,
334+
srcDir: string,
335+
filesGlob: string,
336+
prefix: S3ObjectPrefix | string,
337+
stripExtensionGlob: string,
338+
cacheControl: string,
339+
acl: PutObjectRequest['ACL'],
340+
multipartFileSizeMb: number,
341+
multipartChunkBytes: number,
342+
concurrency: number,
343+
syncStrategy: string
344+
): Promise<string[]> {
345+
const startTime = process.hrtime();
346+
347+
if (!workspace) {
348+
throw new Error('GITHUB_WORKSPACE is not defined');
349+
}
350+
info(`Syncing files from ${srcDir} with ${concurrency} concurrent processes`);
351+
352+
const syncCriteria = generateSyncCriteria(syncStrategy);
353+
354+
debug(`Sync criteria: ${syncCriteria.join(',')}`);
355+
356+
const filesToUpload = await getFilesToUpload(
357+
client,
358+
s3BucketName,
359+
srcDir,
360+
filesGlob,
361+
prefix,
362+
stripExtensionGlob,
363+
cacheControl,
364+
multipartFileSizeMb,
365+
multipartChunkBytes,
366+
concurrency,
367+
syncCriteria,
368+
workspace
369+
);
339370

340371
const smallFiles = filesToUpload.filter((file) => !file.multipart);
341372
const multipartFiles = filesToUpload.filter((file) => file.multipart);
342-
const totalFiles = smallFiles.length + multipartFiles.length;
373+
const totalFiles = filesToUpload.length;
343374

344375
if (totalFiles > 0) {
345376
info(

0 commit comments

Comments
 (0)