Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enable to create branch for first deployment #92

Merged
merged 10 commits into from
Feb 6, 2020
7 changes: 6 additions & 1 deletion .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
- 'macos-latest'
- 'windows-latest'
steps:

- uses: actions/checkout@v2

- name: Read .nvmrc
Expand All @@ -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
Expand Down
49 changes: 27 additions & 22 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,41 @@ export async function setRepo(inps: Inputs, remoteURL: string): Promise<void> {
}
}
};
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;
Expand Down
3 changes: 0 additions & 3 deletions src/set-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down