Permalink
Cannot retrieve contributors at this time
76 lines (66 sloc)
1.84 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
gh-pages/src/utils.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as core from '@actions/core'; | |
import * as io from '@actions/io'; | |
import path from 'path'; | |
import fs from 'fs'; | |
export async function getHomeDir(): Promise<string> { | |
let homedir = ''; | |
if (process.platform === 'win32') { | |
homedir = process.env['USERPROFILE'] || 'C:\\'; | |
} else { | |
homedir = `${process.env.HOME}`; | |
} | |
core.debug(`homeDir: ${homedir}`); | |
return homedir; | |
} | |
export async function getWorkDirName(unixTime: string): Promise<string> { | |
const homeDir = await getHomeDir(); | |
const workDirName = path.join(homeDir, `actions_github_pages_${unixTime}`); | |
return workDirName; | |
} | |
export async function createWorkDir(workDirName: string): Promise<void> { | |
await io.mkdirP(workDirName); | |
core.debug(`Created: ${workDirName}`); | |
return; | |
} | |
export async function addNoJekyll( | |
workDir: string, | |
DisableNoJekyll: boolean, | |
PublishBranch: string | |
): Promise<void> { | |
if (DisableNoJekyll) { | |
return; | |
} | |
if (PublishBranch === 'master' || PublishBranch === 'gh-pages') { | |
const filepath = path.join(workDir, '.nojekyll'); | |
if (fs.existsSync(filepath)) { | |
return; | |
} | |
fs.closeSync(fs.openSync(filepath, 'w')); | |
core.info(`[INFO] Created ${filepath}`); | |
} | |
} | |
export async function addCNAME(workDir: string, content: string): Promise<void> { | |
if (content === '') { | |
return; | |
} | |
const filepath = path.join(workDir, 'CNAME'); | |
if (fs.existsSync(filepath)) { | |
core.warning(`CNAME already exists, skip adding CNAME`); | |
return; | |
} | |
fs.writeFileSync(filepath, content + '\n'); | |
core.info(`[INFO] Created ${filepath}`); | |
} | |
export async function skipOnFork( | |
isForkRepository: boolean, | |
githubToken: string, | |
deployKey: string, | |
personalToken: string | |
): Promise<boolean> { | |
if (isForkRepository) { | |
if (githubToken === '' && deployKey === '' && personalToken === '') { | |
return true; | |
} | |
} | |
return false; | |
} |