Merge branch 'dev' into releases/v3

This commit is contained in:
James Ives 2020-09-12 18:19:07 -04:00
commit a2ab10e945
9 changed files with 536 additions and 327 deletions

View File

@ -62,11 +62,12 @@ jobs:
npm run build npm run build
- name: Deploy 🚀 - name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@3.5.8 uses: JamesIves/github-pages-deploy-action@3.6.0
with: with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to. BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: build # The folder the action should deploy. FOLDER: build # The folder the action should deploy.
CLEAN: true # Automatically remove deleted files from the deploy branch
``` ```
If you'd like to make it so the workflow only triggers on push events to specific branches then you can modify the `on` section. If you'd like to make it so the workflow only triggers on push events to specific branches then you can modify the `on` section.
@ -146,9 +147,10 @@ In addition to the deployment options you must also configure the following.
| `TARGET_FOLDER` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** | | `TARGET_FOLDER` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** |
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to the current commit [SHA](http://en.wikipedia.org/wiki/SHA-1) that triggered the build followed by `master` if it doesn't exist. This is useful for making deployments from another branch, and also may be necessary when using a scheduled job. | `with` | **No** | | `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to the current commit [SHA](http://en.wikipedia.org/wiki/SHA-1) that triggered the build followed by `master` if it doesn't exist. This is useful for making deployments from another branch, and also may be necessary when using a scheduled job. | `with` | **No** |
| `COMMIT_MESSAGE` | If you need to customize the commit message for an integration you can do so. | `with` | **No** | | `COMMIT_MESSAGE` | If you need to customize the commit message for an integration you can do so. | `with` | **No** |
| `CLEAN` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to `true`. | `with` | **No** | | `CLEAN` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option is turned on by default, and can be toggled off by setting it to `false`. | `with` | **No** |
| `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string. For example: `'["filename.js", "folder"]'` | `with` | **No** | | `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string. For example: `'["filename.js", "folder"]'` | `with` | **No** |
| `SINGLE_COMMIT` | This option can be toggled to `true` if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history. **Using this option will also cause any existing history to be wiped from the deployment branch**. | `with` | **No** | | `SINGLE_COMMIT` | This option can be toggled to `true` if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history. **Using this option will also cause any existing history to be wiped from the deployment branch**. | `with` | **No** |
| `LFS` | If toggled all files will be migrated from [Git LFS](https://git-lfs.github.com/) so they can be comitted to the deployment branch. | `with` | **No** |
| `SILENT` | Silences the action output preventing it from displaying git messages. | `with` | **No** | | `SILENT` | Silences the action output preventing it from displaying git messages. | `with` | **No** |
| `WORKSPACE` | This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only neccersary to set this variable if you're using the node module. | `with` | **No** | | `WORKSPACE` | This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only neccersary to set this variable if you're using the node module. | `with` | **No** |

View File

@ -349,6 +349,7 @@ describe('git', () => {
folder: 'assets', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', gitHubToken: '123',
lfs: true,
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -358,7 +359,7 @@ describe('git', () => {
const response = await deploy(action) const response = await deploy(action)
// Includes the call to generateBranch // Includes the call to generateBranch
expect(execute).toBeCalledTimes(12) expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SUCCESS) expect(response).toBe(Status.SUCCESS)
}) })

View File

@ -148,9 +148,9 @@ describe('util', () => {
silent: false silent: false
} }
const string = `This is an error message! It contains ${action.accessToken} and ${action.gitHubToken} and ${action.repositoryPath}` const string = `This is an error message! It contains ${action.accessToken} and ${action.gitHubToken} and ${action.repositoryPath} and ${action.accessToken} again!`
expect(suppressSensitiveInformation(string, action)).toBe( expect(suppressSensitiveInformation(string, action)).toBe(
'This is an error message! It contains *** and *** and ***' 'This is an error message! It contains *** and *** and *** and *** again!'
) )
}) })

View File

@ -43,6 +43,7 @@ inputs:
CLEAN: CLEAN:
description: 'If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to true.' description: 'If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to true.'
required: false required: false
default: 'true'
CLEAN_EXCLUDE: CLEAN_EXCLUDE:
description: "If you need to use CLEAN but you would like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string." description: "If you need to use CLEAN but you would like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string."
@ -68,6 +69,10 @@ inputs:
description: "This option can be used if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history." description: "This option can be used if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history."
required: false required: false
LFS:
description: "Migrates files from Git LFS so they can be comitted to the deployment branch."
required: false
SILENT: SILENT:
description: "Silences the action output preventing it from displaying git messages." description: "Silences the action output preventing it from displaying git messages."
required: false required: false

View File

@ -2,7 +2,7 @@
"name": "@jamesives/github-pages-deploy-action", "name": "@jamesives/github-pages-deploy-action",
"description": "GitHub action for building a project and deploying it to GitHub pages.", "description": "GitHub action for building a project and deploying it to GitHub pages.",
"author": "James Ives <iam@jamesiv.es> (https://jamesiv.es)", "author": "James Ives <iam@jamesiv.es> (https://jamesiv.es)",
"version": "3.5.8", "version": "3.5.9",
"license": "MIT", "license": "MIT",
"main": "lib/lib.js", "main": "lib/lib.js",
"types": "lib/lib.d.ts", "types": "lib/lib.d.ts",
@ -33,21 +33,21 @@
"deployment" "deployment"
], ],
"dependencies": { "dependencies": {
"@actions/core": "1.2.4", "@actions/core": "1.2.5",
"@actions/exec": "1.0.4", "@actions/exec": "1.0.4",
"@actions/github": "4.0.0", "@actions/github": "4.0.0",
"@actions/io": "1.0.2" "@actions/io": "1.0.2"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "26.0.4", "@types/jest": "26.0.13",
"@types/node": "14.0.23", "@types/node": "14.10.1",
"eslint": "7.4.0", "eslint": "7.8.1",
"eslint-plugin-github": "3.4.1", "eslint-plugin-github": "3.4.1",
"eslint-plugin-jest": "23.18.0", "eslint-plugin-jest": "24.0.0",
"eslint-plugin-prettier": "^3.1.2", "eslint-plugin-prettier": "^3.1.2",
"jest": "25.5.4", "jest": "25.5.4",
"jest-circus": "26.1.0", "jest-circus": "26.4.2",
"prettier": "2.0.5", "prettier": "2.1.1",
"ts-jest": "25.5.1", "ts-jest": "25.5.1",
"typescript": "3.9.7" "typescript": "3.9.7"
} }

View File

@ -28,6 +28,8 @@ export interface ActionInterface {
gitHubToken?: string | null gitHubToken?: string | null
/** Determines if the action is running in test mode or not. */ /** Determines if the action is running in test mode or not. */
isTest?: boolean | null isTest?: boolean | null
/** Removes files from LFS if toggled to allow normal deployment. */
lfs?: boolean | null
/** The git config name. */ /** The git config name. */
name?: string name?: string
/** The repository path, for example JamesIves/github-pages-deploy-action. */ /** The repository path, for example JamesIves/github-pages-deploy-action. */
@ -65,6 +67,9 @@ export const action: ActionInterface = {
isTest: process.env.UNIT_TEST isTest: process.env.UNIT_TEST
? process.env.UNIT_TEST.toLowerCase() === 'true' ? process.env.UNIT_TEST.toLowerCase() === 'true'
: false, : false,
lfs: !isNullOrUndefined(getInput('LFS'))
? getInput('LFS').toLowerCase() === 'true'
: false,
email: !isNullOrUndefined(getInput('GIT_CONFIG_EMAIL')) email: !isNullOrUndefined(getInput('GIT_CONFIG_EMAIL'))
? getInput('GIT_CONFIG_EMAIL') ? getInput('GIT_CONFIG_EMAIL')
: pusher && pusher.email : pusher && pusher.email

View File

@ -148,11 +148,23 @@ export async function deploy(action: ActionInterface): Promise<Status> {
// Checks out the base branch to begin the deployment process. // Checks out the base branch to begin the deployment process.
await switchToBaseBranch(action) await switchToBaseBranch(action)
await execute( await execute(
`git fetch ${action.repositoryPath}`, `git fetch ${action.repositoryPath}`,
action.workspace, action.workspace,
action.silent action.silent
) )
if (action.lfs) {
// Migrates data from LFS so it can be comitted the "normal" way.
info(`Migrating from Git LFS… ⚓`)
await execute(
`git lfs migrate export --include="*" --yes`,
action.workspace,
action.silent
)
}
await execute( await execute(
`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${action.branch}`, `git worktree add --checkout ${temporaryDeploymentDirectory} origin/${action.branch}`,
action.workspace, action.workspace,

View File

@ -1,6 +1,9 @@
import {isDebug} from '@actions/core' import {isDebug} from '@actions/core'
import {ActionInterface} from './constants' import {ActionInterface} from './constants'
const replaceAll = (input: string, find: string, replace: string): string =>
input.split(find).join(replace)
/* Utility function that checks to see if a value is undefined or not. */ /* Utility function that checks to see if a value is undefined or not. */
export const isNullOrUndefined = (value: any): boolean => export const isNullOrUndefined = (value: any): boolean =>
typeof value === 'undefined' || value === null || value === '' typeof value === 'undefined' || value === null || value === ''
@ -64,16 +67,14 @@ export const suppressSensitiveInformation = (
return value return value
} }
if (action.accessToken) { const orderedByLength = ([
value = value.replace(action.accessToken, '***') action.accessToken,
} action.gitHubToken,
action.repositoryPath
].filter(Boolean) as string[]).sort((a, b) => b.length - a.length)
if (action.gitHubToken) { for (const find of orderedByLength) {
value = value.replace(action.gitHubToken, '***') value = replaceAll(value, find, '***')
}
if (action.repositoryPath) {
value = value.replace(action.repositoryPath, '***')
} }
return value return value

791
yarn.lock

File diff suppressed because it is too large Load Diff