Skip to content

Commit 0f5c65e

Browse files
authored
feat: Add exclude_assets option (#416)
Related to #163
1 parent 2046290 commit 0f5c65e

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

__tests__/get-inputs.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function getInputsLog(authMethod: string, inps: Inputs): string {
5353
[INFO] TagMessage: ${inps.TagMessage}
5454
[INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll}
5555
[INFO] CNAME: ${inps.CNAME}
56+
[INFO] ExcludeAssets ${inps.ExcludeAssets}
5657
`;
5758
}
5859

@@ -121,6 +122,7 @@ describe('getInputs()', () => {
121122
expect(inps.TagMessage).toMatch('');
122123
expect(inps.DisableNoJekyll).toBe(false);
123124
expect(inps.CNAME).toMatch('');
125+
expect(inps.ExcludeAssets).toMatch('.github');
124126
});
125127

126128
test('get spec inputs', () => {
@@ -142,6 +144,7 @@ describe('getInputs()', () => {
142144
process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
143145
process.env['INPUT_DISABLE_NOJEKYLL'] = 'true';
144146
process.env['INPUT_CNAME'] = 'github.com';
147+
process.env['INPUT_EXCLUDE_ASSETS'] = '.github';
145148

146149
const inps: Inputs = getInputs();
147150

@@ -163,6 +166,7 @@ describe('getInputs()', () => {
163166
expect(inps.TagMessage).toMatch('Deployment v1.2.3');
164167
expect(inps.DisableNoJekyll).toBe(true);
165168
expect(inps.CNAME).toMatch('github.com');
169+
expect(inps.ExcludeAssets).toMatch('.github');
166170
});
167171

168172
test('get spec inputs enable_jekyll', () => {

__tests__/git-utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('setRepo()', () => {
4040
// process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
4141
// process.env['INPUT_DISABLE_NOJEKYLL'] = 'true';
4242
// process.env['INPUT_CNAME'] = 'github.com';
43+
process.env['INPUT_EXCLUDE_ASSETS'] = '.github';
4344
const inps: Inputs = getInputs();
4445
const remoteURL = 'https://x-access-token:[email protected]/actions/pages.git';
4546
const date = new Date();

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ inputs:
7373
cname:
7474
description: 'Set custom domain'
7575
required: false
76+
exclude_assets:
77+
description: 'Set files or directories to exclude from a publish directory.'
78+
required: false
79+
default: '.github'

src/get-inputs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function showInputs(inps: Inputs): void {
2828
[INFO] TagMessage: ${inps.TagMessage}
2929
[INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll}
3030
[INFO] CNAME: ${inps.CNAME}
31+
[INFO] ExcludeAssets ${inps.ExcludeAssets}
3132
`);
3233
}
3334

@@ -65,7 +66,8 @@ export function getInputs(): Inputs {
6566
TagName: core.getInput('tag_name'),
6667
TagMessage: core.getInput('tag_message'),
6768
DisableNoJekyll: useBuiltinJekyll,
68-
CNAME: core.getInput('cname')
69+
CNAME: core.getInput('cname'),
70+
ExcludeAssets: core.getInput('exclude_assets')
6971
};
7072

7173
return inps;

src/git-utils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@ export async function createBranchForce(branch: string): Promise<void> {
1212
return;
1313
}
1414

15-
export async function copyAssets(publishDir: string, destDir: string): Promise<void> {
15+
export async function copyAssets(
16+
publishDir: string,
17+
destDir: string,
18+
excludeAssets: string
19+
): Promise<void> {
1620
const copyOpts = {recursive: true, force: true};
1721
const files = fs.readdirSync(publishDir);
1822
core.debug(`${files}`);
1923
for await (const file of files) {
20-
if (file.endsWith('.git') || file.endsWith('.github')) {
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') {
2134
continue;
2235
}
36+
2337
const filePublishPath = path.join(publishDir, file);
2438
const fileDestPath = path.join(destDir, file);
2539
const destPath = path.dirname(fileDestPath);
@@ -54,7 +68,7 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
5468
await createDir(destDir);
5569
process.chdir(workDir);
5670
await createBranchForce(inps.PublishBranch);
57-
await copyAssets(publishDir, destDir);
71+
await copyAssets(publishDir, destDir, inps.ExcludeAssets);
5872
return;
5973
}
6074

@@ -96,7 +110,7 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
96110
}
97111
}
98112

99-
await copyAssets(publishDir, destDir);
113+
await copyAssets(publishDir, destDir, inps.ExcludeAssets);
100114
process.chdir(workDir);
101115
return;
102116
} else {
@@ -108,7 +122,7 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
108122
await createDir(destDir);
109123
process.chdir(workDir);
110124
await createBranchForce(inps.PublishBranch);
111-
await copyAssets(publishDir, destDir);
125+
await copyAssets(publishDir, destDir, inps.ExcludeAssets);
112126
return;
113127
}
114128
}

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface Inputs {
1717
readonly TagMessage: string;
1818
readonly DisableNoJekyll: boolean;
1919
readonly CNAME: string;
20+
readonly ExcludeAssets: string;
2021
}
2122

2223
export interface CmdResult {

0 commit comments

Comments
 (0)