Skip to content

Commit b508219

Browse files
committed
Improving globbing to support brace expansion
Replace @actions/glob with glob
1 parent de59498 commit b508219

File tree

9 files changed

+2358
-1223
lines changed

9 files changed

+2358
-1223
lines changed

.github/workflows/build-test-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
bucket: ${{ steps.update-stack.outputs.S3BucketName }}
9494
action: 'sync'
9595
src-dir: './test-fixtures'
96-
files-glob: 'css/**'
96+
files-glob: '{site-assets,css}/**/*'
9797
aws-region: 'us-east-1'
9898
prefix: 'preview'
9999
cache-control: 'public,max-age=31536000,immutable'

dist/index.js

Lines changed: 2143 additions & 1183 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.

dist/licenses.txt

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

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@
3636
"dependencies": {
3737
"@actions/core": "^1.6.0",
3838
"@actions/github": "^5.0.0",
39-
"@actions/glob": "^0.2.0",
4039
"@aws-sdk/client-s3": "^3.44.0",
4140
"@aws-sdk/lib-storage": "^3.44.0",
41+
"glob": "^7.2.0",
4242
"mime-types": "^2.1.34",
4343
"minimatch": "^3.0.4",
4444
"s3-etag": "^0.0.6"
4545
},
4646
"devDependencies": {
4747
"@octokit/webhooks-definitions": "^3.67.3",
48+
"@types/glob": "^7.2.0",
4849
"@types/mime-types": "^2.1.1",
4950
"@types/minimatch": "^3.0.5",
5051
"@types/node": "^17.0.0",

src/__tests__/s3.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ describe('getObjectKeyFromFilePath', () => {
3636
const files = await getFilesFromSrcDir(srcDir, '**/*.html');
3737
expect(files).toEqual([`${rootDir}/blog.html`, `${rootDir}/index.html`]);
3838
});
39+
40+
it('should find files using srcDir and filesGlob with brace expansion', async () => {
41+
const srcDir = './test-fixtures';
42+
const rootDir = path.join(path.resolve(process.cwd()), srcDir);
43+
const files = await getFilesFromSrcDir(srcDir, '{css,site-assets}/**/*');
44+
expect(files).toEqual([
45+
`${rootDir}/css/styles.css`,
46+
`${rootDir}/site-assets/script.js`,
47+
]);
48+
});
3949
});
4050

4151
describe('shouldUploadFile', () => {

src/s3.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import path from 'node:path';
22
import fs from 'node:fs';
3+
import util from 'node:util';
34
import mime from 'mime-types';
5+
import glob from 'glob';
46
import { generateETag } from 's3-etag';
57
import {
68
DeleteObjectsCommand,
@@ -14,8 +16,7 @@ import {
1416
ServiceOutputTypes,
1517
} from '@aws-sdk/client-s3';
1618
import { Upload } from '@aws-sdk/lib-storage';
17-
import glob from '@actions/glob';
18-
import { debug, error, info } from '@actions/core';
19+
import { debug, info } from '@actions/core';
1920
import minimatch from 'minimatch';
2021

2122
import { workspace } from './github.js';
@@ -234,10 +235,7 @@ export async function getFilesFromSrcDir(
234235
if (srcDir.trim() === '' || filesGlob.trim() === '') {
235236
throw new Error('srcDir and filesGlob must not be empty');
236237
}
237-
const globber = await glob.create(`${srcDir}/${filesGlob}`, {
238-
matchDirectories: false,
239-
});
240-
return globber.glob();
238+
return util.promisify(glob)(filesGlob, { cwd: srcDir, absolute: true });
241239
}
242240

243241
type FileToUpload = {

test-fixtures/site-assets/script.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// hello

0 commit comments

Comments
 (0)