Skip to content

Commit 8c19c7f

Browse files
support git actions input env var (#14)
Co-authored-by: saffi <[email protected]>
1 parent b8e782b commit 8c19c7f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
name: csdp-report-image
2-
version: 0.0.18
2+
version: 0.0.19

src/validate.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Validate mandatory env vars. address host default
33
*/
44
export function validate(payload: Record<string, string|undefined>): Record<string, string|undefined> {
5-
const filtered = filterEnvVarPattern(payload)
5+
const filtered = { ...filterEnvVarPattern(payload), ...filterGitActionsEnvVarInputPattern(payload) }
66
const messages: string[] = []
77
if (!filtered['CF_API_KEY']) {
88
messages.push(`CF_API_KEY must be provided as environment variable.`)
@@ -30,3 +30,17 @@ function filterEnvVarPattern(env: Record<string, string|undefined>): Record<stri
3030
return obj
3131
}, {})
3232
}
33+
34+
/**
35+
* Filter git actions env for codefresh vars prefix
36+
* @param env
37+
*/
38+
function filterGitActionsEnvVarInputPattern(env: Record<string, string|undefined>): Record<string, string|undefined> {
39+
const from = 'INPUT_'.length
40+
return Object.keys(env)
41+
.filter(key => (/^INPUT_CF_[A-Z_]+$/.test(key)))
42+
.reduce((obj, key) => {
43+
obj[key.slice(from)] = env[key]
44+
return obj
45+
}, {})
46+
}

0 commit comments

Comments
 (0)