Skip to content
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

feat: exclude_assets supports glob patterns #417

Merged
merged 1 commit into from
Jul 25, 2020
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
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