feat: Add .nojekyll file by default for all branches (#438)

This commit is contained in:
Shohei Ueda 2020-08-02 15:11:20 +09:00 committed by GitHub
parent 4fb3d60161
commit 079d48367e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 68 deletions

View File

@ -70,28 +70,14 @@ async function getWorkDir(): Promise<string> {
} }
describe('addNoJekyll()', () => { describe('addNoJekyll()', () => {
test('add .nojekyll gh-pages', async () => { test('add .nojekyll', async () => {
let workDir = ''; let workDir = '';
(async (): Promise<void> => { (async (): Promise<void> => {
workDir = await getWorkDir(); workDir = await getWorkDir();
})(); })();
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, false, 'gh-pages'); await addNoJekyll(workDir, false);
const test = fs.existsSync(filepath);
expect(test).toBe(true);
fs.unlinkSync(filepath);
});
test('add .nojekyll master', async () => {
let workDir = '';
(async (): Promise<void> => {
workDir = await getWorkDir();
})();
const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, false, 'master');
const test = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test).toBe(true); expect(test).toBe(true);
@ -106,57 +92,21 @@ describe('addNoJekyll()', () => {
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
fs.closeSync(fs.openSync(filepath, 'w')); fs.closeSync(fs.openSync(filepath, 'w'));
await addNoJekyll(workDir, false, 'master'); await addNoJekyll(workDir, false);
const test = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test).toBe(true); expect(test).toBe(true);
fs.unlinkSync(filepath); fs.unlinkSync(filepath);
}); });
test('not add .nojekyll disable_nojekyll gh-pages', async () => { test('not add .nojekyll disable_nojekyll', async () => {
let workDir = ''; let workDir = '';
(async (): Promise<void> => { (async (): Promise<void> => {
workDir = await getWorkDir(); workDir = await getWorkDir();
})(); })();
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, true, 'gh-pages'); await addNoJekyll(workDir, true);
const test = fs.existsSync(filepath);
expect(test).toBe(false);
});
test('not add .nojekyll disable_nojekyll master', async () => {
let workDir = '';
(async (): Promise<void> => {
workDir = await getWorkDir();
})();
const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, true, 'master');
const test = fs.existsSync(filepath);
expect(test).toBe(false);
});
test('not add .nojekyll other-branch', async () => {
let workDir = '';
(async (): Promise<void> => {
workDir = await getWorkDir();
})();
const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, false, 'other-branch');
const test = fs.existsSync(filepath);
expect(test).toBe(false);
});
test('not add .nojekyll disable_nojekyll other-branch', async () => {
let workDir = '';
(async (): Promise<void> => {
workDir = await getWorkDir();
})();
const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, true, 'other-branch');
const test = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test).toBe(false); expect(test).toBe(false);
}); });

View File

@ -48,7 +48,7 @@ export async function run(): Promise<void> {
const unixTime = date.getTime(); const unixTime = date.getTime();
const workDir = await getWorkDirName(`${unixTime}`); const workDir = await getWorkDirName(`${unixTime}`);
await setRepo(inps, remoteURL, workDir); await setRepo(inps, remoteURL, workDir);
await addNoJekyll(workDir, inps.DisableNoJekyll, inps.PublishBranch); await addNoJekyll(workDir, inps.DisableNoJekyll);
await addCNAME(workDir, inps.CNAME); await addCNAME(workDir, inps.CNAME);
core.endGroup(); core.endGroup();

View File

@ -29,22 +29,16 @@ export async function createDir(dirPath: string): Promise<void> {
return; return;
} }
export async function addNoJekyll( export async function addNoJekyll(workDir: string, DisableNoJekyll: boolean): Promise<void> {
workDir: string,
DisableNoJekyll: boolean,
PublishBranch: string
): Promise<void> {
if (DisableNoJekyll) { if (DisableNoJekyll) {
return; return;
} }
if (PublishBranch === 'master' || PublishBranch === 'gh-pages') { const filepath = path.join(workDir, '.nojekyll');
const filepath = path.join(workDir, '.nojekyll'); if (fs.existsSync(filepath)) {
if (fs.existsSync(filepath)) { return;
return;
}
fs.closeSync(fs.openSync(filepath, 'w'));
core.info(`[INFO] Created ${filepath}`);
} }
fs.closeSync(fs.openSync(filepath, 'w'));
core.info(`[INFO] Created ${filepath}`);
} }
export async function addCNAME(workDir: string, content: string): Promise<void> { export async function addCNAME(workDir: string, content: string): Promise<void> {