feat: Add enable_jekyll (#143)

Implementation of `enable_jekyll` option which is an alias for `disable_nojekyll`

- Issue #130 
- Pull Request #132
This commit is contained in:
Shohei Ueda 2020-03-07 05:30:51 +09:00 committed by GitHub
parent ade8887479
commit dc1169c5ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 50 deletions

View File

@ -2,6 +2,19 @@
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.
# [3.5.0-0](https://github.com/peaceiris/actions-gh-pages/compare/v3.4.1...v3.5.0-0) (2020-03-06)
### deps
* bump node 12.15.0 to 12.16.1 (#142) ([ade8887](https://github.com/peaceiris/actions-gh-pages/commit/ade88874791f5b67d0c475d6dffb5219ed4407f1)), closes [#142](https://github.com/peaceiris/actions-gh-pages/issues/142)
### feat
* Add enable_jekyll ([1fff2ca](https://github.com/peaceiris/actions-gh-pages/commit/1fff2ca84a6b42067a86c6229774aa5e2891a661))
## [3.4.1](https://github.com/peaceiris/actions-gh-pages/compare/v3.4.0...v3.4.1) (2020-03-06)

View File

@ -2,28 +2,31 @@
import {Inputs} from '../src/interfaces';
import {showInputs, getInputs} from '../src/get-inputs';
import os from 'os';
import fs from 'fs';
import yaml from 'js-yaml';
beforeEach(() => {
jest.resetModules();
process.stdout.write = jest.fn();
const doc = yaml.safeLoad(
fs.readFileSync(__dirname + '/../action.yml', 'utf8')
);
Object.keys(doc.inputs).forEach(name => {
const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
process.env[envVar] = doc.inputs[name]['default'];
});
});
afterEach(() => {
delete process.env['INPUT_DEPLOY_KEY'];
delete process.env['INPUT_GITHUB_TOKEN'];
delete process.env['INPUT_PERSONAL_TOKEN'];
delete process.env['INPUT_PUBLISH_BRANCH'];
delete process.env['INPUT_PUBLISH_DIR'];
delete process.env['INPUT_EXTERNAL_REPOSITORY'];
delete process.env['INPUT_ALLOW_EMPTY_COMMIT'];
delete process.env['INPUT_KEEP_FILES'];
delete process.env['INPUT_FORCE_ORPHAN'];
delete process.env['INPUT_USER_NAME'];
delete process.env['INPUT_USER_EMAIL'];
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'];
const doc = yaml.safeLoad(
fs.readFileSync(__dirname + '/../action.yml', 'utf8')
);
Object.keys(doc.inputs).forEach(name => {
const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
console.debug(`delete ${envVar}\t${process.env[envVar]}`);
delete process.env[envVar];
});
});
// Assert that process.stdout.write calls called only with the given arguments.
@ -36,22 +39,6 @@ function assertWriteCalls(calls: string[]): void {
}
}
function setTestInputs(): void {
process.env['INPUT_PUBLISH_BRANCH'] = 'master';
process.env['INPUT_PUBLISH_DIR'] = 'out';
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'] = 'github@github.com';
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';
}
function getInputsLog(authMethod: string, inps: Inputs): string {
return `\
[INFO] ${authMethod}: true
@ -66,20 +53,15 @@ function getInputsLog(authMethod: string, inps: Inputs): string {
[INFO] CommitMessage: ${inps.CommitMessage}
[INFO] TagName: ${inps.TagName}
[INFO] TagMessage: ${inps.TagMessage}
[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}
[INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll}
[INFO] CNAME: ${inps.CNAME}
`;
}
describe('showInputs()', () => {
beforeEach(() => {
process.stdout.write = jest.fn();
});
// eslint-disable-next-line jest/expect-expect
test('print all inputs DeployKey', () => {
process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';
setTestInputs();
const inps: Inputs = getInputs();
showInputs(inps);
@ -91,8 +73,8 @@ describe('showInputs()', () => {
// eslint-disable-next-line jest/expect-expect
test('print all inputs GithubToken', () => {
delete process.env['INPUT_DEPLOY_KEY'];
process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
setTestInputs();
const inps: Inputs = getInputs();
showInputs(inps);
@ -104,8 +86,9 @@ describe('showInputs()', () => {
// eslint-disable-next-line jest/expect-expect
test('print all inputs PersonalToken', () => {
delete process.env['INPUT_DEPLOY_KEY'];
delete process.env['INPUT_GITHUB_TOKEN'];
process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
setTestInputs();
const inps: Inputs = getInputs();
showInputs(inps);
@ -119,10 +102,6 @@ describe('showInputs()', () => {
describe('getInputs()', () => {
test('get default inputs', () => {
process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';
// process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
// process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
process.env['INPUT_PUBLISH_BRANCH'] = 'gh-pages';
process.env['INPUT_PUBLISH_DIR'] = 'public';
const inps: Inputs = getInputs();
@ -181,4 +160,14 @@ describe('getInputs()', () => {
expect(inps.DisableNoJekyll).toBe(true);
expect(inps.CNAME).toMatch('github.com');
});
test('throw error enable_jekyll or disable_nojekyll', () => {
process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';
process.env['INPUT_ENABLE_JEKYLL'] = 'true';
process.env['INPUT_DISABLE_NOJEKYLL'] = 'true';
expect(() => {
getInputs();
}).toThrowError('Use either of enable_jekyll or disable_nojekyll');
});
});

View File

@ -55,8 +55,12 @@ inputs:
tag_message:
description: 'Set tag message'
required: false
enable_jekyll:
description: 'Enable the GitHub Pages built-in Jekyll'
required: false
default: 'false'
disable_nojekyll:
description: 'Disable adding .nojekyll file to master or gh-pages branches'
description: 'An alias for enable_jekyll to disable adding .nojekyll file to master or gh-pages branches'
required: false
default: 'false'
cname:

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "actions-github-pages",
"version": "3.4.1",
"version": "3.5.0-0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -749,6 +749,12 @@
"pretty-format": "^25.1.0"
}
},
"@types/js-yaml": {
"version": "3.12.2",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.12.2.tgz",
"integrity": "sha512-0CFu/g4mDSNkodVwWijdlr8jH7RoplRWNgovjFLEZeT+QEbbZXjBmCe3HwaWheAlCbHwomTwzZoSedeOycABug==",
"dev": true
},
"@types/json-schema": {
"version": "7.0.4",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz",

View File

@ -1,6 +1,6 @@
{
"name": "actions-github-pages",
"version": "3.4.1",
"version": "3.5.0-0",
"description": "GitHub Actions for GitHub Pages",
"main": "lib/index.js",
"engines": {
@ -57,6 +57,7 @@
},
"devDependencies": {
"@types/jest": "^25.1.3",
"@types/js-yaml": "^3.12.2",
"@types/node": "~12",
"@typescript-eslint/eslint-plugin": "^2.22.0",
"@typescript-eslint/parser": "^2.22.0",
@ -66,6 +67,7 @@
"husky": "^4.2.3",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"js-yaml": "^3.13.1",
"lint-staged": "^10.0.8",
"prettier": "1.19.1",
"standard-version": "^7.1.0",

View File

@ -24,12 +24,27 @@ export function showInputs(inps: Inputs): void {
[INFO] CommitMessage: ${inps.CommitMessage}
[INFO] TagName: ${inps.TagName}
[INFO] TagMessage: ${inps.TagMessage}
[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}
[INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll}
[INFO] CNAME: ${inps.CNAME}
`);
}
export function getInputs(): Inputs {
let useBuiltinJekyll = false;
const enableJekyll: boolean =
(core.getInput('enable_jekyll') || 'false').toUpperCase() === 'TRUE';
const disableNoJekyll: boolean =
(core.getInput('disable_nojekyll') || 'false').toUpperCase() === 'TRUE';
if (enableJekyll && disableNoJekyll) {
throw new Error(`Use either of enable_jekyll or disable_nojekyll`);
} else if (enableJekyll) {
useBuiltinJekyll = true;
} else if (disableNoJekyll) {
useBuiltinJekyll = true;
}
const inps: Inputs = {
DeployKey: core.getInput('deploy_key'),
GithubToken: core.getInput('github_token'),
@ -48,8 +63,7 @@ export function getInputs(): Inputs {
CommitMessage: core.getInput('commit_message'),
TagName: core.getInput('tag_name'),
TagMessage: core.getInput('tag_message'),
DisableNoJekyll:
(core.getInput('disable_nojekyll') || 'false').toUpperCase() === 'TRUE',
DisableNoJekyll: useBuiltinJekyll,
CNAME: core.getInput('cname')
};