Adds check to see if folder exists

This commit is contained in:
James Ives 2020-06-06 10:55:49 -04:00
parent 51daf2df18
commit 57ea9373b3
3 changed files with 45 additions and 15 deletions

View File

@ -34,7 +34,7 @@ describe('git', () => {
it('should execute commands if a GitHub token is provided', async () => { it('should execute commands if a GitHub token is provided', async () => {
Object.assign(action, { Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action', repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
pusher: { pusher: {
@ -50,7 +50,7 @@ describe('git', () => {
it('should execute commands if an Access Token is provided', async () => { it('should execute commands if an Access Token is provided', async () => {
Object.assign(action, { Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action', repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
accessToken: '123', accessToken: '123',
pusher: { pusher: {
@ -66,7 +66,7 @@ describe('git', () => {
it('should execute commands if SSH is true', async () => { it('should execute commands if SSH is true', async () => {
Object.assign(action, { Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action', repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
ssh: true, ssh: true,
pusher: { pusher: {
@ -83,7 +83,7 @@ describe('git', () => {
it('should fail if there is no provided GitHub Token, Access Token or SSH bool', async () => { it('should fail if there is no provided GitHub Token, Access Token or SSH bool', async () => {
Object.assign(action, { Object.assign(action, {
repositoryPath: null, repositoryPath: null,
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
pusher: { pusher: {
name: 'asd', name: 'asd',
@ -104,7 +104,7 @@ describe('git', () => {
it('should fail if access token is defined but it is an empty string', async () => { it('should fail if access token is defined but it is an empty string', async () => {
Object.assign(action, { Object.assign(action, {
repositoryPath: null, repositoryPath: null,
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
pusher: { pusher: {
name: 'asd', name: 'asd',
@ -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 () => { it('should fail if there is no provided repository path', async () => {
Object.assign(action, { Object.assign(action, {
repositoryPath: null, repositoryPath: null,
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
pusher: { pusher: {
name: 'asd', name: 'asd',
@ -329,7 +352,7 @@ describe('git', () => {
describe('deploy', () => { describe('deploy', () => {
it('should execute commands', async () => { it('should execute commands', async () => {
Object.assign(action, { Object.assign(action, {
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
pusher: { pusher: {
@ -348,7 +371,7 @@ describe('git', () => {
it('should execute commands with single commit toggled', async () => { it('should execute commands with single commit toggled', async () => {
Object.assign(action, { Object.assign(action, {
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
singleCommit: true, singleCommit: true,
@ -368,7 +391,7 @@ describe('git', () => {
it('should execute commands with clean options, ommits sha commit message', async () => { it('should execute commands with clean options, ommits sha commit message', async () => {
process.env.GITHUB_SHA = '' process.env.GITHUB_SHA = ''
Object.assign(action, { Object.assign(action, {
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
pusher: { pusher: {
@ -388,7 +411,7 @@ describe('git', () => {
it('should execute commands with clean options stored as an array instead', async () => { it('should execute commands with clean options stored as an array instead', async () => {
Object.assign(action, { Object.assign(action, {
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
pusher: { pusher: {
@ -428,7 +451,7 @@ describe('git', () => {
it('should stop early if there is nothing to commit', async () => { it('should stop early if there is nothing to commit', async () => {
Object.assign(action, { Object.assign(action, {
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
pusher: { pusher: {
@ -446,7 +469,7 @@ describe('git', () => {
it('should throw an error if one of the required parameters is not available', async () => { it('should throw an error if one of the required parameters is not available', async () => {
Object.assign(action, { Object.assign(action, {
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
ssh: null, ssh: null,
accessToken: null, accessToken: null,

View File

@ -36,7 +36,7 @@ describe('main', () => {
it('should run through the commands', async () => { it('should run through the commands', async () => {
Object.assign(action, { Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action', repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
pusher: { pusher: {
@ -55,7 +55,7 @@ describe('main', () => {
it('should run through the commands and succeed', async () => { it('should run through the commands and succeed', async () => {
Object.assign(action, { Object.assign(action, {
repositoryPath: 'JamesIves/github-pages-deploy-action', repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
pusher: { pusher: {
@ -71,7 +71,7 @@ describe('main', () => {
it('should throw if an error is encountered', async () => { it('should throw if an error is encountered', async () => {
Object.assign(action, { Object.assign(action, {
folder: 'build', folder: 'assets',
branch: 'branch', branch: 'branch',
baseBranch: 'master', baseBranch: 'master',
gitHubToken: null, gitHubToken: null,

View File

@ -1,4 +1,5 @@
import {isDebug} from '@actions/core' import {isDebug} from '@actions/core'
import {existsSync} from 'fs'
import {ActionInterface} from './constants' import {ActionInterface} from './constants'
/* Utility function that checks to see if a value is undefined or not. */ /* Utility function that checks to see if a value is undefined or not. */
@ -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." "Incorrectly formatted build folder. The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly."
) )
} }
if (!existsSync(action.folder)) {
throw new Error(
`The ${action.folder} directory you're trying to deploy doesn't exist. ❗`
)
}
} }
/* Suppresses sensitive information from being exposed in error messages. */ /* Suppresses sensitive information from being exposed in error messages. */