This repository was archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmain.ts
63 lines (55 loc) · 1.63 KB
/
main.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
import * as core from "@actions/core"
import axios, { AxiosResponse, ResponseType } from "axios"
import { readFileSync } from "fs"
import snake from "snakecase-keys"
import camel from "camelcase-keys"
interface Deploy {
revision: string
branch: string
environment: string | null
version: string | null
repositoryUrl: string
}
const DEPLOYS_URL: string =
process.env.VELOCITY_DEPLOYS_URL || "https://velocity.codeclimate.com/deploys"
const GITHUB_EVENT_PATH: string = process.env.GITHUB_EVENT_PATH as string
const readEvent = (): any =>
camel(JSON.parse(readFileSync(GITHUB_EVENT_PATH, "utf8")), { deep: true })
const report = (deploy: Deploy): Promise<AxiosResponse<any>> =>
axios.post(
DEPLOYS_URL,
snake({
...deploy,
token: core.getInput("token"),
}),
{
headers: {
Accept: "application/json",
},
}
)
const run = async (): Promise<void> => {
const event = readEvent()
const deploy: Deploy = {
revision: process.env.GITHUB_SHA as string,
branch: (process.env.GITHUB_REF as string).replace("refs/heads", ""),
environment:
core.getInput("environment") ||
(event.deployment || {}).environment ||
null,
version: core.getInput("version") || null,
repositoryUrl: event.repository.url,
}
core.debug("Reporting deploy to Velocity...")
core.debug(`revision: ${deploy.revision}`)
core.debug(`branch: ${deploy.branch}`)
core.debug(`environment: ${deploy.environment}`)
core.debug(`version: ${deploy.version}`)
try {
await report(deploy)
core.debug("Reported deploy.")
} catch (error) {
core.setFailed(error.message)
}
}
run()