Skip to content

Commit

Permalink
fix: use onetime workdir name
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Feb 19, 2020
1 parent 0031179 commit 0d912a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export async function copyAssets(

export async function setRepo(
inps: Inputs,
remoteURL: string
): Promise<string> {
const workDir = path.join(getHomeDir(), 'actions_github_pages');
remoteURL: string,
unixTime: string
): Promise<void> {
const workDir = path.join(getHomeDir(), `actions_github_pages_${unixTime}`);
const publishDir = path.join(
`${process.env.GITHUB_WORKSPACE}`,
inps.PublishDir
Expand All @@ -54,7 +55,7 @@ export async function setRepo(
process.chdir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, workDir);
return workDir;
return;
}

const result: CmdResult = {
Expand Down Expand Up @@ -92,7 +93,7 @@ export async function setRepo(
}

await copyAssets(publishDir, workDir);
return workDir;
return;
} else {
throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`);
}
Expand All @@ -105,7 +106,7 @@ export async function setRepo(
process.chdir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, workDir);
return workDir;
return;
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import {Inputs} from './interfaces';
import {getInputs} from './get-inputs';
import {setTokens} from './set-tokens';
Expand All @@ -15,7 +14,9 @@ export async function run(): Promise<void> {
const remoteURL = await setTokens(inps);
core.debug(`[INFO] remoteURL: ${remoteURL}`);

const workDir = await git.setRepo(inps, remoteURL);
const date = new Date();
const unixTime = date.getTime();
await git.setRepo(inps, remoteURL, unixTime);

try {
await exec.exec('git', ['remote', 'rm', 'origin']);
Expand All @@ -33,9 +34,6 @@ export async function run(): Promise<void> {
await git.push(inps.PublishBranch, inps.ForceOrphan);
await git.pushTag(inps.TagName, inps.TagMessage);

core.info(`[INFO] Deleting ${workDir}`);
await io.rmRF(workDir);

core.info('[INFO] Action successfully completed');

return;
Expand Down

0 comments on commit 0d912a1

Please sign in to comment.