Skip to content

Commit

Permalink
Merge branch 'dev' into releases/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Jun 6, 2020
2 parents 68843f8 + 14e664a commit 3ee16c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: build # The folder the action should deploy.
```
Expand Down
47 changes: 35 additions & 12 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('git', () => {
it('should execute commands if a GitHub token is provided', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build',
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
pusher: {
Expand All @@ -50,7 +50,7 @@ describe('git', () => {
it('should execute commands if an Access Token is provided', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build',
folder: 'assets',
branch: 'branch',
accessToken: '123',
pusher: {
Expand All @@ -66,7 +66,7 @@ describe('git', () => {
it('should execute commands if SSH is true', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build',
folder: 'assets',
branch: 'branch',
ssh: true,
pusher: {
Expand All @@ -83,7 +83,7 @@ describe('git', () => {
it('should fail if there is no provided GitHub Token, Access Token or SSH bool', async () => {
Object.assign(action, {
repositoryPath: null,
folder: 'build',
folder: 'assets',
branch: 'branch',
pusher: {
name: 'asd',
Expand All @@ -104,7 +104,7 @@ describe('git', () => {
it('should fail if access token is defined but it is an empty string', async () => {
Object.assign(action, {
repositoryPath: null,
folder: 'build',
folder: 'assets',
branch: 'branch',
pusher: {
name: 'asd',
Expand Down Expand Up @@ -146,10 +146,33 @@ describe('git', () => {
}
})

it('should fail if the folder does not exist in the tree', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
gitHubToken: '123',
branch: 'branch',
pusher: {
name: 'asd',
email: 'as@cat'
},
folder: 'notARealFolder',
ssh: true
})

try {
await init(action)
} catch (e) {
expect(execute).toBeCalledTimes(0)
expect(e.message).toMatch(
`There was an error initializing the repository: The notARealFolder directory you're trying to deploy doesn't exist. ❗ ❌`
)
}
})

it('should fail if there is no provided repository path', async () => {
Object.assign(action, {
repositoryPath: null,
folder: 'build',
folder: 'assets',
branch: 'branch',
pusher: {
name: 'asd',
Expand Down Expand Up @@ -329,7 +352,7 @@ describe('git', () => {
describe('deploy', () => {
it('should execute commands', async () => {
Object.assign(action, {
folder: 'build',
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
pusher: {
Expand All @@ -348,7 +371,7 @@ describe('git', () => {

it('should execute commands with single commit toggled', async () => {
Object.assign(action, {
folder: 'build',
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
singleCommit: true,
Expand All @@ -368,7 +391,7 @@ describe('git', () => {
it('should execute commands with clean options, ommits sha commit message', async () => {
process.env.GITHUB_SHA = ''
Object.assign(action, {
folder: 'build',
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
pusher: {
Expand All @@ -388,7 +411,7 @@ describe('git', () => {

it('should execute commands with clean options stored as an array instead', async () => {
Object.assign(action, {
folder: 'build',
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
pusher: {
Expand Down Expand Up @@ -428,7 +451,7 @@ describe('git', () => {

it('should stop early if there is nothing to commit', async () => {
Object.assign(action, {
folder: 'build',
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
pusher: {
Expand All @@ -446,7 +469,7 @@ describe('git', () => {

it('should throw an error if one of the required parameters is not available', async () => {
Object.assign(action, {
folder: 'build',
folder: 'assets',
branch: 'branch',
ssh: null,
accessToken: null,
Expand Down
6 changes: 3 additions & 3 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('main', () => {
it('should run through the commands', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build',
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
pusher: {
Expand All @@ -55,7 +55,7 @@ describe('main', () => {
it('should run through the commands and succeed', async () => {
Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build',
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
pusher: {
Expand All @@ -71,7 +71,7 @@ describe('main', () => {

it('should throw if an error is encountered', async () => {
Object.assign(action, {
folder: 'build',
folder: 'assets',
branch: 'branch',
baseBranch: 'master',
gitHubToken: null,
Expand Down
7 changes: 7 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {isDebug} from '@actions/core'
import {existsSync} from 'fs'
import {ActionInterface} from './constants'

/* Utility function that checks to see if a value is undefined or not. */
Expand Down Expand Up @@ -50,6 +51,12 @@ export const hasRequiredParameters = (action: ActionInterface): void => {
"Incorrectly formatted build folder. The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly."
)
}

if (!existsSync(action.folder) && action.folder !== action.root) {
throw new Error(
`The ${action.folder} directory you're trying to deploy doesn't exist. ❗`
)
}
}

/* Suppresses sensitive information from being exposed in error messages. */
Expand Down

0 comments on commit 3ee16c4

Please sign in to comment.