2020-05-15 05:24:32 +08:00
|
|
|
import {exportVariable, info, setFailed} from '@actions/core'
|
2020-10-17 23:47:44 +08:00
|
|
|
import {ActionInterface, Status, NodeActionInterface} from './constants'
|
2020-10-07 21:34:20 +08:00
|
|
|
import {deploy, init} from './git'
|
2020-10-15 22:20:15 +08:00
|
|
|
import {
|
|
|
|
generateFolderPath,
|
|
|
|
checkParameters,
|
|
|
|
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-10-17 23:47:44 +08:00
|
|
|
configuration: ActionInterface | NodeActionInterface
|
2020-03-02 20:52:38 +08:00
|
|
|
): Promise<void> {
|
2020-05-15 05:24:32 +08:00
|
|
|
let status: Status = Status.RUNNING
|
2020-03-02 20:52:38 +08:00
|
|
|
|
|
|
|
try {
|
2020-07-05 04:11:12 +08:00
|
|
|
info(`
|
|
|
|
GitHub Pages Deploy Action 🚀
|
2020-07-05 02:29:45 +08:00
|
|
|
|
2020-07-05 04:11:12 +08:00
|
|
|
🚀 Getting Started Guide: https://github.com/marketplace/actions/deploy-to-github-pages
|
2020-10-17 23:47:44 +08:00
|
|
|
❓ Discussions / Q&A: https://github.com/JamesIves/github-pages-deploy-action/discussions
|
|
|
|
🔧 Report a Bug: https://github.com/JamesIves/github-pages-deploy-action/issues
|
|
|
|
|
2020-10-18 00:35:48 +08:00
|
|
|
📣 Maintained by James Ives: https://jamesiv.es
|
|
|
|
💖 Support: https://github.com/sponsors/JamesIves`)
|
2020-07-05 02:29:45 +08:00
|
|
|
|
2020-03-28 22:35:26 +08:00
|
|
|
info('Checking configuration and starting deployment… 🚦')
|
2020-03-02 20:52:38 +08:00
|
|
|
|
2020-10-17 23:47:44 +08:00
|
|
|
const settings: ActionInterface = {
|
2020-03-02 20:52:38 +08:00
|
|
|
...configuration
|
2020-03-05 21:19:45 +08:00
|
|
|
}
|
2020-03-02 20:52:38 +08:00
|
|
|
|
2020-10-17 23:47:44 +08:00
|
|
|
// Defines the repository/folder paths and token types.
|
|
|
|
// Also verifies that the action has all of the required parameters.
|
2020-10-15 22:20:15 +08:00
|
|
|
settings.folderPath = generateFolderPath(settings)
|
|
|
|
|
|
|
|
checkParameters(settings)
|
|
|
|
|
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)
|
2020-05-15 05:24:32 +08:00
|
|
|
status = await deploy(settings)
|
2020-03-02 20:52:38 +08:00
|
|
|
} catch (error) {
|
2020-05-15 05:24:32 +08:00
|
|
|
status = Status.FAILED
|
2020-03-05 21:19:45 +08:00
|
|
|
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
|
|
|
`${
|
2020-05-15 05:24:32 +08:00
|
|
|
status === Status.FAILED
|
2020-05-25 00:25:43 +08:00
|
|
|
? 'Deployment failed! ❌'
|
2020-05-15 05:24:32 +08:00
|
|
|
: status === Status.SUCCESS
|
2020-05-25 00:25:43 +08:00
|
|
|
? 'Completed deployment successfully! ✅'
|
2020-05-15 05:24:32 +08:00
|
|
|
: 'There is nothing to commit. Exiting early… 📭'
|
2020-03-02 20:52:38 +08:00
|
|
|
}`
|
2020-03-05 21:19:45 +08:00
|
|
|
)
|
2020-05-15 05:24:32 +08:00
|
|
|
|
|
|
|
exportVariable('DEPLOYMENT_STATUS', status)
|
2020-03-02 20:52:38 +08:00
|
|
|
}
|
|
|
|
}
|