chore: change printWidth from 80 to 100 (#362)

This commit is contained in:
Shohei Ueda 2020-06-22 05:40:26 +09:00 committed by GitHub
parent b6801e6334
commit 4d89a385db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 32 additions and 128 deletions

View File

@ -1,5 +1,5 @@
{ {
"printWidth": 80, "printWidth": 100,
"tabWidth": 2, "tabWidth": 2,
"useTabs": false, "useTabs": false,
"semi": true, "semi": true,

View File

@ -9,9 +9,7 @@ beforeEach(() => {
jest.resetModules(); jest.resetModules();
process.stdout.write = jest.fn(); process.stdout.write = jest.fn();
const doc = yaml.safeLoad( const doc = yaml.safeLoad(fs.readFileSync(__dirname + '/../action.yml', 'utf8'));
fs.readFileSync(__dirname + '/../action.yml', 'utf8')
);
Object.keys(doc.inputs).forEach(name => { Object.keys(doc.inputs).forEach(name => {
const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
process.env[envVar] = doc.inputs[name]['default']; process.env[envVar] = doc.inputs[name]['default'];
@ -19,9 +17,7 @@ beforeEach(() => {
}); });
afterEach(() => { afterEach(() => {
const doc = yaml.safeLoad( const doc = yaml.safeLoad(fs.readFileSync(__dirname + '/../action.yml', 'utf8'));
fs.readFileSync(__dirname + '/../action.yml', 'utf8')
);
Object.keys(doc.inputs).forEach(name => { Object.keys(doc.inputs).forEach(name => {
const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
console.debug(`delete ${envVar}\t${process.env[envVar]}`); console.debug(`delete ${envVar}\t${process.env[envVar]}`);

View File

@ -1,9 +1,4 @@
import { import {getUserName, getUserEmail, setCommitAuthor, getCommitMessage} from '../src/git-utils';
getUserName,
getUserEmail,
setCommitAuthor,
getCommitMessage
} from '../src/git-utils';
import {getWorkDirName, createWorkDir} from '../src/utils'; import {getWorkDirName, createWorkDir} from '../src/utils';
import {CmdResult} from '../src/interfaces'; import {CmdResult} from '../src/interfaces';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
@ -138,13 +133,7 @@ describe('getCommitMessage()', () => {
}); });
test('get custom message', () => { test('get custom message', () => {
const test = getCommitMessage( const test = getCommitMessage('Custom msg', '', '', 'actions/pages', 'commit_hash');
'Custom msg',
'',
'',
'actions/pages',
'commit_hash'
);
expect(test).toMatch('Custom msg commit_hash'); expect(test).toMatch('Custom msg commit_hash');
}); });
@ -160,13 +149,7 @@ describe('getCommitMessage()', () => {
}); });
test('get full custom message', () => { test('get full custom message', () => {
const test = getCommitMessage( const test = getCommitMessage('', 'Full custom msg', '', 'actions/pages', 'commit_hash');
'',
'Full custom msg',
'',
'actions/pages',
'commit_hash'
);
expect(test).toMatch('Full custom msg'); expect(test).toMatch('Full custom msg');
}); });

View File

@ -1,8 +1,4 @@
import { import {getPublishRepo, setPersonalToken, setGithubToken} from '../src/set-tokens';
getPublishRepo,
setPersonalToken,
setGithubToken
} from '../src/set-tokens';
beforeEach(() => { beforeEach(() => {
jest.resetModules(); jest.resetModules();
@ -26,8 +22,7 @@ describe('getPublishRepo()', () => {
describe('setGithubToken()', () => { describe('setGithubToken()', () => {
test('return remote url with GITHUB_TOKEN gh-pages', () => { test('return remote url with GITHUB_TOKEN gh-pages', () => {
const expected = const expected = 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
const test = setGithubToken( const test = setGithubToken(
'GITHUB_TOKEN', 'GITHUB_TOKEN',
'owner/repo', 'owner/repo',
@ -40,8 +35,7 @@ describe('setGithubToken()', () => {
}); });
test('return remote url with GITHUB_TOKEN master', () => { test('return remote url with GITHUB_TOKEN master', () => {
const expected = const expected = 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
const test = setGithubToken( const test = setGithubToken(
'GITHUB_TOKEN', 'GITHUB_TOKEN',
'owner/repo', 'owner/repo',
@ -55,14 +49,7 @@ describe('setGithubToken()', () => {
test('throw error master to master', () => { test('throw error master to master', () => {
expect(() => { expect(() => {
setGithubToken( setGithubToken('GITHUB_TOKEN', 'owner/repo', 'master', '', 'refs/heads/master', 'push');
'GITHUB_TOKEN',
'owner/repo',
'master',
'',
'refs/heads/master',
'push'
);
}).toThrowError('You deploy from master to master'); }).toThrowError('You deploy from master to master');
}); });
@ -76,14 +63,11 @@ describe('setGithubToken()', () => {
'refs/heads/master', 'refs/heads/master',
'push' 'push'
); );
}).toThrowError( }).toThrowError('GITHUB_TOKEN does not support to push to an external repository');
'GITHUB_TOKEN does not support to push to an external repository'
);
}); });
test('return remote url with GITHUB_TOKEN pull_request', () => { test('return remote url with GITHUB_TOKEN pull_request', () => {
const expected = const expected = 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
const test = setGithubToken( const test = setGithubToken(
'GITHUB_TOKEN', 'GITHUB_TOKEN',
'owner/repo', 'owner/repo',

View File

@ -27,7 +27,7 @@
} }
}, },
"lint-staged": { "lint-staged": {
"src/**/*.ts": [ "{src,__tests__}/**/*.ts": [
"prettier --check", "prettier --check",
"eslint" "eslint"
], ],

View File

@ -53,12 +53,9 @@ export function getInputs(): Inputs {
PublishBranch: core.getInput('publish_branch'), PublishBranch: core.getInput('publish_branch'),
PublishDir: core.getInput('publish_dir'), PublishDir: core.getInput('publish_dir'),
ExternalRepository: core.getInput('external_repository'), ExternalRepository: core.getInput('external_repository'),
AllowEmptyCommit: AllowEmptyCommit: (core.getInput('allow_empty_commit') || 'false').toUpperCase() === 'TRUE',
(core.getInput('allow_empty_commit') || 'false').toUpperCase() === 'TRUE', KeepFiles: (core.getInput('keep_files') || 'false').toUpperCase() === 'TRUE',
KeepFiles: ForceOrphan: (core.getInput('force_orphan') || 'false').toUpperCase() === 'TRUE',
(core.getInput('keep_files') || 'false').toUpperCase() === 'TRUE',
ForceOrphan:
(core.getInput('force_orphan') || 'false').toUpperCase() === 'TRUE',
UserName: core.getInput('user_name'), UserName: core.getInput('user_name'),
UserEmail: core.getInput('user_email'), UserEmail: core.getInput('user_email'),
CommitMessage: core.getInput('commit_message'), CommitMessage: core.getInput('commit_message'),

View File

@ -12,10 +12,7 @@ export async function createBranchForce(branch: string): Promise<void> {
return; return;
} }
export async function copyAssets( export async function copyAssets(publishDir: string, workDir: string): Promise<void> {
publishDir: string,
workDir: string
): Promise<void> {
const copyOpts = {recursive: true, force: true}; const copyOpts = {recursive: true, force: true};
const files = fs.readdirSync(publishDir); const files = fs.readdirSync(publishDir);
core.debug(`${files}`); core.debug(`${files}`);
@ -31,15 +28,8 @@ export async function copyAssets(
return; return;
} }
export async function setRepo( export async function setRepo(inps: Inputs, remoteURL: string, workDir: string): Promise<void> {
inps: Inputs, const publishDir = path.join(`${process.env.GITHUB_WORKSPACE}`, inps.PublishDir);
remoteURL: string,
workDir: string
): Promise<void> {
const publishDir = path.join(
`${process.env.GITHUB_WORKSPACE}`,
inps.PublishDir
);
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`); core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`);
if (inps.ForceOrphan) { if (inps.ForceOrphan) {
@ -65,15 +55,7 @@ export async function setRepo(
try { try {
result.exitcode = await exec.exec( result.exitcode = await exec.exec(
'git', 'git',
[ ['clone', '--depth=1', '--single-branch', '--branch', inps.PublishBranch, remoteURL, workDir],
'clone',
'--depth=1',
'--single-branch',
'--branch',
inps.PublishBranch,
remoteURL,
workDir
],
options options
); );
if (result.exitcode === 0) { if (result.exitcode === 0) {
@ -90,9 +72,7 @@ export async function setRepo(
throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`); throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`);
} }
} catch (e) { } catch (e) {
core.info( core.info(`[INFO] first deployment, create new branch ${inps.PublishBranch}`);
`[INFO] first deployment, create new branch ${inps.PublishBranch}`
);
core.info(e.message); core.info(e.message);
await createWorkDir(workDir); await createWorkDir(workDir);
process.chdir(workDir); process.chdir(workDir);
@ -118,10 +98,7 @@ export function getUserEmail(userEmail: string): string {
} }
} }
export async function setCommitAuthor( export async function setCommitAuthor(userName: string, userEmail: string): Promise<void> {
userName: string,
userEmail: string
): Promise<void> {
if (userName && !userEmail) { if (userName && !userEmail) {
throw new Error('user_email is undefined'); throw new Error('user_email is undefined');
} }
@ -160,10 +137,7 @@ export function getCommitMessage(
return subject; return subject;
} }
export async function commit( export async function commit(allowEmptyCommit: boolean, msg: string): Promise<void> {
allowEmptyCommit: boolean,
msg: string
): Promise<void> {
try { try {
if (allowEmptyCommit) { if (allowEmptyCommit) {
await exec.exec('git', ['commit', '--allow-empty', '-m', `${msg}`]); await exec.exec('git', ['commit', '--allow-empty', '-m', `${msg}`]);
@ -176,10 +150,7 @@ export async function commit(
} }
} }
export async function push( export async function push(branch: string, forceOrphan: boolean): Promise<void> {
branch: string,
forceOrphan: boolean
): Promise<void> {
if (forceOrphan) { if (forceOrphan) {
await exec.exec('git', ['push', 'origin', '--force', branch]); await exec.exec('git', ['push', 'origin', '--force', branch]);
} else { } else {
@ -187,10 +158,7 @@ export async function push(
} }
} }
export async function pushTag( export async function pushTag(tagName: string, tagMessage: string): Promise<void> {
tagName: string,
tagMessage: string
): Promise<void> {
if (tagName === '') { if (tagName === '') {
return; return;
} }

View File

@ -5,14 +5,7 @@ import * as github from '@actions/github';
import {Inputs} from './interfaces'; import {Inputs} from './interfaces';
import {showInputs, getInputs} from './get-inputs'; import {showInputs, getInputs} from './get-inputs';
import {setTokens} from './set-tokens'; import {setTokens} from './set-tokens';
import { import {setRepo, setCommitAuthor, getCommitMessage, commit, push, pushTag} from './git-utils';
setRepo,
setCommitAuthor,
getCommitMessage,
commit,
push,
pushTag
} from './git-utils';
import {getWorkDirName, addNoJekyll, addCNAME, skipOnFork} from './utils'; import {getWorkDirName, addNoJekyll, addCNAME, skipOnFork} from './utils';
export async function run(): Promise<void> { export async function run(): Promise<void> {
@ -39,9 +32,7 @@ export async function run(): Promise<void> {
inps.PersonalToken inps.PersonalToken
); );
if (isSkipOnFork) { if (isSkipOnFork) {
core.warning( core.warning('This action runs on a fork and not found auth token, Skip deployment');
'This action runs on a fork and not found auth token, Skip deployment'
);
core.setOutput('skip', 'true'); core.setOutput('skip', 'true');
return; return;
} }

View File

@ -9,10 +9,7 @@ const cpexec = require('child_process').execFileSync;
import {Inputs} from './interfaces'; import {Inputs} from './interfaces';
import {getHomeDir} from './utils'; import {getHomeDir} from './utils';
export async function setSSHKey( export async function setSSHKey(inps: Inputs, publishRepo: string): Promise<string> {
inps: Inputs,
publishRepo: string
): Promise<string> {
core.info('[INFO] setup SSH deploy key'); core.info('[INFO] setup SSH deploy key');
const homeDir = await getHomeDir(); const homeDir = await getHomeDir();
@ -81,27 +78,18 @@ export function setGithubToken(
} }
if (externalRepository) { if (externalRepository) {
throw new Error( throw new Error('GITHUB_TOKEN does not support to push to an external repository');
'GITHUB_TOKEN does not support to push to an external repository'
);
} }
return `https://x-access-token:${githubToken}@github.com/${publishRepo}.git`; return `https://x-access-token:${githubToken}@github.com/${publishRepo}.git`;
} }
export function setPersonalToken( export function setPersonalToken(personalToken: string, publishRepo: string): string {
personalToken: string,
publishRepo: string
): string {
core.info('[INFO] setup personal access token'); core.info('[INFO] setup personal access token');
return `https://x-access-token:${personalToken}@github.com/${publishRepo}.git`; return `https://x-access-token:${personalToken}@github.com/${publishRepo}.git`;
} }
export function getPublishRepo( export function getPublishRepo(externalRepository: string, owner: string, repo: string): string {
externalRepository: string,
owner: string,
repo: string
): string {
if (externalRepository) { if (externalRepository) {
return externalRepository; return externalRepository;
} }

View File

@ -47,10 +47,7 @@ export async function addNoJekyll(
} }
} }
export async function addCNAME( export async function addCNAME(workDir: string, content: string): Promise<void> {
workDir: string,
content: string
): Promise<void> {
if (content === '') { if (content === '') {
return; return;
} }