Skip to content

Commit 00fde1e

Browse files
peaceirisdhimmelnicolas-van
authored
feat: Add disable_nojekyll and cname options (#119)
* feat: Add disable_nojekyll and cname options * docs: Add cname and disable_nojekyll * chore: Add vim * chore(release): 3.3.0-0 * ci: Add codecov/codecov-action * refactor: Enhance warning message - Add .nojekyll file by default to only the master and gh-pages branches. When the file already exists, this action does nothing. - When we set other branches to publish_branch, this action does not add .nojekyll file. cf. #112 (comment) Close #112 Co-authored-by: Daniel Himmelstein <[email protected]> Co-authored-by: Nicolas Vanhoren <[email protected]>
1 parent 6244b19 commit 00fde1e

File tree

15 files changed

+331
-26
lines changed

15 files changed

+331
-26
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ jobs:
6262
with:
6363
name: coverage
6464
path: coverage
65+
66+
- uses: codecov/codecov-action@v1
67+
with:
68+
token: ${{ secrets.CODECOV_TOKEN }}

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
# [3.3.0-0](https://github.com/peaceiris/actions-gh-pages/compare/v3.2.0...v3.3.0-0) (2020-02-20)
6+
7+
8+
### chore
9+
10+
* Add vim ([b9a6975](https://github.com/peaceiris/actions-gh-pages/commit/b9a697582713e95c1d628172933226631d3825af))
11+
12+
### deps
13+
14+
* bump @types/jest from 25.1.2 to 25.1.3 (#118) ([0b1dd44](https://github.com/peaceiris/actions-gh-pages/commit/0b1dd44709acc2ba27cf43e181767b92e78d1577)), closes [#118](https://github.com/peaceiris/actions-gh-pages/issues/118)
15+
* bump ts-jest from 25.2.0 to 25.2.1 (#117) ([e1bf32a](https://github.com/peaceiris/actions-gh-pages/commit/e1bf32ad68fadb9a32147579d6dc49b51d6ddefb)), closes [#117](https://github.com/peaceiris/actions-gh-pages/issues/117)
16+
17+
### feat
18+
19+
* Add disable_nojekyll and cname options ([7c4b591](https://github.com/peaceiris/actions-gh-pages/commit/7c4b591cf65cf4daf0464fba89b32ff4e764b427)), closes [#112](https://github.com/peaceiris/actions-gh-pages/issues/112)
20+
21+
22+
523
# [3.2.0](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.0...v3.2.0) (2020-02-19)
624

725

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ RUN apt-get update && \
1010
libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev autoconf \
1111
ca-certificates \
1212
wget \
13-
ssh && \
13+
ssh \
14+
vim && \
1415
rm -rf /var/lib/apt/lists/*
1516

1617
WORKDIR /git

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Three tokens are supported.
7272
- [Options](#options)
7373
- [⭐️ `personal_token`](#%EF%B8%8F-personal_token)
7474
- [⭐️ `github_token`](#%EF%B8%8F-github_token)
75+
- [⭐️ CNAME](#%EF%B8%8F-cname)
76+
- [⭐️ Disable `.nojekyll`](#%EF%B8%8F-disable-nojekyll)
7577
- [⭐️ Allow empty commits](#%EF%B8%8F-allow-empty-commits)
7678
- [⭐️ Keeping existing files](#%EF%B8%8F-keeping-existing-files)
7779
- [⭐️ Deploy to external repository](#%EF%B8%8F-deploy-to-external-repository)
@@ -246,6 +248,36 @@ jobs:
246248
+ github_token: ${{ secrets.GITHUB_TOKEN }}
247249
```
248250

251+
### ⭐️ CNAME
252+
253+
To add `CNAME` file, we can set the `cname` option.
254+
255+
For more details about `CNAME`, read the official documentation: [Managing a custom domain for your GitHub Pages site - GitHub Help](https://help.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site)
256+
257+
```yaml
258+
- name: Deploy
259+
uses: peaceiris/actions-gh-pages@v3
260+
with:
261+
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
262+
publish_dir: ./public
263+
cname: github.com
264+
```
265+
266+
### ⭐️ Disable `.nojekyll`
267+
268+
By default, this action adds the `.nojekyll` file to only the `master` and `gh-pages` branches. When the file already exists, this action does nothing.
269+
270+
To disable this behavior, we can set the `disable_nojekyll` option to `true`.
271+
272+
```yaml
273+
- name: Deploy
274+
uses: peaceiris/actions-gh-pages@v3
275+
with:
276+
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
277+
publish_dir: ./public
278+
disable_nojekyll: true
279+
```
280+
249281
### ⭐️ Allow empty commits
250282

251283
By default, a commit will not be generated when no file changes. If you want to allow an empty commit, set the optional parameter `allow_empty_commit` to `true`.

__tests__/get-inputs.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ afterEach(() => {
2121
delete process.env['INPUT_COMMIT_MESSAGE'];
2222
delete process.env['INPUT_TAG_NAME'];
2323
delete process.env['INPUT_TAG_MESSAGE'];
24+
delete process.env['INPUT_DISABLE_NOJEKYLL'];
25+
delete process.env['INPUT_CNAME'];
2426
});
2527

2628
describe('getInputs()', () => {
@@ -30,15 +32,6 @@ describe('getInputs()', () => {
3032
// process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
3133
process.env['INPUT_PUBLISH_BRANCH'] = 'gh-pages';
3234
process.env['INPUT_PUBLISH_DIR'] = 'public';
33-
// process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo';
34-
// process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true';
35-
// process.env['INPUT_KEEP_FILES'] = 'true';
36-
// process.env['INPUT_FORCE_ORPHAN'] = 'true';
37-
// process.env['INPUT_USER_NAME'] = 'username';
38-
// process.env['INPUT_USER_EMAIL'] = '[email protected]';
39-
// process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature';
40-
// process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3';
41-
// process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
4235

4336
const inps: Inputs = getInputs();
4437

@@ -56,6 +49,8 @@ describe('getInputs()', () => {
5649
expect(inps.CommitMessage).toMatch('');
5750
expect(inps.TagName).toMatch('');
5851
expect(inps.TagMessage).toMatch('');
52+
expect(inps.DisableNoJekyll).toBe(false);
53+
expect(inps.CNAME).toMatch('');
5954
});
6055

6156
test('get spec inputs', () => {
@@ -73,6 +68,8 @@ describe('getInputs()', () => {
7368
process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature';
7469
process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3';
7570
process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
71+
process.env['INPUT_DISABLE_NOJEKYLL'] = 'true';
72+
process.env['INPUT_CNAME'] = 'github.com';
7673

7774
const inps: Inputs = getInputs();
7875

@@ -90,5 +87,7 @@ describe('getInputs()', () => {
9087
expect(inps.CommitMessage).toMatch('feat: Add new feature');
9188
expect(inps.TagName).toMatch('deploy-v1.2.3');
9289
expect(inps.TagMessage).toMatch('Deployment v1.2.3');
90+
expect(inps.DisableNoJekyll).toBe(true);
91+
expect(inps.CNAME).toMatch('github.com');
9392
});
9493
});

__tests__/utils.test.ts

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
import path from 'path';
2+
import fs from 'fs';
3+
import {
4+
getHomeDir,
5+
getWorkDirName,
6+
createWorkDir,
7+
addNoJekyll,
8+
addCNAME
9+
} from '../src/utils';
10+
11+
beforeEach(() => {
12+
jest.resetModules();
13+
});
14+
15+
// afterEach(() => {
16+
17+
// });
18+
19+
async function getTime(): Promise<string> {
20+
const date = new Date();
21+
const unixTime = date.getTime();
22+
return `${unixTime}`;
23+
}
24+
25+
describe('getHomeDir()', () => {
26+
test('get home directory name', async () => {
27+
let test = '';
28+
if (process.platform === 'win32') {
29+
test = 'C:\\Users\\runneradmin';
30+
} else {
31+
test = `${process.env.HOME}`;
32+
}
33+
const expected = await getHomeDir();
34+
expect(test).toMatch(expected);
35+
});
36+
});
37+
38+
describe('getWorkDirName()', () => {
39+
test('get work directory name', async () => {
40+
let home = '';
41+
if (process.platform === 'win32') {
42+
home = 'C:\\Users\\runneradmin';
43+
} else {
44+
home = `${process.env.HOME}`;
45+
}
46+
const unixTime = await getTime();
47+
const expected = path.join(home, `actions_github_pages_${unixTime}`);
48+
const test = await getWorkDirName(`${unixTime}`);
49+
expect(test).toMatch(expected);
50+
});
51+
});
52+
53+
describe('createWorkDir()', () => {
54+
test('create work directory', async () => {
55+
const unixTime = await getTime();
56+
const workDirName = await getWorkDirName(`${unixTime}`);
57+
await createWorkDir(workDirName);
58+
const test = fs.existsSync(workDirName);
59+
expect(test).toBe(true);
60+
});
61+
});
62+
63+
async function getWorkDir(): Promise<string> {
64+
const unixTime = await getTime();
65+
let workDir = '';
66+
workDir = await getWorkDirName(`${unixTime}`);
67+
await createWorkDir(workDir);
68+
return workDir;
69+
}
70+
71+
describe('addNoJekyll()', () => {
72+
test('add .nojekyll gh-pages', async () => {
73+
let workDir = '';
74+
(async (): Promise<void> => {
75+
workDir = await getWorkDir();
76+
})();
77+
const filepath = path.join(workDir, '.nojekyll');
78+
79+
await addNoJekyll(workDir, false, 'gh-pages');
80+
const test1 = fs.existsSync(filepath);
81+
expect(test1).toBe(true);
82+
83+
fs.unlinkSync(filepath);
84+
});
85+
86+
test('add .nojekyll master', async () => {
87+
let workDir = '';
88+
(async (): Promise<void> => {
89+
workDir = await getWorkDir();
90+
})();
91+
const filepath = path.join(workDir, '.nojekyll');
92+
93+
await addNoJekyll(workDir, false, 'master');
94+
const test2 = fs.existsSync(filepath);
95+
expect(test2).toBe(true);
96+
97+
fs.unlinkSync(filepath);
98+
});
99+
100+
test('not add .nojekyll disable_nojekyll gh-pages', async () => {
101+
let workDir = '';
102+
(async (): Promise<void> => {
103+
workDir = await getWorkDir();
104+
})();
105+
const filepath = path.join(workDir, '.nojekyll');
106+
107+
await addNoJekyll(workDir, true, 'gh-pages');
108+
const test3 = fs.existsSync(filepath);
109+
expect(test3).toBe(false);
110+
});
111+
112+
test('not add .nojekyll disable_nojekyll master', async () => {
113+
let workDir = '';
114+
(async (): Promise<void> => {
115+
workDir = await getWorkDir();
116+
})();
117+
const filepath = path.join(workDir, '.nojekyll');
118+
119+
await addNoJekyll(workDir, true, 'master');
120+
const test4 = fs.existsSync(filepath);
121+
expect(test4).toBe(false);
122+
});
123+
124+
test('not add .nojekyll other-branch', async () => {
125+
let workDir = '';
126+
(async (): Promise<void> => {
127+
workDir = await getWorkDir();
128+
})();
129+
const filepath = path.join(workDir, '.nojekyll');
130+
131+
await addNoJekyll(workDir, false, 'other-branch');
132+
const test5 = fs.existsSync(filepath);
133+
expect(test5).toBe(false);
134+
});
135+
136+
test('not add .nojekyll disable_nojekyll other-branch', async () => {
137+
let workDir = '';
138+
(async (): Promise<void> => {
139+
workDir = await getWorkDir();
140+
})();
141+
const filepath = path.join(workDir, '.nojekyll');
142+
143+
await addNoJekyll(workDir, true, 'other-branch');
144+
const test6 = fs.existsSync(filepath);
145+
expect(test6).toBe(false);
146+
});
147+
});
148+
149+
describe('addCNAME()', () => {
150+
test('add CNAME', async () => {
151+
let workDir = '';
152+
(async (): Promise<void> => {
153+
workDir = await getWorkDir();
154+
})();
155+
const filepath = path.join(workDir, 'CNAME');
156+
157+
await addCNAME(workDir, 'github.com');
158+
const test1 = fs.readFileSync(filepath, 'utf8');
159+
expect(test1).toMatch('github.com');
160+
161+
fs.unlinkSync(filepath);
162+
});
163+
164+
test('do nothing', async () => {
165+
let workDir = '';
166+
(async (): Promise<void> => {
167+
workDir = await getWorkDir();
168+
})();
169+
const filepath = path.join(workDir, 'CNAME');
170+
171+
await addCNAME(workDir, '');
172+
const test2 = fs.existsSync(filepath);
173+
expect(test2).toBe(false);
174+
});
175+
176+
test('CNAME already exists', async () => {
177+
let workDir = '';
178+
(async (): Promise<void> => {
179+
workDir = await getWorkDir();
180+
})();
181+
const filepath = path.join(workDir, 'CNAME');
182+
183+
await addCNAME(workDir, 'github.io');
184+
await addCNAME(workDir, 'github.com');
185+
const test3 = fs.readFileSync(filepath, 'utf8');
186+
expect(test3).toMatch('github.io');
187+
188+
fs.unlinkSync(filepath);
189+
});
190+
});

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@ inputs:
5555
tag_message:
5656
description: 'Set tag message'
5757
required: false
58+
disable_nojekyll:
59+
description: 'Disable adding .nojekyll file to master or gh-pages branches'
60+
required: false
61+
default: 'false'
62+
cname:
63+
description: 'Set custom domain'
64+
required: false

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "actions-github-pages",
3-
"version": "3.2.0",
3+
"version": "3.3.0-0",
44
"description": "GitHub Actions for GitHub Pages",
55
"main": "lib/index.js",
66
"engines": {

src/get-inputs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function showInputs(inps: Inputs): void {
2121
core.info(`[INFO] CommitMessage: ${inps.CommitMessage}`);
2222
core.info(`[INFO] TagName: ${inps.TagName}`);
2323
core.info(`[INFO] TagMessage: ${inps.TagMessage}`);
24+
core.info(`[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}`);
25+
core.info(`[INFO] CNAME: ${inps.CNAME}`);
2426
}
2527

2628
export function getInputs(): Inputs {
@@ -41,7 +43,10 @@ export function getInputs(): Inputs {
4143
UserEmail: core.getInput('user_email'),
4244
CommitMessage: core.getInput('commit_message'),
4345
TagName: core.getInput('tag_name'),
44-
TagMessage: core.getInput('tag_message')
46+
TagMessage: core.getInput('tag_message'),
47+
DisableNoJekyll:
48+
(core.getInput('disable_nojekyll') || 'false').toUpperCase() === 'TRUE',
49+
CNAME: core.getInput('cname')
4550
};
4651

4752
showInputs(inps);

0 commit comments

Comments
 (0)