mirror of
https://github.com/peaceiris/actions-gh-pages.git
synced 2025-07-14 14:16:00 +08:00
* feat: Add disable_nojekyll and cname options * docs: Add cname and disable_nojekyll * chore: Add vim * chore(release): 3.3.0-0 * ci: Add codecov/codecov-action * refactor: Enhance warning message - Add .nojekyll file by default to only the master and gh-pages branches. When the file already exists, this action does nothing. - When we set other branches to publish_branch, this action does not add .nojekyll file. cf. https://github.com/peaceiris/actions-gh-pages/issues/112#issuecomment-589678269 Close #112 Co-authored-by: Daniel Himmelstein <daniel.himmelstein@gmail.com> Co-authored-by: Nicolas Vanhoren <nicolas.vanhoren@gmail.com>
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
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}`);
|
|
}
|