Skip to content

Commit

Permalink
fix: allow empty commit for first deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Feb 6, 2020
1 parent bbfae79 commit d6396b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 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<boolean> {
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 false;
}

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

await copyAssets(publishDir, workDir);
return;
return false;
} else {
throw new Error(`Failed to close remote branch ${inps.PublishBranch}`);
}
Expand All @@ -100,7 +103,7 @@ export async function setRepo(inps: Inputs, remoteURL: string): Promise<void> {
await createWorkDir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, workDir);
return;
return true;
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function run(): Promise<void> {
const remoteURL = await setTokens(inps);
core.debug(`[INFO] remoteURL: ${remoteURL}`);

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

try {
await exec.exec('git', ['remote', 'rm', 'origin']);
Expand All @@ -24,11 +24,18 @@ export async function run(): Promise<void> {
await exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
await exec.exec('git', ['add', '--all']);

let allowEmptyCommit = false;
if (firstDeployment) {
allowEmptyCommit = true;
} else {
allowEmptyCommit = inps.AllowEmptyCommit;
}
await git.commit(
inps.AllowEmptyCommit,
allowEmptyCommit,
inps.ExternalRepository,
inps.CommitMessage
);

await git.push(inps.PublishBranch, inps.ForceOrphan);
await git.pushTag(inps.TagName, inps.TagMessage);
core.info('[INFO] successfully deployed');
Expand Down

0 comments on commit d6396b9

Please sign in to comment.