github-pages-deploy-action/src/constants.ts

114 lines
4.5 KiB
TypeScript
Raw Normal View History

2020-03-05 21:19:45 +08:00
import {getInput} from '@actions/core'
import * as github from '@actions/github'
import {isNullOrUndefined} from './util'
2020-03-05 21:19:45 +08:00
const {pusher, repository} = github.context.payload
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
2020-03-07 11:36:56 +08:00
export interface ActionInterface {
/** Deployment access token. */
2020-03-05 21:19:45 +08:00
accessToken?: string | null
/** The base branch that the deploy should be made from. */
2020-03-05 21:19:45 +08:00
baseBranch?: string
/** The branch that the action should deploy to. */
2020-03-05 21:19:45 +08:00
branch: string
/** 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. */
2020-03-29 01:27:15 +08:00
clean?: boolean | null
/** If you need to use CLEAN but you'd like to preserve certain files or folders you can use this option. */
2020-03-07 11:36:56 +08:00
cleanExclude?: string | string[]
/** If you need to customize the commit message for an integration you can do so. */
2020-03-05 21:19:45 +08:00
commitMessage?: string
/** The default branch of the deployment. Similar to baseBranch if you're using this action as a module. */
2020-03-05 21:19:45 +08:00
defaultBranch?: string
/** The git config email. */
2020-03-05 21:19:45 +08:00
email?: string
/** The folder to deploy. */
2020-03-05 21:19:45 +08:00
folder: string
/** GitHub deployment token. */
2020-03-05 21:19:45 +08:00
gitHubToken?: string | null
/** Determines if the action is running in test mode or not. */
2020-03-29 01:27:15 +08:00
isTest?: boolean | null
2020-09-13 05:33:19 +08:00
/** Removes files from LFS if toggled to allow normal deployment. */
lfs?: boolean | null
/** The git config name. */
2020-03-05 21:19:45 +08:00
name?: string
2020-03-09 21:19:16 +08:00
/** The repository path, for example JamesIves/github-pages-deploy-action. */
2020-03-05 21:19:45 +08:00
repositoryName?: string
2020-03-02 21:37:55 +08:00
/** The fully qualified repositpory path, this gets auto generated if repositoryName is provided. */
2020-03-05 21:19:45 +08:00
repositoryPath?: string
/** The root directory where your project lives. */
2020-03-05 21:19:45 +08:00
root?: string
/** Wipes the commit history from the deployment branch in favor of a single commit. */
singleCommit?: boolean | null
2020-06-26 20:18:23 +08:00
/** Determines if the action should run in silent mode or not. */
2020-06-27 02:10:06 +08:00
silent: boolean
/** Set to true if you're using an ssh client in your build step. */
2020-03-29 01:27:15 +08:00
ssh?: boolean | null
/** 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. */
2020-03-05 21:19:45 +08:00
targetFolder?: string
/** The token type, ie ssh/github token/access token, this gets automatically generated. */
2020-03-05 21:19:45 +08:00
tokenType?: string
/** The folder where your deployment project lives. */
2020-03-05 21:19:45 +08:00
workspace: string
}
/* Required action data that gets initialized when running within the GitHub Actions environment. */
2020-03-07 11:36:56 +08:00
export const action: ActionInterface = {
2020-03-05 21:19:45 +08:00
accessToken: getInput('ACCESS_TOKEN'),
baseBranch: getInput('BASE_BRANCH'),
folder: getInput('FOLDER'),
branch: getInput('BRANCH'),
commitMessage: getInput('COMMIT_MESSAGE'),
2020-03-29 01:04:59 +08:00
clean: !isNullOrUndefined(getInput('CLEAN'))
? getInput('CLEAN').toLowerCase() === 'true'
: false,
2020-03-05 21:19:45 +08:00
cleanExclude: getInput('CLEAN_EXCLUDE'),
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : 'master',
2020-03-29 01:04:59 +08:00
isTest: process.env.UNIT_TEST
? process.env.UNIT_TEST.toLowerCase() === 'true'
: false,
2020-09-13 05:33:19 +08:00
lfs: !isNullOrUndefined(getInput('LFS'))
? getInput('LFS').toLowerCase() === 'true'
: false,
2020-03-05 21:19:45 +08:00
email: !isNullOrUndefined(getInput('GIT_CONFIG_EMAIL'))
? getInput('GIT_CONFIG_EMAIL')
: pusher && pusher.email
? pusher.email
2020-09-13 06:11:16 +08:00
: `${
process.env.GITHUB_ACTOR || 'github-pages-deploy-action'
}@users.noreply.github.com`,
2020-03-05 21:19:45 +08:00
gitHubToken: getInput('GITHUB_TOKEN'),
name: !isNullOrUndefined(getInput('GIT_CONFIG_NAME'))
? getInput('GIT_CONFIG_NAME')
: pusher && pusher.name
? pusher.name
: process.env.GITHUB_ACTOR
? process.env.GITHUB_ACTOR
2020-03-05 21:19:45 +08:00
: 'GitHub Pages Deploy Action',
repositoryName: !isNullOrUndefined(getInput('REPOSITORY_NAME'))
? getInput('REPOSITORY_NAME')
2020-03-02 21:37:55 +08:00
: repository && repository.full_name
? repository.full_name
: process.env.GITHUB_REPOSITORY,
2020-03-05 21:19:45 +08:00
root: '.',
singleCommit: !isNullOrUndefined(getInput('SINGLE_COMMIT'))
? getInput('SINGLE_COMMIT').toLowerCase() === 'true'
: false,
2020-06-26 20:18:23 +08:00
silent: !isNullOrUndefined(getInput('SILENT'))
? getInput('SILENT').toLowerCase() === 'true'
: false,
ssh: !isNullOrUndefined(getInput('SSH'))
? getInput('SSH').toLowerCase() === 'true'
: false,
2020-03-05 21:19:45 +08:00
targetFolder: getInput('TARGET_FOLDER'),
workspace: process.env.GITHUB_WORKSPACE || ''
}
/** Status codes for the action. */
export enum Status {
SUCCESS = 'success',
FAILED = 'failed',
SKIPPED = 'skipped',
RUNNING = 'running'
}