diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 6063853f..c74fbd82 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -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: { @@ -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: { @@ -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: { @@ -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', @@ -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', @@ -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', @@ -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: { @@ -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, @@ -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: { @@ -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: { @@ -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: { @@ -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, diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 4d7b1c87..303e4798 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -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: { @@ -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: { @@ -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, diff --git a/src/util.ts b/src/util.ts index 735f6f5a..5994a2b8 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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. */ @@ -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)) { + throw new Error( + `The ${action.folder} directory you're trying to deploy doesn't exist. ❗` + ) + } } /* Suppresses sensitive information from being exposed in error messages. */