Skip to content

Commit

Permalink
feat: exclude_assets supports glob patterns (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris authored Jul 25, 2020
1 parent bf46251 commit 6f45501
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
17 changes: 11 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4",
"@actions/github": "^4.0.0",
"@actions/glob": "^0.1.0",
"@actions/io": "^1.0.2"
},
"devDependencies": {
Expand Down
35 changes: 24 additions & 11 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as glob from '@actions/glob';
import path from 'path';
import fs from 'fs';
import {Inputs, CmdResult} from './interfaces';
Expand All @@ -12,28 +13,38 @@ export async function createBranchForce(branch: string): Promise<void> {
return;
}

export async function deleteExcludedAssets(destDir: string, excludeAssets: string): Promise<void> {
core.info(`[INFO] delete excluded assets`);
const excludedAssetNames: Array<string> = excludeAssets.split(',');
const excludedAssetPaths = ((): Array<string> => {
const paths: Array<string> = [];
for (const pattern of excludedAssetNames) {
paths.push(path.join(destDir, pattern));
}
return paths;
})();
const globber = await glob.create(excludedAssetPaths.join('\n'));
for await (const asset of globber.globGenerator()) {
io.rmRF(asset);
core.info(`[INFO] delete ${asset}`);
}
return;
}

export async function copyAssets(
publishDir: string,
destDir: string,
excludeAssets: string
): Promise<void> {
core.info(`[INFO] prepare publishing assets`);
const copyOpts = {recursive: true, force: true};
const files = fs.readdirSync(publishDir);
core.debug(`${files}`);
for await (const file of files) {
const isExcludeFile = ((): boolean => {
const excludedAssetNames: Array<string> = excludeAssets.split(',');
for (const excludedAssetName of excludedAssetNames) {
if (file === excludedAssetName) {
return true;
}
}
return false;
})();
if (isExcludeFile || file === '.git') {
if (file === '.git') {
core.info(`[INFO] skip ${file}`);
continue;
}

const filePublishPath = path.join(publishDir, file);
const fileDestPath = path.join(destDir, file);
const destPath = path.dirname(fileDestPath);
Expand All @@ -44,6 +55,8 @@ export async function copyAssets(
core.info(`[INFO] copy ${file}`);
}

await deleteExcludedAssets(destDir, excludeAssets);

return;
}

Expand Down

0 comments on commit 6f45501

Please sign in to comment.