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

57 lines
1.7 KiB
TypeScript
Raw Normal View History

import {exportVariable, info, setFailed} from '@actions/core'
import {action, ActionInterface, Status} 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> {
let status: Status = Status.RUNNING
try {
info(`GitHub Pages Deploy Action 🚀
Getting Started Guide: https://github.com/marketplace/actions/deploy-to-github-pages
FAQ: https://github.com/JamesIves/github-pages-deploy-action/wiki
🔧 Support: https://github.com/JamesIves/github-pages-deploy-action/issues
Contribute: https://github.com/JamesIves/github-pages-deploy-action/blob/dev/CONTRIBUTING.md
Maintainer: James Ives (https://jamesiv.es)`)
2020-03-28 22:35:26 +08:00
info('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)
2020-03-05 21:19:45 +08:00
await init(settings)
status = await deploy(settings)
} catch (error) {
status = Status.FAILED
2020-03-05 21:19:45 +08:00
setFailed(error.message)
} finally {
2020-03-28 22:35:26 +08:00
info(
`${
status === Status.FAILED
2020-05-25 00:25:43 +08:00
? 'Deployment failed! ❌'
: status === Status.SUCCESS
2020-05-25 00:25:43 +08:00
? 'Completed deployment successfully! ✅'
: 'There is nothing to commit. Exiting early… 📭'
}`
2020-03-05 21:19:45 +08:00
)
exportVariable('DEPLOYMENT_STATUS', status)
}
}
2020-03-07 11:36:56 +08:00
export {init, deploy, generateBranch, ActionInterface}