Files
deploy-pages/src/index.js
T

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-12-13 23:03:09 -05:00
// This package assumes a site has already been built and the files exist in the current workspace
// If there's an artifact named `artifact.tar`, it can upload that to actions on its own,
// without the user having to do the tar process themselves.
const core = require('@actions/core')
// const github = require('@actions/github'); // TODO: Not used until we publish API endpoint to the @action/github package
2022-08-23 17:19:21 -07:00
const { Deployment } = require('./deployment')
2021-12-13 23:03:09 -05:00
const deployment = new Deployment()
async function cancelHandler(evtOrExitCodeOrError) {
2022-08-23 21:32:40 -07:00
await deployment.cancel()
2021-12-13 23:03:09 -05:00
process.exit(isNaN(+evtOrExitCodeOrError) ? 1 : +evtOrExitCodeOrError)
}
async function main() {
2022-08-23 17:19:21 -07:00
let idToken = ''
2022-06-28 17:44:21 -07:00
try {
idToken = await core.getIDToken()
} catch (error) {
2022-06-28 17:55:21 -07:00
console.log(error)
2022-12-01 00:21:00 +08:00
core.setFailed(`Ensure GITHUB_TOKEN has permission "id-token: write".`)
2022-06-28 17:44:21 -07:00
return
}
2021-12-13 23:03:09 -05:00
try {
await deployment.create(idToken)
await deployment.check()
} catch (error) {
core.setFailed(error)
}
}
// Register signal handlers for workflow cancellation
process.on('SIGINT', cancelHandler)
process.on('SIGTERM', cancelHandler)
// Main
2022-08-23 17:19:21 -07:00
const emitTelemetry = core.getInput('emit_telemetry')
if (emitTelemetry === 'true') {
// For compatibility, treat the use of this deprecated input as a no-op
2022-03-29 10:05:17 -04:00
} else {
main()
}