-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (44 loc) · 1.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import fs from 'fs'
import core from '@actions/core'
import github from '@actions/github'
import fetch from 'node-fetch'
import esbuild from 'esbuild'
import httpPlugin from 'esbuild-plugin-http'
try {
const time = (new Date()).toTimeString()
//console.log(JSON.stringify(github.context , null, 2))
await esbuild.build({
entryPoints: [core.getInput('main')],
bundle: true,
format: 'esm',
outfile: core.getInput('outfile'),
plugins: [httpPlugin],
}).catch(() => process.exit(1))
const worker = fs.readFileSync(core.getInput('outfile'))
console.log(`The ESBuild output: ${worker}`)
const name = core.getInput('name') ?? github.context.repository.name
const domain = core.getInput('domain')
const cloudflareAccountId = core.getInput('cloudflareAccountId')
const cloudflareApiToken = core.getInput('cloudflareApiToken')
const deployment = await fetch('https://workers.do/api/deploy', {
method: 'POST',
body: JSON.stringify({
name,
domain: `${domain}`,
context: github.context,
worker: `${worker}`,
cloudflareAccountId: `${cloudflareAccountId}`,
cloudflareApiToken: `${cloudflareApiToken}`,
}),
}).then(res => res.json()).catch(({name, message, stack}) => ({ error: {name, message, stack}}))
const commentText = deployment?.commentText
if (commentText) {
core.setOutput("url", commentText)
fs.writeFileSync(process.env.GITHUB_STEP_SUMMARY, commentText)
console.log(`The deployment results: ${JSON.stringify(deployment, null, 2)}`)
} else {
core.setFailed(JSON.stringify(deployment, null, 2))
}
} catch (error) {
core.setFailed(error.stack)
}