Skip to content

Improve globbing to support brace expansion #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
bucket: ${{ steps.update-stack.outputs.S3BucketName }}
action: 'sync'
src-dir: './test-fixtures'
files-glob: 'css/**'
files-glob: '{site-assets,css}/**/*'
aws-region: 'us-east-1'
prefix: 'preview'
cache-control: 'public,max-age=31536000,immutable'
Expand Down
3,326 changes: 2,143 additions & 1,183 deletions dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

186 changes: 174 additions & 12 deletions dist/licenses.txt

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

41 changes: 22 additions & 19 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/github": "^5.0.0",
"@actions/glob": "^0.2.0",
"@aws-sdk/client-s3": "^3.44.0",
"@aws-sdk/lib-storage": "^3.44.0",
"glob": "^7.2.0",
"mime-types": "^2.1.34",
"minimatch": "^3.0.4",
"s3-etag": "^0.0.6"
},
"devDependencies": {
"@octokit/webhooks-definitions": "^3.67.3",
"@types/glob": "^7.2.0",
"@types/mime-types": "^2.1.1",
"@types/minimatch": "^3.0.5",
"@types/node": "^17.0.0",
Expand Down
10 changes: 10 additions & 0 deletions src/__tests__/s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ describe('getObjectKeyFromFilePath', () => {
const files = await getFilesFromSrcDir(srcDir, '**/*.html');
expect(files).toEqual([`${rootDir}/blog.html`, `${rootDir}/index.html`]);
});

it('should find files using srcDir and filesGlob with brace expansion', async () => {
const srcDir = './test-fixtures';
const rootDir = path.join(path.resolve(process.cwd()), srcDir);
const files = await getFilesFromSrcDir(srcDir, '{css,site-assets}/**/*');
expect(files).toEqual([
`${rootDir}/css/styles.css`,
`${rootDir}/site-assets/script.js`,
]);
});
});

describe('shouldUploadFile', () => {
Expand Down
10 changes: 4 additions & 6 deletions src/s3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import path from 'node:path';
import fs from 'node:fs';
import util from 'node:util';
import mime from 'mime-types';
import glob from 'glob';
import { generateETag } from 's3-etag';
import {
DeleteObjectsCommand,
Expand All @@ -14,8 +16,7 @@ import {
ServiceOutputTypes,
} from '@aws-sdk/client-s3';
import { Upload } from '@aws-sdk/lib-storage';
import glob from '@actions/glob';
import { debug, error, info } from '@actions/core';
import { debug, info } from '@actions/core';
import minimatch from 'minimatch';

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

type FileToUpload = {
Expand Down
1 change: 1 addition & 0 deletions test-fixtures/site-assets/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// hello