Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/src/rest/__tests__/test-sessions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ describe('TestSessions REST client', () => {
runAttempt: '2',
workflow: 'Checkly',
job: 'validate',
jobId: '42424242',
eventName: 'pull_request',
ref: 'refs/pull/4/merge',
headRef: 'herve/test-checkly-action',
baseRef: 'main',
serverUrl: 'https://github.com',
rerun: 'repository-dispatch',
},
}

Expand Down
35 changes: 35 additions & 0 deletions packages/cli/src/services/__tests__/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ const ENV_KEYS = [
'CHECKLY_GITHUB_RUN_ATTEMPT',
'CHECKLY_GITHUB_WORKFLOW',
'CHECKLY_GITHUB_JOB',
'CHECKLY_GITHUB_JOB_ID',
'CHECKLY_GITHUB_EVENT_NAME',
'CHECKLY_GITHUB_REF',
'CHECKLY_GITHUB_HEAD_REF',
'CHECKLY_GITHUB_BASE_REF',
'CHECKLY_GITHUB_SERVER_URL',
'CHECKLY_GITHUB_RERUN',
] as const

describe('util', () => {
Expand Down Expand Up @@ -174,11 +176,13 @@ describe('util', () => {
process.env.CHECKLY_GITHUB_RUN_ATTEMPT = '2'
process.env.CHECKLY_GITHUB_WORKFLOW = 'Checkly'
process.env.CHECKLY_GITHUB_JOB = 'validate'
process.env.CHECKLY_GITHUB_JOB_ID = '42424242'
process.env.CHECKLY_GITHUB_EVENT_NAME = 'pull_request'
process.env.CHECKLY_GITHUB_REF = 'refs/pull/4/merge'
process.env.CHECKLY_GITHUB_HEAD_REF = 'herve/test-checkly-action'
process.env.CHECKLY_GITHUB_BASE_REF = 'main'
process.env.CHECKLY_GITHUB_SERVER_URL = 'https://github.com'
process.env.CHECKLY_GITHUB_RERUN = 'repository-dispatch'

expect(getGitInformation()).toEqual(expect.objectContaining({
commitId: 'abc123def456',
Expand All @@ -195,14 +199,45 @@ describe('util', () => {
runAttempt: '2',
workflow: 'Checkly',
job: 'validate',
jobId: '42424242',
eventName: 'pull_request',
ref: 'refs/pull/4/merge',
headRef: 'herve/test-checkly-action',
baseRef: 'main',
serverUrl: 'https://github.com',
rerun: 'repository-dispatch',
},
}))
})

it('should trim the GitHub job id and re-run mode', () => {
process.env.CHECKLY_GITHUB_REPORT = 'true'
process.env.CHECKLY_GITHUB_SHA = 'abc123def456'
process.env.CHECKLY_GITHUB_JOB_ID = ' 42424242\n'
process.env.CHECKLY_GITHUB_RERUN = ' repository-dispatch '

expect(getGitInformation()?.github).toEqual(expect.objectContaining({
jobId: '42424242',
rerun: 'repository-dispatch',
}))
})

it.each([
['unset', undefined],
['empty', ''],
['whitespace only', ' '],
])('should leave the GitHub job id and re-run mode out of the payload when %s', (_, value) => {
process.env.CHECKLY_GITHUB_REPORT = 'true'
process.env.CHECKLY_GITHUB_SHA = 'abc123def456'
if (value !== undefined) {
process.env.CHECKLY_GITHUB_JOB_ID = value
process.env.CHECKLY_GITHUB_RERUN = value
}

const payload = JSON.parse(JSON.stringify(getGitInformation()))
expect(payload.github).not.toHaveProperty('jobId')
expect(payload.github).not.toHaveProperty('rerun')
})
})

describe('normalizeGitRemoteUrl()', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/services/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export interface GitHubActionsInformation {
runAttempt?: string
workflow?: string
job?: string
jobId?: string
eventName?: string
ref?: string
headRef?: string
baseRef?: string
serverUrl?: string
rerun?: string
}

export interface CiInformation {
Expand Down Expand Up @@ -157,6 +159,10 @@ function isGitHubReportingEnabled (): boolean {
return value === 'true' || value === '1'
}

function getTrimmedEnv (name: string): string | undefined {
return process.env[name]?.trim() || undefined
}

export function findFilesRecursively (directory: string, ignoredPaths: Array<string> = []) {
if (!fsSync.statSync(directory, { throwIfNoEntry: false })?.isDirectory()) {
return []
Expand Down Expand Up @@ -274,11 +280,13 @@ export function getGitInformation (repoUrl?: string, cwd: string = process.cwd()
runAttempt: process.env.CHECKLY_GITHUB_RUN_ATTEMPT,
workflow: process.env.CHECKLY_GITHUB_WORKFLOW,
job: process.env.CHECKLY_GITHUB_JOB,
jobId: getTrimmedEnv('CHECKLY_GITHUB_JOB_ID'),
eventName: process.env.CHECKLY_GITHUB_EVENT_NAME,
ref: process.env.CHECKLY_GITHUB_REF,
headRef: process.env.CHECKLY_GITHUB_HEAD_REF,
baseRef: process.env.CHECKLY_GITHUB_BASE_REF,
serverUrl: process.env.CHECKLY_GITHUB_SERVER_URL,
rerun: getTrimmedEnv('CHECKLY_GITHUB_RERUN'),
}
}

Expand Down
Loading