From e34188042a08e5c0e704cc1d51a226e35cdb10e2 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 13 Jul 2020 12:52:45 -0400 Subject: [PATCH] Changes to CNAME and nojekyll files (#362) --- .gitignore | 4 ++++ README.md | 4 +++- __tests__/git.test.ts | 26 ++++++++++++++++++++++++++ src/git.ts | 11 +++++++++-- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index fabe443a..b38e794d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,10 @@ yarn-debug.log* yarn-error.log* node_modules +# Test Temp Files +assets/.nojekyll +assets/CNAME + # Build lib diff --git a/README.md b/README.md index 50fc568b..e504d345 100644 --- a/README.md +++ b/README.md @@ -315,7 +315,9 @@ If you use a [container](https://help.github.com/en/actions/automating-your-work ### Additional Build Files 📁 -If you're using a custom domain and require a `CNAME` file, or if you require the use of a `.nojekyll` file, you can safely commit these files directly into deployment branch without them being overridden after each deployment. +If you're using a custom domain and require a `CNAME` file, or if you require the use of a `.nojekyll` file, you can safely commit these files directly into deployment branch without them being overridden after each deployment. Additionally you can include these files in your deployment folder to update them. + +If you wish to remove these files you must go into the deployment branch directly to remove them. This is to prevent accidental changes in your deployment script from creating breaking changes. --- diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 879620fd..181a5b30 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -6,6 +6,7 @@ import {mkdirP, rmRF} from '@actions/io' import {action, Status} from '../src/constants' import {execute} from '../src/execute' import {deploy, generateBranch, init, switchToBaseBranch} from '../src/git' +import fs from 'fs'; const originalAction = JSON.stringify(action) @@ -362,6 +363,30 @@ describe('git', () => { expect(response).toBe(Status.SUCCESS) }) + it('should not ignore CNAME or nojekyll if they exist in the deployment folder', async () => { + Object.assign(action, { + silent: false, + folder: 'assets', + branch: 'branch', + gitHubToken: '123', + pusher: { + name: 'asd', + email: 'as@cat' + }, + clean: true, + }) + + const response = await deploy(action) + + fs.createWriteStream("assets/.nojekyll"); + fs.createWriteStream("assets/CNAME"); + + // Includes the call to generateBranch + expect(execute).toBeCalledTimes(12) + expect(rmRF).toBeCalledTimes(1) + expect(response).toBe(Status.SUCCESS) + }) + it('should execute commands with single commit toggled', async () => { Object.assign(action, { silent: false, @@ -381,6 +406,7 @@ describe('git', () => { expect(execute).toBeCalledTimes(18) expect(rmRF).toBeCalledTimes(1) }) + it('should execute commands with clean options, ommits sha commit message', async () => { process.env.GITHUB_SHA = '' diff --git a/src/git.ts b/src/git.ts index 3567f8e7..d0ff102b 100644 --- a/src/git.ts +++ b/src/git.ts @@ -1,5 +1,6 @@ import {info} from '@actions/core' -import {rmRF, mkdirP} from '@actions/io' +import {mkdirP, rmRF} from '@actions/io' +import fs from 'fs' import {ActionInterface, Status} from './constants' import {execute} from './execute' import { @@ -193,7 +194,13 @@ export async function deploy(action: ActionInterface): Promise { : temporaryDeploymentDirectory } ${ action.clean - ? `--delete ${excludes} --exclude CNAME --exclude .nojekyll` + ? `--delete ${excludes} ${ + !fs.existsSync(`${action.folder}/CNAME`) ? '--exclude CNAME' : '' + } ${ + !fs.existsSync(`${action.folder}/.nojekyll`) + ? '--exclude .nojekyll' + : '' + }` : '' } --exclude .ssh --exclude .git --exclude .github ${ action.folder === action.root