Skip to content

Commit e341880

Browse files
authored
Changes to CNAME and nojekyll files (JamesIves#362)
1 parent 2028eb2 commit e341880

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ yarn-debug.log*
77
yarn-error.log*
88
node_modules
99

10+
# Test Temp Files
11+
assets/.nojekyll
12+
assets/CNAME
13+
1014
# Build
1115
lib
1216

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ If you use a [container](https://help.github.com/en/actions/automating-your-work
315315

316316
### Additional Build Files 📁
317317

318-
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.
318+
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.
319+
320+
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.
319321

320322
---
321323

__tests__/git.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {mkdirP, rmRF} from '@actions/io'
66
import {action, Status} from '../src/constants'
77
import {execute} from '../src/execute'
88
import {deploy, generateBranch, init, switchToBaseBranch} from '../src/git'
9+
import fs from 'fs';
910

1011
const originalAction = JSON.stringify(action)
1112

@@ -362,6 +363,30 @@ describe('git', () => {
362363
expect(response).toBe(Status.SUCCESS)
363364
})
364365

366+
it('should not ignore CNAME or nojekyll if they exist in the deployment folder', async () => {
367+
Object.assign(action, {
368+
silent: false,
369+
folder: 'assets',
370+
branch: 'branch',
371+
gitHubToken: '123',
372+
pusher: {
373+
name: 'asd',
374+
email: 'as@cat'
375+
},
376+
clean: true,
377+
})
378+
379+
const response = await deploy(action)
380+
381+
fs.createWriteStream("assets/.nojekyll");
382+
fs.createWriteStream("assets/CNAME");
383+
384+
// Includes the call to generateBranch
385+
expect(execute).toBeCalledTimes(12)
386+
expect(rmRF).toBeCalledTimes(1)
387+
expect(response).toBe(Status.SUCCESS)
388+
})
389+
365390
it('should execute commands with single commit toggled', async () => {
366391
Object.assign(action, {
367392
silent: false,
@@ -381,6 +406,7 @@ describe('git', () => {
381406
expect(execute).toBeCalledTimes(18)
382407
expect(rmRF).toBeCalledTimes(1)
383408
})
409+
384410

385411
it('should execute commands with clean options, ommits sha commit message', async () => {
386412
process.env.GITHUB_SHA = ''

src/git.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {info} from '@actions/core'
2-
import {rmRF, mkdirP} from '@actions/io'
2+
import {mkdirP, rmRF} from '@actions/io'
3+
import fs from 'fs'
34
import {ActionInterface, Status} from './constants'
45
import {execute} from './execute'
56
import {
@@ -193,7 +194,13 @@ export async function deploy(action: ActionInterface): Promise<Status> {
193194
: temporaryDeploymentDirectory
194195
} ${
195196
action.clean
196-
? `--delete ${excludes} --exclude CNAME --exclude .nojekyll`
197+
? `--delete ${excludes} ${
198+
!fs.existsSync(`${action.folder}/CNAME`) ? '--exclude CNAME' : ''
199+
} ${
200+
!fs.existsSync(`${action.folder}/.nojekyll`)
201+
? '--exclude .nojekyll'
202+
: ''
203+
}`
197204
: ''
198205
} --exclude .ssh --exclude .git --exclude .github ${
199206
action.folder === action.root

0 commit comments

Comments
 (0)