Skip to content

Commit

Permalink
Fix package name, simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
badsyntax committed Dec 26, 2021
1 parent b4cf6b9 commit 1f95fed
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"request": "launch",
"name": "Debug Main",
"program": "${workspaceFolder}/lib/main.js",
"preLaunchTask": "npm: build",
"preLaunchTask": "npm: build:ide",
"outFiles": ["${workspaceFolder}/lib/**/*.js"],
"outputCapture": "std",
"env": {
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 1f95fed

Please sign in to comment.