Skip to content

Commit 4f06df8

Browse files
authored
fix: skip deployment on forks (#156)
* fix: skip on forks * chore(release): 3.5.4-6 Close #153
1 parent ff31e77 commit 4f06df8

File tree

6 files changed

+126
-4
lines changed

6 files changed

+126
-4
lines changed

CHANGELOG.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,69 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [3.5.4-6](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-5...v3.5.4-6) (2020-03-15)
6+
7+
8+
### fix
9+
10+
* skip logic ([44bdada](https://github.com/peaceiris/actions-gh-pages/commit/44bdada02c71f646d23ffefe1ea07d16386dbf83))
11+
12+
13+
14+
## [3.5.4-5](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-4...v3.5.4-5) (2020-03-14)
15+
16+
17+
### fix
18+
19+
* property access ([72f58a0](https://github.com/peaceiris/actions-gh-pages/commit/72f58a06cf5db88d3eb982f57de8dbc266e39232))
20+
21+
22+
23+
## [3.5.4-4](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-3...v3.5.4-4) (2020-03-14)
24+
25+
26+
### test
27+
28+
* skipOnFork() ([6f9a5b7](https://github.com/peaceiris/actions-gh-pages/commit/6f9a5b7a66bbf855cadc34099fa6450c40eff4a2))
29+
30+
31+
32+
## [3.5.4-3](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-2...v3.5.4-3) (2020-03-14)
33+
34+
35+
### fix
36+
37+
* skip logic ([01976c9](https://github.com/peaceiris/actions-gh-pages/commit/01976c9d9b95b42997caa2a85c2d737eb75e852e))
38+
39+
40+
41+
## [3.5.4-2](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-1...v3.5.4-2) (2020-03-14)
42+
43+
44+
### fix
45+
46+
* skip logic ([c97a39a](https://github.com/peaceiris/actions-gh-pages/commit/c97a39a35f681badbf7490c2786eddf06b17316d))
47+
48+
49+
50+
## [3.5.4-1](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-0...v3.5.4-1) (2020-03-14)
51+
52+
53+
### fix
54+
55+
* isForkRepository ([6546aa9](https://github.com/peaceiris/actions-gh-pages/commit/6546aa96085e89bd91adc56f58be665766e93a1e))
56+
57+
58+
59+
## [3.5.4-0](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.3...v3.5.4-0) (2020-03-14)
60+
61+
62+
### fix
63+
64+
* skip on forks ([c320668](https://github.com/peaceiris/actions-gh-pages/commit/c320668126b104ad2c15ea1b583a75cd3978c2f3)), closes [#153](https://github.com/peaceiris/actions-gh-pages/issues/153)
65+
66+
67+
568
## [3.5.3](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.2...v3.5.3) (2020-03-13)
669

770

__tests__/utils.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
getWorkDirName,
66
createWorkDir,
77
addNoJekyll,
8-
addCNAME
8+
addCNAME,
9+
skipOnFork
910
} from '../src/utils';
1011

1112
beforeEach(() => {
@@ -203,3 +204,30 @@ describe('addCNAME()', () => {
203204
fs.unlinkSync(filepath);
204205
});
205206
});
207+
208+
describe('skipOnFork()', () => {
209+
test('return false on upstream', async () => {
210+
const test = await skipOnFork(false, 'token', '', '');
211+
expect(test).toBeFalsy();
212+
});
213+
214+
test('return false on fork with github_token', async () => {
215+
const test = await skipOnFork(true, 'token', '', '');
216+
expect(test).toBeFalsy();
217+
});
218+
219+
test('return false on fork with deploy_key', async () => {
220+
const test = await skipOnFork(true, '', 'deploy_key', '');
221+
expect(test).toBeFalsy();
222+
});
223+
224+
test('return false on fork with personal_token', async () => {
225+
const test = await skipOnFork(true, '', '', 'personal_token');
226+
expect(test).toBeFalsy();
227+
});
228+
229+
test('return true on fork with no tokens', async () => {
230+
const test = await skipOnFork(true, '', '', '');
231+
expect(test).toBeTruthy();
232+
});
233+
});

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "actions-github-pages",
3-
"version": "3.5.3",
3+
"version": "3.5.4-6",
44
"description": "GitHub Actions for GitHub Pages",
55
"main": "lib/index.js",
66
"engines": {

src/main.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1+
import {context} from '@actions/github';
12
import * as core from '@actions/core';
23
import * as exec from '@actions/exec';
34
import {Inputs} from './interfaces';
45
import {showInputs, getInputs} from './get-inputs';
56
import {setTokens} from './set-tokens';
67
import {setRepo, setCommitAuthor, commit, push, pushTag} from './git-utils';
7-
import {getWorkDirName, addNoJekyll, addCNAME} from './utils';
8+
import {getWorkDirName, addNoJekyll, addCNAME, skipOnFork} from './utils';
89

910
export async function run(): Promise<void> {
1011
try {
1112
const inps: Inputs = getInputs();
1213
showInputs(inps);
1314

15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
const isForkRepository = (context.payload as any).repository.fork;
17+
const isSkipOnFork = await skipOnFork(
18+
isForkRepository,
19+
inps.GithubToken,
20+
inps.DeployKey,
21+
inps.PersonalToken
22+
);
23+
if (isSkipOnFork) {
24+
core.warning(
25+
'This action runs on a fork and not found auth token, Skip deployment'
26+
);
27+
return;
28+
}
29+
1430
const remoteURL = await setTokens(inps);
1531
core.debug(`[INFO] remoteURL: ${remoteURL}`);
1632

src/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,18 @@ export async function addCNAME(
6262
fs.writeFileSync(filepath, content + '\n');
6363
core.info(`[INFO] Created ${filepath}`);
6464
}
65+
66+
export async function skipOnFork(
67+
isForkRepository: boolean,
68+
githubToken: string,
69+
deployKey: string,
70+
personalToken: string
71+
): Promise<boolean> {
72+
if (isForkRepository) {
73+
if (githubToken === '' && deployKey === '' && personalToken === '') {
74+
return true;
75+
}
76+
}
77+
78+
return false;
79+
}

0 commit comments

Comments
 (0)