Skip to content

Commit 275ee87

Browse files
other (#24)
* log calling url if provided & fix test. Co-authored-by: saffi <[email protected]>
1 parent d08c494 commit 275ee87

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

action.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ inputs:
44
VERSION:
55
description: specify client version
66
required: false
7-
default: 0.0.28
7+
default: 0.0.29
88
CF_API_KEY:
99
description: "Codefresh API KEY"
1010
required: true
@@ -126,6 +126,8 @@ runs:
126126
CF_JIRA_INTEGRATION: ${{ inputs.CF_JIRA_INTEGRATION }}
127127
CF_JIRA_FAIL_ON_NOT_FOUND: ${{ inputs.CF_JIRA_FAIL_ON_NOT_FOUND }}
128128
run: |
129+
CF_WORKFLOW_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
129130
env>cf_env
130-
echo 'CF_CI_TYPE="github-actions"' >> cf_env
131+
echo 'CF_CI_TYPE=github-actions' >> cf_env
132+
echo "CF_WORKFLOW_URL=$CF_WORKFLOW_URL" >> cf_env
131133
docker run --env-file=cf_env quay.io/codefresh/csdp-report-image:$VERSION

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.28
2+
version: 0.0.29

src/__tests__/validate.spec.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ describe('client report-image validation', () => {
66
try {
77
validate({ ENV1: '1', someVal: 'ignored' })
88
} catch (error) {
9-
expect(error.message).toBe(`Validation Error: ["CF_API_KEY must be provided as environment variable.","CF_IMAGE must be provided as environment variable."]`)
9+
expect(error.message).toBe(`Validation Error: ["CF_API_KEY must be provided as environment variable.",` +
10+
`"CF_IMAGE must be provided as environment variable.",`+
11+
`"CF_HOST must be provided as app-proxy http/s address"]`)
1012
return
1113
}
1214
fail(`should have thrown Validation Error`)
@@ -24,17 +26,4 @@ describe('client report-image validation', () => {
2426
'CF_IMAGE': 'testImage'
2527
})
2628
})
27-
it('default CF_HOST', async () => {
28-
let res
29-
try {
30-
res = validate({ CF_API_KEY: '1', alsoIgnored: 'ignored', IGNORED: 'ignored too', CF_IMAGE: 'testImage' })
31-
} catch (error) {
32-
fail(`should have not thrown an error ${JSON.stringify(error)}`)
33-
}
34-
expect(res).toEqual({
35-
'CF_API_KEY': '1',
36-
'CF_HOST': 'g.codefresh.io',
37-
'CF_IMAGE': 'testImage'
38-
})
39-
})
4029
})

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ async function main(): Promise<void> {
1717
console.debug(`Payload: ${JSON.stringify(payload, null, 2)}`)
1818
console.debug(`Sending request: ${url}, headers: ${JSON.stringify(headers)}`)
1919
}
20+
if (payload['CF_CI_TYPE'] && payload['CF_WORKFLOW_URL']) {
21+
console.info(`Running ${payload['CF_CI_TYPE']} URL: ${payload['CF_WORKFLOW_URL']}`)
22+
}
2023
const waitFor = new Promise((resolve, reject) => {
2124
const eventSource = new EventSource(url, { headers })
2225
eventSource.addEventListener('report', function (event) {

src/validate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export function validate(payload: Record<string, string|undefined>): Record<stri
1010
if (!filtered['CF_IMAGE']) {
1111
messages.push(`CF_IMAGE must be provided as environment variable.`)
1212
}
13+
if (!filtered['CF_HOST']) {
14+
messages.push(`CF_HOST must be provided as app-proxy http/s address`)
15+
}
1316
if (messages.length>0) {
1417
throw new Error(`Validation Error: ${JSON.stringify(messages)}`)
1518
}
16-
filtered['CF_HOST'] = filtered['CF_HOST'] || 'g.codefresh.io'
1719

1820
return filtered
1921
}

0 commit comments

Comments
 (0)