Skip to content

Commit

Permalink
Merge pull request #40 from badsyntax/list-request
Browse files Browse the repository at this point in the history
List request
  • Loading branch information
badsyntax authored Dec 26, 2021
2 parents e407bee + 1f95fed commit 4c6c2fe
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"warn",
{
"args": "after-used",
"argsIgnorePattern": "^_"
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_"
}
]
}
Expand Down
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Main",
"program": "${workspaceFolder}/lib/main.js",
"preLaunchTask": "npm: build:ide",
"outFiles": ["${workspaceFolder}/lib/**/*.js"],
"outputCapture": "std",
"env": {
"INPUT_BUCKET": "badsyntax-github-action-example-aws-s3-us-east-1",
"INPUT_ACTION": "sync",
"INPUT_FILES-GLOB": "**/*.css",
"INPUT_SRC-DIR": "./test-fixtures",
"INPUT_AWS-REGION": "us-east-1",
"INPUT_PREFIX": "preview",
"INPUT_CONCURRENCY": "6",
"INPUT_MULTIPART-FILE-SIZE-MB": "100",
"INPUT_SYNC-STRATEGY": "ETag",
"INPUT_CACHE-CONTROL": "public,max-age=31536000,immutable",
"GITHUB_EVENT_NAME": "pull_request",
"GITHUB_ACTION": "synchronize",
"GITHUB_REPOSITORY": "badsyntax/github-action-aws-s3",
"GITHUB_WORKSPACE": "${workspaceFolder}"
}
},
{
"name": "Debug All Jest Tests",
"request": "launch",
Expand Down
29 changes: 17 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "github-action-aws-cloudformation",
"name": "github-action-aws-s3",
"version": "0.0.0",
"private": true,
"description": "A GitHub Action to create/update your CloudFormation stack",
"main": "lib/main.js",
"type": "module",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build:ide": "npm run build -- --sourceMap",
"format": "prettier --write '**/*.{ts,json,svg,md,yml}'",
"format-check": "prettier --check '**/*.{ts,json,svg,md,yml}'",
"lint": "eslint src/**/*.ts",
Expand All @@ -19,7 +20,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/badsyntax/github-action-aws-cloudformation.git"
"url": "git+https://github.com/badsyntax/github-action-aws-s3.git"
},
"keywords": [
"actions",
Expand Down
73 changes: 52 additions & 21 deletions src/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,39 +261,27 @@ export function generateSyncCriteria(syncStrategy: string): string[] {
.filter((criteria) => !!criteria);
}

export async function syncFilesToS3(
async function getFilesToUpload(
client: S3Client,
s3BucketName: string,
srcDir: string,
filesGlob: string,
prefix: S3ObjectPrefix | string,
stripExtensionGlob: string,
cacheControl: string,
acl: PutObjectRequest['ACL'],
multipartFileSizeMb: number,
multipartChunkBytes: number,
concurrency: number,
syncStrategy: string
): Promise<string[]> {
const startTime = process.hrtime();

if (!workspace) {
throw new Error('GITHUB_WORKSPACE is not defined');
}
info(`Syncing files from ${srcDir} with ${concurrency} concurrent processes`);

syncCriteria: string[],
workspace: string
) {
const rootDir = path.join(workspace, srcDir);
const files = await getFilesFromSrcDir(srcDir, filesGlob);

const localFiles = await getFilesFromSrcDir(srcDir, filesGlob);
const filesToUpload: FileToUpload[] = [];

const syncCriteria = generateSyncCriteria(syncStrategy);

debug(`Sync criteria: ${syncCriteria.join(',')}`);

await new AsyncBatchQueue(
return new AsyncBatchQueue(
concurrency,
files.map((file) => async () => {
localFiles.map((file) => async () => {
const s3Key = getObjectKeyFromFilePath(
rootDir,
file,
Expand Down Expand Up @@ -335,11 +323,54 @@ export async function syncFilesToS3(
info(`Skipped ${s3Key} (no-change)`);
}
})
).process();
)
.process()
.then(() => filesToUpload);
}

export async function syncFilesToS3(
client: S3Client,
s3BucketName: string,
srcDir: string,
filesGlob: string,
prefix: S3ObjectPrefix | string,
stripExtensionGlob: string,
cacheControl: string,
acl: PutObjectRequest['ACL'],
multipartFileSizeMb: number,
multipartChunkBytes: number,
concurrency: number,
syncStrategy: string
): Promise<string[]> {
const startTime = process.hrtime();

if (!workspace) {
throw new Error('GITHUB_WORKSPACE is not defined');
}
info(`Syncing files from ${srcDir} with ${concurrency} concurrent processes`);

const syncCriteria = generateSyncCriteria(syncStrategy);

debug(`Sync criteria: ${syncCriteria.join(',')}`);

const filesToUpload = await getFilesToUpload(
client,
s3BucketName,
srcDir,
filesGlob,
prefix,
stripExtensionGlob,
cacheControl,
multipartFileSizeMb,
multipartChunkBytes,
concurrency,
syncCriteria,
workspace
);

const smallFiles = filesToUpload.filter((file) => !file.multipart);
const multipartFiles = filesToUpload.filter((file) => file.multipart);
const totalFiles = smallFiles.length + multipartFiles.length;
const totalFiles = filesToUpload.length;

if (totalFiles > 0) {
info(
Expand Down

0 comments on commit 4c6c2fe

Please sign in to comment.