feat: Add exclude_assets option (#416)

Related to #163
This commit is contained in:
Shohei Ueda
2020-07-25 20:52:35 +09:00
committed by GitHub
parent 2046290e2b
commit 0f5c65e140
6 changed files with 32 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ export function showInputs(inps: Inputs): void {
[INFO] TagMessage: ${inps.TagMessage}
[INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll}
[INFO] CNAME: ${inps.CNAME}
[INFO] ExcludeAssets ${inps.ExcludeAssets}
`);
}
@@ -65,7 +66,8 @@ export function getInputs(): Inputs {
TagName: core.getInput('tag_name'),
TagMessage: core.getInput('tag_message'),
DisableNoJekyll: useBuiltinJekyll,
CNAME: core.getInput('cname')
CNAME: core.getInput('cname'),
ExcludeAssets: core.getInput('exclude_assets')
};
return inps;

View File

@@ -12,14 +12,28 @@ export async function createBranchForce(branch: string): Promise<void> {
return;
}
export async function copyAssets(publishDir: string, destDir: string): Promise<void> {
export async function copyAssets(
publishDir: string,
destDir: string,
excludeAssets: string
): Promise<void> {
const copyOpts = {recursive: true, force: true};
const files = fs.readdirSync(publishDir);
core.debug(`${files}`);
for await (const file of files) {
if (file.endsWith('.git') || file.endsWith('.github')) {
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') {
continue;
}
const filePublishPath = path.join(publishDir, file);
const fileDestPath = path.join(destDir, file);
const destPath = path.dirname(fileDestPath);
@@ -54,7 +68,7 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
await createDir(destDir);
process.chdir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, destDir);
await copyAssets(publishDir, destDir, inps.ExcludeAssets);
return;
}
@@ -96,7 +110,7 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
}
}
await copyAssets(publishDir, destDir);
await copyAssets(publishDir, destDir, inps.ExcludeAssets);
process.chdir(workDir);
return;
} else {
@@ -108,7 +122,7 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
await createDir(destDir);
process.chdir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, destDir);
await copyAssets(publishDir, destDir, inps.ExcludeAssets);
return;
}
}

View File

@@ -17,6 +17,7 @@ export interface Inputs {
readonly TagMessage: string;
readonly DisableNoJekyll: boolean;
readonly CNAME: string;
readonly ExcludeAssets: string;
}
export interface CmdResult {