Merge branch 'dev' into releases/v3

This commit is contained in:
JamesIves 2020-04-11 13:58:24 -04:00
commit 78e2ccef3c
6 changed files with 41 additions and 20 deletions

View File

@ -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.

View File

@ -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. ❌'
)

View File

@ -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 () => {

View File

@ -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 <iam@jamesiv.es> (https://jamesiv.es)",
"version": "3.4.6",
"version": "3.4.7",
"license": "MIT",
"main": "lib/lib.js",
"types": "lib/lib.d.ts",
@ -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",

View File

@ -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<void> {
)} `
)
} 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)
}
}

View File

@ -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"