diff --git a/src/main.ts b/src/main.ts index 2b47eeff2..690a575bf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,13 +4,22 @@ import {Inputs} from './interfaces'; import {showInputs, getInputs} from './get-inputs'; import {setTokens} from './set-tokens'; import {setRepo, setCommitAuthor, commit, push, pushTag} from './git-utils'; -import {getWorkDirName, addNoJekyll, addCNAME} from './utils'; +import {getWorkDirName, addNoJekyll, addCNAME, skipOnFork} from './utils'; export async function run(): Promise { try { const inps: Inputs = getInputs(); showInputs(inps); + const isSkipOnFork = await skipOnFork( + inps.GithubToken, + inps.DeployKey, + inps.PersonalToken + ); + if (isSkipOnFork) { + return; + } + const remoteURL = await setTokens(inps); core.debug(`[INFO] remoteURL: ${remoteURL}`); diff --git a/src/utils.ts b/src/utils.ts index c86147b61..ef22bab5b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,4 @@ +import {context} from '@actions/github'; import * as core from '@actions/core'; import * as io from '@actions/io'; import path from 'path'; @@ -62,3 +63,23 @@ export async function addCNAME( fs.writeFileSync(filepath, content + '\n'); core.info(`[INFO] Created ${filepath}`); } + +export async function skipOnFork( + githubToken: string, + deployKey: string, + personalToken: string +): Promise { + const isForkRepository = + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (context.payload as any).repository.fork.toUpperCase() === 'TRUE'; + + if (!isForkRepository || githubToken) { + return false; + } + + if (isForkRepository && (deployKey || personalToken)) { + return false; + } + + return true; +}