2020-03-28 22:35:26 +08:00
|
|
|
import {info, 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-02 20:52:38 +08:00
|
|
|
|
2020-03-09 21:19:16 +08:00
|
|
|
/** Initializes and runs the action.
|
|
|
|
*
|
|
|
|
* @param {object} configuration - The action configuration.
|
|
|
|
*/
|
2020-03-02 20:52:38 +08:00
|
|
|
export default async function run(
|
2020-03-07 11:36:56 +08:00
|
|
|
configuration: ActionInterface
|
2020-03-02 20:52:38 +08:00
|
|
|
): Promise<void> {
|
2020-03-07 11:36:56 +08:00
|
|
|
let errorState = false
|
2020-03-02 20:52:38 +08:00
|
|
|
|
|
|
|
try {
|
2020-03-28 22:35:26 +08:00
|
|
|
info('Checking configuration and starting deployment… 🚦')
|
2020-03-02 20:52:38 +08:00
|
|
|
|
|
|
|
const settings = {
|
|
|
|
...action,
|
|
|
|
...configuration
|
2020-03-05 21:19:45 +08:00
|
|
|
}
|
2020-03-02 20:52:38 +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-02 20:52:38 +08:00
|
|
|
|
2020-03-05 21:19:45 +08:00
|
|
|
await init(settings)
|
|
|
|
await deploy(settings)
|
2020-03-02 20:52:38 +08:00
|
|
|
} catch (error) {
|
2020-03-05 21:19:45 +08:00
|
|
|
errorState = true
|
|
|
|
setFailed(error.message)
|
2020-03-02 20:52:38 +08:00
|
|
|
} finally {
|
2020-03-28 22:35:26 +08:00
|
|
|
info(
|
2020-03-02 20:52:38 +08:00
|
|
|
`${
|
|
|
|
errorState
|
2020-03-05 21:19:45 +08:00
|
|
|
? 'Deployment Failed ❌'
|
|
|
|
: 'Completed Deployment Successfully! ✅'
|
2020-03-02 20:52:38 +08:00
|
|
|
}`
|
2020-03-05 21:19:45 +08:00
|
|
|
)
|
2020-03-02 20:52:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 11:36:56 +08:00
|
|
|
export {init, deploy, generateBranch, ActionInterface}
|