2020-03-16 09:00:19 +09:00
|
|
|
import {context} from '@actions/github';
|
2020-02-05 14:34:19 +09:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as exec from '@actions/exec';
|
|
|
|
import {Inputs} from './interfaces';
|
2020-03-07 00:41:30 +09:00
|
|
|
import {showInputs, getInputs} from './get-inputs';
|
2020-02-05 14:34:19 +09:00
|
|
|
import {setTokens} from './set-tokens';
|
2020-03-12 22:58:12 +09:00
|
|
|
import {setRepo, setCommitAuthor, commit, push, pushTag} from './git-utils';
|
2020-03-16 09:00:19 +09:00
|
|
|
import {getWorkDirName, addNoJekyll, addCNAME, skipOnFork} from './utils';
|
2020-02-05 14:34:19 +09:00
|
|
|
|
|
|
|
export async function run(): Promise<void> {
|
|
|
|
try {
|
|
|
|
const inps: Inputs = getInputs();
|
2020-03-07 00:41:30 +09:00
|
|
|
showInputs(inps);
|
2020-03-16 09:00:19 +09:00
|
|
|
|
2020-03-16 13:56:58 +09:00
|
|
|
if (core.isDebug()) {
|
|
|
|
console.log(context);
|
|
|
|
}
|
|
|
|
|
2020-03-16 11:48:40 +09:00
|
|
|
const eventName = context.eventName;
|
2020-03-16 12:03:08 +09:00
|
|
|
if (eventName === 'pull_request' || eventName === 'push') {
|
2020-03-16 11:48:40 +09:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
const isForkRepository = (context.payload as any).repository.fork;
|
|
|
|
const isSkipOnFork = await skipOnFork(
|
|
|
|
isForkRepository,
|
|
|
|
inps.GithubToken,
|
|
|
|
inps.DeployKey,
|
|
|
|
inps.PersonalToken
|
2020-03-16 09:00:19 +09:00
|
|
|
);
|
2020-03-16 11:48:40 +09:00
|
|
|
if (isSkipOnFork) {
|
|
|
|
core.warning(
|
|
|
|
'This action runs on a fork and not found auth token, Skip deployment'
|
|
|
|
);
|
2020-03-22 15:16:36 +08:00
|
|
|
core.setOutput('skip', 'true');
|
2020-03-16 11:48:40 +09:00
|
|
|
return;
|
|
|
|
}
|
2020-03-16 09:00:19 +09:00
|
|
|
}
|
2020-02-05 14:34:19 +09:00
|
|
|
|
|
|
|
const remoteURL = await setTokens(inps);
|
2020-03-16 13:56:58 +09:00
|
|
|
core.debug(`remoteURL: ${remoteURL}`);
|
2020-02-05 14:34:19 +09:00
|
|
|
|
2020-02-19 22:56:40 +09:00
|
|
|
const date = new Date();
|
|
|
|
const unixTime = date.getTime();
|
2020-02-24 18:49:55 +09:00
|
|
|
const workDir = await getWorkDirName(`${unixTime}`);
|
2020-03-12 22:58:12 +09:00
|
|
|
await setRepo(inps, remoteURL, workDir);
|
2020-02-24 18:49:55 +09:00
|
|
|
|
|
|
|
await addNoJekyll(workDir, inps.DisableNoJekyll, inps.PublishBranch);
|
|
|
|
await addCNAME(workDir, inps.CNAME);
|
2020-02-05 14:34:19 +09:00
|
|
|
|
|
|
|
try {
|
|
|
|
await exec.exec('git', ['remote', 'rm', 'origin']);
|
|
|
|
} catch (e) {
|
2020-03-07 00:41:30 +09:00
|
|
|
core.info(`[INFO] ${e.message}`);
|
2020-02-05 14:34:19 +09:00
|
|
|
}
|
|
|
|
await exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
|
|
|
|
await exec.exec('git', ['add', '--all']);
|
2020-03-12 22:58:12 +09:00
|
|
|
await setCommitAuthor(inps.UserName, inps.UserEmail);
|
|
|
|
await commit(
|
2020-02-05 14:34:19 +09:00
|
|
|
inps.AllowEmptyCommit,
|
|
|
|
inps.ExternalRepository,
|
|
|
|
inps.CommitMessage
|
|
|
|
);
|
2020-03-12 22:58:12 +09:00
|
|
|
await push(inps.PublishBranch, inps.ForceOrphan);
|
|
|
|
await pushTag(inps.TagName, inps.TagMessage);
|
2020-02-19 22:56:40 +09:00
|
|
|
|
2020-02-08 17:31:09 +09:00
|
|
|
core.info('[INFO] Action successfully completed');
|
2020-02-05 14:34:19 +09:00
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (e) {
|
2020-03-07 00:41:30 +09:00
|
|
|
throw new Error(e.message);
|
2020-02-05 14:34:19 +09:00
|
|
|
}
|
|
|
|
}
|