8000 Removed the need for a chmod command (#248) · FFY00/github-pages-deploy-action@0467ae9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0467ae9

Browse files
authored
Removed the need for a chmod command (JamesIves#248)
1 parent 32f89e0 commit 0467ae9

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
When contributing to this repository, please first discuss the change you wish to make via issue,
44
email, or any other method with the owners of this repository before making a change.
55

6-
## Pull Request Best Practices
6+
## Before Making a Pull Request
77

88
1. Ensure that you've tested your feature/change yourself. As the primary focus of this project is deployment, providing a link to a deployed repository using your branch is preferred. You can reference the forked action using your GitHub username, for example `yourname/github-pages-deplpy-action@master`.
99
2. Make sure you update the README if you've made a change that requires documentation.
1010
3. When making a pull request, highlight any areas that may cause a breaking change so the maintainer can update the version number accordingly on the GitHub marketplace.
1111
4. Make sure you've formatted and linted your code. You can do this by running `yarn format` and `yarn lint`.
12-
5. Fix or add any tests where applicable. You can run `yarn test` to run the suite.
12+
5. Fix or add any tests where applicable. You can run `yarn test` to run the suite. As this action is small in scope it's important that a high level of test coverage is maintained. All tests are written using Jest.
13+
6. Ensure all typing is accurate and the action compiles correctly by running `yarn build`.
1314

1415
# Deploying
1516

16-
In order to deploy and test your own fork of this action, you must commit the required `node_modules` dependencies. Be sure to run `nvm use` before installing any dependencies. You can learn more about nvm [here](https://github.com/nvm-sh/nvm/blob/master/README.md).
17+
In order to deploy and test your own fork of this action, you must commit the `node_modules` dependencies. Be sure to run `nvm use` before installing any dependencies. You can learn more about nvm [here](https://github.com/nvm-sh/nvm/blob/master/README.md).
1718

1819
To do this you can follow the instructions below:
1920

@@ -42,4 +43,4 @@ $ git checkout -b branchnamehere
4243
$ git commit -a -m "prod dependencies"
4344
```
4445

45-
The `node_modules` folder should _not_ be included when making a pull request. These are only required for GitHub Actions when it consumes the distribution branch branch, the `dev` branch of the project should be free from any dependencies or lib files.
46+
The `node_modules` folder should _not_ be included when making a pull request. These are only required for GitHub Actions when it consumes the distribution branch, the `dev` branch of the project should be free from any dependencies or lib files.

__tests__/git.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ process.env['GITHUB_SHA'] = '123'
55
import {action} from '../src/constants'
66
import {deploy, generateBranch, init, switchToBaseBranch} from '../src/git'
77
import {execute} from '../src/execute'
8+
import {rmRF} from '@actions/io'
89

910
const originalAction = JSON.stringify(action)
1011

@@ -15,6 +16,10 @@ jest.mock('@actions/core', () => ({
1516
info: jest.fn()
1617
}))
1718

19+
jest.mock('@actions/io', () => ({
20+
rmRF: jest.fn()
21+
}))
22+
1823
jest.mock('../src/execute', () => ({
1924
execute: jest.fn()
2025
}))
@@ -316,7 +321,8 @@ describe('git', () => {
316321
await deploy(action)
317322

318323
// Includes the call to generateBranch
319-
expect(execute).toBeCalledTimes(13)
324+
expect(execute).toBeCalledTimes(11)
325+
expect(rmRF).toBeCalledTimes(1)
320326
})
321327

322328
it('should execute commands with single commit toggled', async () => {
@@ -334,7 +340,8 @@ describe('git', () => {
334340
await deploy(action)
335341

336342
// Includes the call to generateBranch
337-
expect(execute).toBeCalledTimes(19)
343+
expect(execute).toBeCalledTimes(17)
344+
expect(rmRF).toBeCalledTimes(1)
338345
})
339346

340347
it('should execute commands with clean options, ommits sha commit message', async () => {
@@ -354,7 +361,8 @@ describe('git', () => {
354361
await deploy(action)
355362

356363
// Includes the call to generateBranch
357-
expect(execute).toBeCalledTimes(13)
364+
expect(execute).toBeCalledTimes(11)
365+
expect(rmRF).toBeCalledTimes(1)
358366
})
359367

360368
it('should execute commands with clean options stored as an array instead', async () => {
@@ -373,7 +381,8 @@ describe('git', () => {
373381
await deploy(action)
374382

375383
// Includes the call to generateBranch
376-
expect(execute).toBeCalledTimes(13)
384+
expect(execute).toBeCalledTimes(11)
385+
expect(rmRF).toBeCalledTimes(1)
377386
})
378387

379388
it('should gracefully handle incorrectly formatted clean exclude items', async () => {
@@ -391,7 +400,8 @@ describe('git', () => {
391400

392401
await deploy(action)
393402

394-
expect(execute).toBeCalledTimes(13)
403+
expect(execute).toBeCalledTimes(11)
404+
expect(rmRF).toBeCalledTimes(1)
395405
})
396406

397407
it('should stop early if there is nothing to commit', async () => {
@@ -407,7 +417,8 @@ describe('git', () => {
407417
})
408418

409419
await deploy(action)
410-
expect(execute).toBeCalledTimes(14)
420+
expect(execute).toBeCalledTimes(12)
421+
expect(rmRF).toBeCalledTimes(1)
411422
})
412423

413424
it('should throw an error if one of the required parameters is not available', async () => {
@@ -427,7 +438,8 @@ describe('git', () => {
427438
try {
428439
await deploy(action)
429440
} catch (e) {
430-
expect(execute).toBeCalledTimes(2)
441+
expect(execute).toBeCalledTimes(0)
442+
expect(rmRF).toBeCalledTimes(1)
431443
expect(e.message).toMatch(
432444
'The deploy step encountered an error: No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true. ❌'
433445
)
17AE

__tests__/main.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '../src/main'
77
import {action} from '../src/constants'
88
import run from '../src/lib'
99
import {execute} from '../src/execute'
10+
import {rmRF} from '@actions/io'
1011
import {setFailed} from '@actions/core'
1112

1213
const originalAction = JSON.stringify(action)
@@ -15,6 +16,10 @@ jest.mock('../src/execute', () => ({
1516
execute: jest.fn()
1617
}))
1718

19+
jest.mock('@actions/io', () => ({
20+
rmRF: jest.fn()
21+
}))
22+
1823
jest.mock('@actions/core', () => ({
1924
setFailed: jest.fn(),
2025
getInput: jest.fn(),
@@ -42,7 +47,8 @@ describe('main', () => {
4247
debug: true
4348
})
4449
await run(action)
45-
expect(execute).toBeCalledTimes(20)
50+
expect(execute).toBeCalledTimes(18)
51+
expect(rmRF).toBeCalledTimes(1)
4652
})
4753

4854
it('should throw if an error is encountered', async () => {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"dependencies": {
3636
"@actions/core": "1.2.3",
3737
"@actions/exec": "1.0.3",
38-
"@actions/github": "2.1.1"
38+
"@actions/github": "2.1.1",
39+
"@actions/io": "1.0.2"
3940
},
4041
"devDependencies": {
4142
"@types/jest": "25.2.1",

src/git.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {info} from '@actions/core'
2+
import {rmRF} from '@actions/io'
23
import {ActionInterface} from './constants'
34
import {execute} from './execute'
45
import {
@@ -238,11 +239,7 @@ export async function deploy(action: ActionInterface): Promise<void> {
238239
)} ❌`
239240
)
240241
} finally {
241-
// Ensures the deployment directory is safely removed.
242-
await execute(
243-
`chmod u+w -R ${temporaryDeploymentDirectory}`,
244-
action.workspace
245-
)
246-
await execute(`rm -rf ${temporaryDeploymentDirectory}`, action.workspace)
242+
// Ensures the deployment directory is safely removed after each deployment.
243+
await rmRF(temporaryDeploymentDirectory)
247244
}
248245
}

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
dependencies:
2727
tunnel "0.0.6"
2828

29+
"@actions/io@1.0.2":
30+
version "1.0.2"
31+
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.2.tgz#2f614b6e69ce14d191180451eb38e6576a6e6b27"
32+
2933
"@actions/io@^1.0.1":
3034
version "1.0.1"
3135
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.1.tgz#81a9418fe2bbdef2d2717a8e9f85188b9c565aca"

0 commit comments

Comments
 (0)
0