2020-03-05 21:19:45 +08:00
|
|
|
import {exportVariable, setFailed} from '@actions/core'
|
|
|
|
import {action, actionInterface} from './constants'
|
|
|
|
import {deploy, generateBranch, init} from './git'
|
|
|
|
import {generateRepositoryPath, generateTokenType} from './util'
|
2020-03-02 20:52:38 +08:00
|
|
|
|
|
|
|
/** Initializes and runs the action. */
|
|
|
|
export default async function run(
|
|
|
|
configuration: actionInterface
|
|
|
|
): Promise<void> {
|
2020-03-05 21:19:45 +08:00
|
|
|
let errorState: boolean = false
|
2020-03-02 20:52:38 +08:00
|
|
|
|
|
|
|
try {
|
2020-03-05 21:19:45 +08:00
|
|
|
console.log('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
|
|
|
|
|
|
|
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-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 {
|
|
|
|
console.log(
|
|
|
|
`${
|
|
|
|
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-05 21:19:45 +08:00
|
|
|
export {init, deploy, generateBranch, actionInterface}
|