Skip to content

Commit 4c6c2fe

Browse files
authored
Merge pull request #40 from badsyntax/list-request
List request
2 parents e407bee + 1f95fed commit 4c6c2fe

File tree

6 files changed

+100
-37
lines changed

6 files changed

+100
-37
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"warn",
2626
{
2727
"args": "after-used",
28-
"argsIgnorePattern": "^_"
28+
"argsIgnorePattern": "^_",
29+
"varsIgnorePattern": "^_"
2930
}
3031
]
3132
}

.vscode/launch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Debug Main",
8+
"program": "${workspaceFolder}/lib/main.js",
9+
"preLaunchTask": "npm: build:ide",
10+
"outFiles": ["${workspaceFolder}/lib/**/*.js"],
11+
"outputCapture": "std",
12+
"env": {
13+
"INPUT_BUCKET": "badsyntax-github-action-example-aws-s3-us-east-1",
14+
"INPUT_ACTION": "sync",
15+
"INPUT_FILES-GLOB": "**/*.css",
16+
"INPUT_SRC-DIR": "./test-fixtures",
17+
"INPUT_AWS-REGION": "us-east-1",
18+
"INPUT_PREFIX": "preview",
19+
"INPUT_CONCURRENCY": "6",
20+
"INPUT_MULTIPART-FILE-SIZE-MB": "100",
21+
"INPUT_SYNC-STRATEGY": "ETag",
22+
"INPUT_CACHE-CONTROL": "public,max-age=31536000,immutable",
23+
"GITHUB_EVENT_NAME": "pull_request",
24+
"GITHUB_ACTION": "synchronize",
25+
"GITHUB_REPOSITORY": "badsyntax/github-action-aws-s3",
26+
"GITHUB_WORKSPACE": "${workspaceFolder}"
27+
}
28+
},
429
{
530
"name": "Debug All Jest Tests",
631
"request": "launch",

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)