Skip to content

Commit

Permalink
fix: Add removing workDir at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Feb 18, 2020
1 parent 1c50baa commit 5ba5849
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export async function copyAssets(
return;
}

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

const result: CmdResult = {
Expand Down Expand Up @@ -89,7 +92,7 @@ export async function setRepo(inps: Inputs, remoteURL: string): Promise<void> {
}

await copyAssets(publishDir, workDir);
return;
return workDir;
} else {
throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`);
}
Expand All @@ -102,7 +105,7 @@ export async function setRepo(inps: Inputs, remoteURL: string): Promise<void> {
process.chdir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, workDir);
return;
return workDir;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 @@ -14,7 +15,7 @@ export async function run(): Promise<void> {
const remoteURL = await setTokens(inps);
core.debug(`[INFO] remoteURL: ${remoteURL}`);

await git.setRepo(inps, remoteURL);
const workDir = await git.setRepo(inps, remoteURL);

try {
await exec.exec('git', ['remote', 'rm', 'origin']);
Expand All @@ -33,6 +34,8 @@ export async function run(): Promise<void> {
await git.pushTag(inps.TagName, inps.TagMessage);
core.info('[INFO] Action successfully completed');

io.rmRF(workDir);

return;
} catch (e) {
throw new Error(e);
Expand Down

0 comments on commit 5ba5849

Please sign in to comment.