Skip to content

Commit 6f45501

Browse files
authored
feat: exclude_assets supports glob patterns (#417)
Related to #163 https://github.com/actions/toolkit/tree/main/packages/glob
1 parent bf46251 commit 6f45501

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@actions/core": "^1.2.4",
5858
"@actions/exec": "^1.0.4",
5959
"@actions/github": "^4.0.0",
60+
"@actions/glob": "^0.1.0",
6061
"@actions/io": "^1.0.2"
6162
},
6263
"devDependencies": {

src/git-utils.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
33
import * as io from '@actions/io';
4+
import * as glob from '@actions/glob';
45
import path from 'path';
56
import fs from 'fs';
67
import {Inputs, CmdResult} from './interfaces';
@@ -12,28 +13,38 @@ export async function createBranchForce(branch: string): Promise<void> {
1213
return;
1314
}
1415

16+
export async function deleteExcludedAssets(destDir: string, excludeAssets: string): Promise<void> {
17+
core.info(`[INFO] delete excluded assets`);
18+
const excludedAssetNames: Array<string> = excludeAssets.split(',');
19+
const excludedAssetPaths = ((): Array<string> => {
20+
const paths: Array<string> = [];
21+
for (const pattern of excludedAssetNames) {
22+
paths.push(path.join(destDir, pattern));
23+
}
24+
return paths;
25+
})();
26+
const globber = await glob.create(excludedAssetPaths.join('\n'));
27+
for await (const asset of globber.globGenerator()) {
28+
io.rmRF(asset);
29+
core.info(`[INFO] delete ${asset}`);
30+
}
31+
return;
32+
}
33+
1534
export async function copyAssets(
1635
publishDir: string,
1736
destDir: string,
1837
excludeAssets: string
1938
): Promise<void> {
39+
core.info(`[INFO] prepare publishing assets`);
2040
const copyOpts = {recursive: true, force: true};
2141
const files = fs.readdirSync(publishDir);
2242
core.debug(`${files}`);
2343
for await (const file of files) {
24-
const isExcludeFile = ((): boolean => {
25-
const excludedAssetNames: Array<string> = excludeAssets.split(',');
26-
for (const excludedAssetName of excludedAssetNames) {
27-
if (file === excludedAssetName) {
28-
return true;
29-
}
30-
}
31-
return false;
32-
})();
33-
if (isExcludeFile || file === '.git') {
44+
if (file === '.git') {
45+
core.info(`[INFO] skip ${file}`);
3446
continue;
3547
}
36-
3748
const filePublishPath = path.join(publishDir, file);
3849
const fileDestPath = path.join(destDir, file);
3950
const destPath = path.dirname(fileDestPath);
@@ -44,6 +55,8 @@ export async function copyAssets(
4455
core.info(`[INFO] copy ${file}`);
4556
}
4657

58+
await deleteExcludedAssets(destDir, excludeAssets);
59+
4760
return;
4861
}
4962

0 commit comments

Comments
 (0)