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: skip deployment on forks #156

Merged
merged 29 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c320668
fix: skip on forks
peaceiris Mar 14, 2020
3a443e3
chore(release): Add build assets
peaceiris Mar 14, 2020
21536c0
chore(release): 3.5.4-0
peaceiris Mar 14, 2020
a60eec2
chore(release): Remove build assets [skip ci]
peaceiris Mar 14, 2020
6546aa9
fix: isForkRepository
peaceiris Mar 14, 2020
2ca4395
chore(release): Add build assets
peaceiris Mar 14, 2020
dea6ee7
chore(release): 3.5.4-1
peaceiris Mar 14, 2020
9df954b
chore(release): Remove build assets [skip ci]
peaceiris Mar 14, 2020
c97a39a
fix: skip logic
peaceiris Mar 14, 2020
d3e35b2
chore(release): Add build assets
peaceiris Mar 14, 2020
90a40ad
chore(release): 3.5.4-2
peaceiris Mar 14, 2020
78a39ce
chore(release): Remove build assets [skip ci]
peaceiris Mar 14, 2020
01976c9
fix: skip logic
peaceiris Mar 14, 2020
2712ed5
chore(release): Add build assets
peaceiris Mar 14, 2020
0f6166f
chore(release): 3.5.4-3
peaceiris Mar 14, 2020
5c097c0
chore(release): Remove build assets [skip ci]
peaceiris Mar 14, 2020
6f9a5b7
test: skipOnFork()
peaceiris Mar 14, 2020
a8f5250
chore(release): Add build assets
peaceiris Mar 14, 2020
ee64849
chore(release): 3.5.4-4
peaceiris Mar 14, 2020
a8a9c90
chore(release): Remove build assets [skip ci]
peaceiris Mar 14, 2020
72f58a0
fix: property access
peaceiris Mar 14, 2020
a9077f3
chore(release): Add build assets
peaceiris Mar 14, 2020
ee83428
chore(release): 3.5.4-5
peaceiris Mar 14, 2020
4377a42
chore(release): Remove build assets [skip ci]
peaceiris Mar 14, 2020
44bdada
fix: skip logic
peaceiris Mar 15, 2020
07d4ccd
chore(release): Add build assets
peaceiris Mar 15, 2020
476e697
chore(release): 3.5.4-6
peaceiris Mar 15, 2020
4884e1b
chore(release): Remove build assets [skip ci]
peaceiris Mar 15, 2020
2292986
refactor: enhance warning message
peaceiris Mar 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,69 @@

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.

## [3.5.4-6](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-5...v3.5.4-6) (2020-03-15)


### fix

* skip logic ([44bdada](https://github.com/peaceiris/actions-gh-pages/commit/44bdada02c71f646d23ffefe1ea07d16386dbf83))



## [3.5.4-5](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-4...v3.5.4-5) (2020-03-14)


### fix

* property access ([72f58a0](https://github.com/peaceiris/actions-gh-pages/commit/72f58a06cf5db88d3eb982f57de8dbc266e39232))



## [3.5.4-4](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-3...v3.5.4-4) (2020-03-14)


### test

* skipOnFork() ([6f9a5b7](https://github.com/peaceiris/actions-gh-pages/commit/6f9a5b7a66bbf855cadc34099fa6450c40eff4a2))



## [3.5.4-3](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-2...v3.5.4-3) (2020-03-14)


### fix

* skip logic ([01976c9](https://github.com/peaceiris/actions-gh-pages/commit/01976c9d9b95b42997caa2a85c2d737eb75e852e))



## [3.5.4-2](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-1...v3.5.4-2) (2020-03-14)


### fix

* skip logic ([c97a39a](https://github.com/peaceiris/actions-gh-pages/commit/c97a39a35f681badbf7490c2786eddf06b17316d))



## [3.5.4-1](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.4-0...v3.5.4-1) (2020-03-14)


### fix

* isForkRepository ([6546aa9](https://github.com/peaceiris/actions-gh-pages/commit/6546aa96085e89bd91adc56f58be665766e93a1e))



## [3.5.4-0](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.3...v3.5.4-0) (2020-03-14)


### fix

* skip on forks ([c320668](https://github.com/peaceiris/actions-gh-pages/commit/c320668126b104ad2c15ea1b583a75cd3978c2f3)), closes [#153](https://github.com/peaceiris/actions-gh-pages/issues/153)



## [3.5.3](https://github.com/peaceiris/actions-gh-pages/compare/v3.5.2...v3.5.3) (2020-03-13)


Expand Down
30 changes: 29 additions & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
getWorkDirName,
createWorkDir,
addNoJekyll,
addCNAME
addCNAME,
skipOnFork
} from '../src/utils';

beforeEach(() => {
Expand Down Expand Up @@ -203,3 +204,30 @@ describe('addCNAME()', () => {
fs.unlinkSync(filepath);
});
});

describe('skipOnFork()', () => {
test('return false on upstream', async () => {
const test = await skipOnFork(false, 'token', '', '');
expect(test).toBeFalsy();
});

test('return false on fork with github_token', async () => {
const test = await skipOnFork(true, 'token', '', '');
expect(test).toBeFalsy();
});

test('return false on fork with deploy_key', async () => {
const test = await skipOnFork(true, '', 'deploy_key', '');
expect(test).toBeFalsy();
});

test('return false on fork with personal_token', async () => {
const test = await skipOnFork(true, '', '', 'personal_token');
expect(test).toBeFalsy();
});

test('return true on fork with no tokens', async () => {
const test = await skipOnFork(true, '', '', '');
expect(test).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "actions-github-pages",
"version": "3.5.3",
"version": "3.5.4-6",
"description": "GitHub Actions for GitHub Pages",
"main": "lib/index.js",
"engines": {
Expand Down
18 changes: 17 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import {context} from '@actions/github';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {Inputs} from './interfaces';
import {showInputs, getInputs} from './get-inputs';
import {setTokens} from './set-tokens';
import {setRepo, setCommitAuthor, commit, push, pushTag} from './git-utils';
import {getWorkDirName, addNoJekyll, addCNAME} from './utils';
import {getWorkDirName, addNoJekyll, addCNAME, skipOnFork} from './utils';

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

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isForkRepository = (context.payload as any).repository.fork;
const isSkipOnFork = await skipOnFork(
isForkRepository,
inps.GithubToken,
inps.DeployKey,
inps.PersonalToken
);
if (isSkipOnFork) {
core.warning(
'This action runs on a fork and not found auth token, Skip deployment'
);
return;
}

const remoteURL = await setTokens(inps);
core.debug(`[INFO] remoteURL: ${remoteURL}`);

Expand Down
15 changes: 15 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,18 @@ export async function addCNAME(
fs.writeFileSync(filepath, content + '\n');
core.info(`[INFO] Created ${filepath}`);
}

export async function skipOnFork(
isForkRepository: boolean,
githubToken: string,
deployKey: string,
personalToken: string
): Promise<boolean> {
if (isForkRepository) {
if (githubToken === '' && deployKey === '' && personalToken === '') {
return true;
}
}

return false;
}