-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputs.ts
65 lines (62 loc) · 1.75 KB
/
inputs.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
64
65
import * as core from '@actions/core'
import { z } from 'zod'
export const InputSchema = z.discriminatedUnion('phase', [
z.object({
service_name: z.string(),
channel_id: z.string(),
team: z.string(),
group_id: z.string(),
phase: z.literal('start'),
environment: z.string(),
before_ref: z.string()
}),
z.object({
service_name: z.string(),
channel_id: z.string(),
team: z.string(),
group_id: z.string(),
phase: z.literal('finish'),
environment: z.string(),
before_ref: z.string(),
thread_ts: z.string()
}),
z.object({
service_name: z.string(),
channel_id: z.string(),
team: z.string(),
group_id: z.string(),
phase: z.literal('failure'),
environment: z.string(),
before_ref: z.string(),
thread_ts: z.string()
}),
z.object({
service_name: z.string(),
channel_id: z.string(),
team: z.string(),
group_id: z.string(),
phase: z.literal('cancelled'),
environment: z.string(),
before_ref: z.string(),
thread_ts: z.string()
})
])
export function getEnvVariable(name: string): string {
const value = process.env[name]
if (!value) {
throw new Error(`Env variable ${name} is missing.`)
}
return value
}
export function parseInputs() {
return InputSchema.parse({
service_name: core.getInput('service_name', { required: true }),
channel_id: core.getInput('channel_id', { required: true }),
team: core.getInput('team', { required: true }),
group_id: core.getInput('group_id', { required: true }),
phase: core.getInput('phase', { required: true }),
environment: core.getInput('environment', { required: true }),
before_ref: core.getInput('before_ref', { required: true }),
thread_ts: core.getInput('thread_ts')
})
}