Skip to content

Commit

Permalink
fix: improve archive performance (#101)
Browse files Browse the repository at this point in the history
* fix: improve archive performance

* refactor zip tests

* check if ignores found

* remove fast-glob
  • Loading branch information
bharathkkb committed Jul 16, 2021
1 parent 231d067 commit bdd610a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 52 deletions.
51 changes: 43 additions & 8 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@actions/core": "^1.4.0",
"@types/archiver": "^5.1.0",
"archiver": "^5.0.0",
"fast-glob": "^3.2.7",
"fs": "0.0.1-security",
"gaxios": "^4.3.0",
"google-auth-library": "^6.0.6",
Expand Down
32 changes: 14 additions & 18 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Gaxios } from 'gaxios';
import * as Archiver from 'archiver';
import * as path from 'path';
import ignore from 'ignore';
import fg from 'fast-glob';

/**
* Zip a directory.
Expand Down Expand Up @@ -58,28 +57,25 @@ export async function zipDir(
core.info(`function source zipfile created: ${archive.pointer()} bytes`);
});
archive.pipe(output);
// Add dir to root of archive
getFiles(dirPath).forEach((filepath) => {
archive.glob(filepath, {
cwd: dirPath,
noglobstar: true,
});
});

// gcloudignore
let gIgnoreF = undefined;
if (getGcloudIgnores(dirPath).length > 0) {
const gIgnore = ignore().add(getGcloudIgnores(dirPath));
gIgnoreF = function (
file: Archiver.EntryData,
): false | Archiver.EntryData {
return !gIgnore.ignores(file.name) ? file : false;
};
}

// Add files in dir to archive iff file not ignored
archive.directory(dirPath, false, gIgnoreF);
// Finish writing files
archive.finalize();
});
}

/**
* @param dir dir to collect files from
* @returns list of files that are not ignored
*/
export function getFiles(dir: string): string[] {
const files = fg.sync(['**'], { cwd: dir });
// return list of files that are not ignored
return ignore().add(getGcloudIgnores(dir)).filter(files);
}

/**
* @param dir dir which may contain .gcloudignore file
* @returns list of ignores in .gcloudignore if present
Expand Down
2 changes: 1 addition & 1 deletion tests/test-func-ignore-node/.gcloudignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_modules/
bar/
1 change: 1 addition & 0 deletions tests/test-func-ignore-node/bar/bar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions tests/test-func-ignore-node/bar/baz/baz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
3 changes: 2 additions & 1 deletion tests/test-func-ignore/.gcloudignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.txt
*.txt
.gcloudignore

0 comments on commit bdd610a

Please sign in to comment.