Skip to content

Commit 1b6740c

Browse files
authored
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
1 parent 479c59e commit 1b6740c

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

.github/workflows/test-action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
- 'macos-latest'
3131
- 'windows-latest'
3232
steps:
33-
3433
- uses: actions/checkout@v2
3534

3635
- name: Read .nvmrc
@@ -43,6 +42,12 @@ jobs:
4342
node-version: '${{ steps.nvm.outputs.NVMRC }}'
4443

4544
- run: npm ci
45+
46+
- name: Remove lint-staged husky
47+
run: |
48+
npm uninstall lint-staged husky
49+
git checkout package-lock.json package.json
50+
4651
- run: npm run build
4752

4853
- name: Setup mdBook

src/git-utils.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,36 +65,41 @@ export async function setRepo(inps: Inputs, remoteURL: string): Promise<void> {
6565
}
6666
}
6767
};
68-
result.exitcode = await exec.exec(
69-
'git',
70-
[
71-
'clone',
72-
'--depth=1',
73-
'--single-branch',
74-
'--branch',
75-
inps.PublishBranch,
76-
remoteURL,
77-
workDir
78-
],
79-
options
80-
);
8168

82-
process.chdir(workDir);
69+
try {
70+
result.exitcode = await exec.exec(
71+
'git',
72+
[
73+
'clone',
74+
'--depth=1',
75+
'--single-branch',
76+
'--branch',
77+
inps.PublishBranch,
78+
remoteURL,
79+
workDir
80+
],
81+
options
82+
);
83+
if (result.exitcode === 0) {
84+
process.chdir(workDir);
85+
if (inps.KeepFiles) {
86+
core.info('[INFO] Keep existing files');
87+
} else {
88+
await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']);
89+
}
8390

84-
if (result.exitcode === 0) {
85-
if (inps.KeepFiles) {
86-
core.info('[INFO] Keep existing files');
91+
await copyAssets(publishDir, workDir);
92+
return;
8793
} else {
88-
await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']);
94+
throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`);
8995
}
90-
91-
await copyAssets(publishDir, workDir);
92-
return;
93-
} else {
96+
} catch (e) {
9497
core.info(
9598
`[INFO] first deployment, create new branch ${inps.PublishBranch}`
9699
);
100+
core.info(e);
97101
await createWorkDir(workDir);
102+
process.chdir(workDir);
98103
await createBranchForce(inps.PublishBranch);
99104
await copyAssets(publishDir, workDir);
100105
return;

src/set-tokens.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ export async function setGithubToken(
100100
`You deploy from ${inps.PublishBranch} to ${inps.PublishBranch}`
101101
);
102102
}
103-
} else if (context.eventName === 'pull_request') {
104-
// TODO: support pull_request event
105-
throw new Error('This action does not support pull_request event now.');
106103
}
107104

108105
const isPrivateRepository = payload.repository?.private;

0 commit comments

Comments
 (0)