-
-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add disable_nojekyll and cname options
- Add .nojekyll file by default for only the master and gh-pages branches. When the file already exists, this action does nothing. - When we set other branches to publish_dir, this action does not add .nojekyll file. cf. #112 Co-authored-by: Daniel Himmelstein <[email protected]> Co-authored-by: Nicolas Vanhoren <[email protected]>
- Loading branch information
1 parent
0b1dd44
commit 7c4b591
Showing
9 changed files
with
243 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ afterEach(() => { | |
delete process.env['INPUT_COMMIT_MESSAGE']; | ||
delete process.env['INPUT_TAG_NAME']; | ||
delete process.env['INPUT_TAG_MESSAGE']; | ||
delete process.env['INPUT_DISABLE_NOJEKYLL']; | ||
delete process.env['INPUT_CNAME']; | ||
}); | ||
|
||
describe('getInputs()', () => { | ||
|
@@ -30,15 +32,6 @@ describe('getInputs()', () => { | |
// process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token'; | ||
process.env['INPUT_PUBLISH_BRANCH'] = 'gh-pages'; | ||
process.env['INPUT_PUBLISH_DIR'] = 'public'; | ||
// process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo'; | ||
// process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true'; | ||
// process.env['INPUT_KEEP_FILES'] = 'true'; | ||
// process.env['INPUT_FORCE_ORPHAN'] = 'true'; | ||
// process.env['INPUT_USER_NAME'] = 'username'; | ||
// process.env['INPUT_USER_EMAIL'] = '[email protected]'; | ||
// process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature'; | ||
// process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3'; | ||
// process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3'; | ||
|
||
const inps: Inputs = getInputs(); | ||
|
||
|
@@ -56,6 +49,8 @@ describe('getInputs()', () => { | |
expect(inps.CommitMessage).toMatch(''); | ||
expect(inps.TagName).toMatch(''); | ||
expect(inps.TagMessage).toMatch(''); | ||
expect(inps.DisableNoJekyll).toBe(false); | ||
expect(inps.CNAME).toMatch(''); | ||
}); | ||
|
||
test('get spec inputs', () => { | ||
|
@@ -73,6 +68,8 @@ describe('getInputs()', () => { | |
process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature'; | ||
process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3'; | ||
process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3'; | ||
process.env['INPUT_DISABLE_NOJEKYLL'] = 'true'; | ||
process.env['INPUT_CNAME'] = 'github.com'; | ||
|
||
const inps: Inputs = getInputs(); | ||
|
||
|
@@ -90,5 +87,7 @@ describe('getInputs()', () => { | |
expect(inps.CommitMessage).toMatch('feat: Add new feature'); | ||
expect(inps.TagName).toMatch('deploy-v1.2.3'); | ||
expect(inps.TagMessage).toMatch('Deployment v1.2.3'); | ||
expect(inps.DisableNoJekyll).toBe(true); | ||
expect(inps.CNAME).toMatch('github.com'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { | ||
getHomeDir, | ||
getWorkDirName, | ||
createWorkDir, | ||
addNoJekyll, | ||
addCNAME | ||
} from '../src/utils'; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
}); | ||
|
||
// afterEach(() => { | ||
|
||
// }); | ||
|
||
describe('getHomeDir()', () => { | ||
test('get home directory name', async () => { | ||
let test = ''; | ||
if (process.platform === 'win32') { | ||
test = 'C:\\Users\\runneradmin'; | ||
} else { | ||
test = `${process.env.HOME}`; | ||
} | ||
const homeDir = await getHomeDir(); | ||
expect(homeDir).toMatch(test); | ||
}); | ||
}); | ||
|
||
async function getWorkDir(): Promise<string> { | ||
const date = new Date(); | ||
const unixTime = date.getTime(); | ||
let workDir = ''; | ||
workDir = await getWorkDirName(`${unixTime}`); | ||
await createWorkDir(workDir); | ||
return workDir; | ||
} | ||
|
||
describe('addNoJekyll()', () => { | ||
test('add .nojekyll gh-pages', async () => { | ||
let workDir = ''; | ||
(async (): Promise<void> => { | ||
workDir = await getWorkDir(); | ||
})(); | ||
const filepath = path.join(workDir, '.nojekyll'); | ||
|
||
await addNoJekyll(workDir, false, 'gh-pages'); | ||
const test1 = fs.existsSync(filepath); | ||
expect(test1).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 test2 = fs.existsSync(filepath); | ||
expect(test2).toBe(true); | ||
|
||
fs.unlinkSync(filepath); | ||
}); | ||
|
||
test('not add .nojekyll disable_nojekyll gh-pages', async () => { | ||
let workDir = ''; | ||
(async (): Promise<void> => { | ||
workDir = await getWorkDir(); | ||
})(); | ||
const filepath = path.join(workDir, '.nojekyll'); | ||
|
||
await addNoJekyll(workDir, true, 'gh-pages'); | ||
const test3 = fs.existsSync(filepath); | ||
expect(test3).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 test4 = fs.existsSync(filepath); | ||
expect(test4).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 test5 = fs.existsSync(filepath); | ||
expect(test5).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 test6 = fs.existsSync(filepath); | ||
expect(test6).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('addCNAME()', () => { | ||
test('add CNAME', async () => { | ||
let workDir = ''; | ||
(async (): Promise<void> => { | ||
workDir = await getWorkDir(); | ||
})(); | ||
const filepath = path.join(workDir, 'CNAME'); | ||
|
||
await addCNAME(workDir, 'github.com'); | ||
const test1 = fs.readFileSync(filepath, 'utf8'); | ||
expect(test1).toMatch('github.com'); | ||
|
||
fs.unlinkSync(filepath); | ||
}); | ||
|
||
test('do nothing', async () => { | ||
let workDir = ''; | ||
(async (): Promise<void> => { | ||
workDir = await getWorkDir(); | ||
})(); | ||
const filepath = path.join(workDir, 'CNAME'); | ||
|
||
await addCNAME(workDir, ''); | ||
const test2 = fs.existsSync(filepath); | ||
expect(test2).toBe(false); | ||
}); | ||
|
||
test('CNAME already exists', async () => { | ||
let workDir = ''; | ||
(async (): Promise<void> => { | ||
workDir = await getWorkDir(); | ||
})(); | ||
const filepath = path.join(workDir, 'CNAME'); | ||
|
||
await addCNAME(workDir, 'github.io'); | ||
await addCNAME(workDir, 'github.com'); | ||
const test3 = fs.readFileSync(filepath, 'utf8'); | ||
expect(test3).toMatch('github.io'); | ||
|
||
fs.unlinkSync(filepath); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters