From 1b6740cb30fc6a5a695a015144589862eb241b7d Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Thu, 6 Feb 2020 15:21:18 +0900 Subject: [PATCH] fix: Enable to create branch for first deployment (#92) * fix: Enable to create branch for first deployment * fix: remove pull_request * ci: remove lint-staged husky for testing * ci: Add git checkout {package-lock,package}.json --- .github/workflows/test-action.yml | 7 ++++- src/git-utils.ts | 49 +++++++++++++++++-------------- src/set-tokens.ts | 3 -- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 8453e06b5..fd859f7c5 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -30,7 +30,6 @@ jobs: - 'macos-latest' - 'windows-latest' steps: - - uses: actions/checkout@v2 - name: Read .nvmrc @@ -43,6 +42,12 @@ jobs: node-version: '${{ steps.nvm.outputs.NVMRC }}' - run: npm ci + + - name: Remove lint-staged husky + run: | + npm uninstall lint-staged husky + git checkout package-lock.json package.json + - run: npm run build - name: Setup mdBook diff --git a/src/git-utils.ts b/src/git-utils.ts index 59c6b3002..654bdd75f 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -65,36 +65,41 @@ export async function setRepo(inps: Inputs, remoteURL: string): Promise { } } }; - result.exitcode = await exec.exec( - 'git', - [ - 'clone', - '--depth=1', - '--single-branch', - '--branch', - inps.PublishBranch, - remoteURL, - workDir - ], - options - ); - process.chdir(workDir); + try { + result.exitcode = await exec.exec( + 'git', + [ + 'clone', + '--depth=1', + '--single-branch', + '--branch', + inps.PublishBranch, + remoteURL, + workDir + ], + options + ); + if (result.exitcode === 0) { + process.chdir(workDir); + if (inps.KeepFiles) { + core.info('[INFO] Keep existing files'); + } else { + await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']); + } - if (result.exitcode === 0) { - if (inps.KeepFiles) { - core.info('[INFO] Keep existing files'); + await copyAssets(publishDir, workDir); + return; } else { - await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']); + throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`); } - - await copyAssets(publishDir, workDir); - return; - } else { + } catch (e) { core.info( `[INFO] first deployment, create new branch ${inps.PublishBranch}` ); + core.info(e); await createWorkDir(workDir); + process.chdir(workDir); await createBranchForce(inps.PublishBranch); await copyAssets(publishDir, workDir); return; diff --git a/src/set-tokens.ts b/src/set-tokens.ts index e50b735bb..979603a0c 100644 --- a/src/set-tokens.ts +++ b/src/set-tokens.ts @@ -100,9 +100,6 @@ export async function setGithubToken( `You deploy from ${inps.PublishBranch} to ${inps.PublishBranch}` ); } - } else if (context.eventName === 'pull_request') { - // TODO: support pull_request event - throw new Error('This action does not support pull_request event now.'); } const isPrivateRepository = payload.repository?.private;