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

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-03-05 21:19:45 +08:00
import {exportVariable, setFailed} from '@actions/core'
2020-03-07 11:36:56 +08:00
import {action, ActionInterface} from './constants'
2020-03-05 21:19:45 +08:00
import {deploy, generateBranch, init} from './git'
import {generateRepositoryPath, generateTokenType} from './util'
2020-03-09 21:19:16 +08:00
/** Initializes and runs the action.
*
* @param {object} configuration - The action configuration.
*/
export default async function run(
2020-03-07 11:36:56 +08:00
configuration: ActionInterface
): Promise<void> {
2020-03-07 11:36:56 +08:00
let errorState = false
try {
2020-03-19 22:01:21 +08:00
console.log('Checking configuration and starting deployment… 🚦')
const settings = {
...action,
...configuration
2020-03-05 21:19:45 +08:00
}
// Defines the repository paths and token types.
2020-03-05 21:19:45 +08:00
settings.repositoryPath = generateRepositoryPath(settings)
settings.tokenType = generateTokenType(settings)
if (settings.debug) {
// Sets the debug flag if passed as an arguement.
2020-03-05 21:19:45 +08:00
exportVariable('DEBUG_DEPLOY_ACTION', 'debug')
}
2020-03-05 21:19:45 +08:00
await init(settings)
await deploy(settings)
} catch (error) {
2020-03-05 21:19:45 +08:00
errorState = true
setFailed(error.message)
} finally {
console.log(
`${
errorState
2020-03-05 21:19:45 +08:00
? 'Deployment Failed ❌'
: 'Completed Deployment Successfully! ✅'
}`
2020-03-05 21:19:45 +08:00
)
}
}
2020-03-07 11:36:56 +08:00
export {init, deploy, generateBranch, ActionInterface}