From 32f89e00aa2b0f7e0e600c92b4788a7ea7cb6f53 Mon Sep 17 00:00:00 2001 From: James Ives Date: Thu, 9 Apr 2020 15:22:53 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Release=203.4.7=20=F0=9F=93=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d1dd55c7..6852c313 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "github-pages-deploy-action", "description": "GitHub action for building a project and deploying it to GitHub pages.", "author": "James Ives (https://jamesiv.es)", - "version": "3.4.6", + "version": "3.4.7", "license": "MIT", "main": "lib/lib.js", "types": "lib/lib.d.ts", From 0467ae98716b8657531ceb632a13adad02b35c5b Mon Sep 17 00:00:00 2001 From: James Ives Date: Sat, 11 Apr 2020 13:57:56 -0400 Subject: [PATCH 2/2] Removed the need for a chmod command (#248) --- CONTRIBUTING.md | 9 +++++---- __tests__/git.test.ts | 26 +++++++++++++++++++------- __tests__/main.test.ts | 8 +++++++- package.json | 3 ++- src/git.ts | 9 +++------ yarn.lock | 4 ++++ 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bbbd7136..a1f0a125 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,17 +3,18 @@ When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. -## Pull Request Best Practices +## Before Making a Pull Request 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`. 2. Make sure you update the README if you've made a change that requires documentation. 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. 4. Make sure you've formatted and linted your code. You can do this by running `yarn format` and `yarn lint`. -5. Fix or add any tests where applicable. You can run `yarn test` to run the suite. +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. +6. Ensure all typing is accurate and the action compiles correctly by running `yarn build`. # Deploying -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). +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). To do this you can follow the instructions below: @@ -42,4 +43,4 @@ $ git checkout -b branchnamehere $ git commit -a -m "prod dependencies" ``` -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. +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. \ No newline at end of file diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 7c94b174..380d1946 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -5,6 +5,7 @@ process.env['GITHUB_SHA'] = '123' import {action} from '../src/constants' import {deploy, generateBranch, init, switchToBaseBranch} from '../src/git' import {execute} from '../src/execute' +import {rmRF} from '@actions/io' const originalAction = JSON.stringify(action) @@ -15,6 +16,10 @@ jest.mock('@actions/core', () => ({ info: jest.fn() })) +jest.mock('@actions/io', () => ({ + rmRF: jest.fn() +})) + jest.mock('../src/execute', () => ({ execute: jest.fn() })) @@ -316,7 +321,8 @@ describe('git', () => { await deploy(action) // Includes the call to generateBranch - expect(execute).toBeCalledTimes(13) + expect(execute).toBeCalledTimes(11) + expect(rmRF).toBeCalledTimes(1) }) it('should execute commands with single commit toggled', async () => { @@ -334,7 +340,8 @@ describe('git', () => { await deploy(action) // Includes the call to generateBranch - expect(execute).toBeCalledTimes(19) + expect(execute).toBeCalledTimes(17) + expect(rmRF).toBeCalledTimes(1) }) it('should execute commands with clean options, ommits sha commit message', async () => { @@ -354,7 +361,8 @@ describe('git', () => { await deploy(action) // Includes the call to generateBranch - expect(execute).toBeCalledTimes(13) + expect(execute).toBeCalledTimes(11) + expect(rmRF).toBeCalledTimes(1) }) it('should execute commands with clean options stored as an array instead', async () => { @@ -373,7 +381,8 @@ describe('git', () => { await deploy(action) // Includes the call to generateBranch - expect(execute).toBeCalledTimes(13) + expect(execute).toBeCalledTimes(11) + expect(rmRF).toBeCalledTimes(1) }) it('should gracefully handle incorrectly formatted clean exclude items', async () => { @@ -391,7 +400,8 @@ describe('git', () => { await deploy(action) - expect(execute).toBeCalledTimes(13) + expect(execute).toBeCalledTimes(11) + expect(rmRF).toBeCalledTimes(1) }) it('should stop early if there is nothing to commit', async () => { @@ -407,7 +417,8 @@ describe('git', () => { }) await deploy(action) - expect(execute).toBeCalledTimes(14) + expect(execute).toBeCalledTimes(12) + expect(rmRF).toBeCalledTimes(1) }) it('should throw an error if one of the required parameters is not available', async () => { @@ -427,7 +438,8 @@ describe('git', () => { try { await deploy(action) } catch (e) { - expect(execute).toBeCalledTimes(2) + expect(execute).toBeCalledTimes(0) + expect(rmRF).toBeCalledTimes(1) expect(e.message).toMatch( '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. ❌' ) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b5557bd9..bccd5c05 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -7,6 +7,7 @@ import '../src/main' import {action} from '../src/constants' import run from '../src/lib' import {execute} from '../src/execute' +import {rmRF} from '@actions/io' import {setFailed} from '@actions/core' const originalAction = JSON.stringify(action) @@ -15,6 +16,10 @@ jest.mock('../src/execute', () => ({ execute: jest.fn() })) +jest.mock('@actions/io', () => ({ + rmRF: jest.fn() +})) + jest.mock('@actions/core', () => ({ setFailed: jest.fn(), getInput: jest.fn(), @@ -42,7 +47,8 @@ describe('main', () => { debug: true }) await run(action) - expect(execute).toBeCalledTimes(20) + expect(execute).toBeCalledTimes(18) + expect(rmRF).toBeCalledTimes(1) }) it('should throw if an error is encountered', async () => { diff --git a/package.json b/package.json index 6852c313..a0f30cb1 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "dependencies": { "@actions/core": "1.2.3", "@actions/exec": "1.0.3", - "@actions/github": "2.1.1" + "@actions/github": "2.1.1", + "@actions/io": "1.0.2" }, "devDependencies": { "@types/jest": "25.2.1", diff --git a/src/git.ts b/src/git.ts index c7973287..e80ca34d 100644 --- a/src/git.ts +++ b/src/git.ts @@ -1,4 +1,5 @@ import {info} from '@actions/core' +import {rmRF} from '@actions/io' import {ActionInterface} from './constants' import {execute} from './execute' import { @@ -238,11 +239,7 @@ export async function deploy(action: ActionInterface): Promise { )} ❌` ) } finally { - // Ensures the deployment directory is safely removed. - await execute( - `chmod u+w -R ${temporaryDeploymentDirectory}`, - action.workspace - ) - await execute(`rm -rf ${temporaryDeploymentDirectory}`, action.workspace) + // Ensures the deployment directory is safely removed after each deployment. + await rmRF(temporaryDeploymentDirectory) } } diff --git a/yarn.lock b/yarn.lock index 768766ff..3e1eeefe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26,6 +26,10 @@ dependencies: tunnel "0.0.6" +"@actions/io@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.2.tgz#2f614b6e69ce14d191180451eb38e6576a6e6b27" + "@actions/io@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.1.tgz#81a9418fe2bbdef2d2717a8e9f85188b9c565aca"