This repository was archived by the owner on Aug 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathconfig.ts
More file actions
80 lines (72 loc) · 2.09 KB
/
Copy pathconfig.ts
File metadata and controls
80 lines (72 loc) · 2.09 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as core from '@actions/core'
import * as z from 'zod'
const FormatEnum = z.enum(['csv', 'json'])
export type FormatEnum = z.infer<typeof FormatEnum>
const CommonConfigSchema = z.object({
downloaded_filename: z.string(),
postprocess: z.string().optional(),
})
export type CommonConfig = z.infer<typeof CommonConfigSchema>
const HTTPConfigSchema = z
.object({
axios_config: z.string().optional(),
http_url: z.string(),
authorization: z.string().optional(),
mask: z.string().optional(), // string array of secrets or boolean
})
.merge(CommonConfigSchema)
export type HTTPConfig = z.infer<typeof HTTPConfigSchema>
const SQLConfigSchema = z
.object({
sql_connstring: z.string(),
sql_queryfile: z.string(),
typeorm_config: z.string().optional(),
})
.merge(CommonConfigSchema)
export type SQLConfig = z.infer<typeof SQLConfigSchema>
const ConfigSchema = z.union([HTTPConfigSchema, SQLConfigSchema])
export type Config = z.infer<typeof ConfigSchema>
export function getConfig(): Config {
const raw: { [k: string]: string } = {}
const keys = [
'axios_config',
'downloaded_filename',
'http_url',
'authorization',
'mask',
'sql_connstring',
'sql_queryfile',
'postprocess',
'typeorm_config',
]
keys.forEach(k => {
const v = core.getInput(k) // getInput always returns a string
if (v) {
raw[k] = v
}
})
core.debug(`Raw config: ${JSON.stringify(raw)}`)
try {
if ('http_url' in raw) {
return HTTPConfigSchema.parse(raw)
} else if ('sql_connstring' in raw) {
return SQLConfigSchema.parse(raw)
} else {
throw new Error(
'One of `http_url` or `sql_connstring` inputs are required.'
)
}
} catch (error) {
throw new Error(
`Invalid configuration!\nReceived: ${JSON.stringify(raw)}\nFailure:${
error.message
}`
)
}
}
export function isHTTPConfig(config: Config): config is HTTPConfig {
return 'http_url' in config
}
export function isSQLConfig(config: Config): config is SQLConfig {
return 'sql_connstring' in config && 'sql_queryfile' in config
}