Skip to content

Commit

Permalink
improve debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
CCFenner committed Mar 15, 2024
1 parent e3fee3b commit 12e2006
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ export async function downloadPiperBinary (
const headers: any = {}
const piperBinaryName = await getPiperBinaryNameFromInputs(isEnterprise, version)
if (token !== '') {
debug('Fetching binary from GitHub API')
headers.Accept = 'application/octet-stream'
headers.Authorization = `token ${token}`

const [binaryAssetURL, tag] = await getReleaseAssetUrl(piperBinaryName, version, apiURL, token, owner, repo)
binaryURL = binaryAssetURL
version = tag
} else {
debug('Fetching binary from URL')
binaryURL = await getPiperDownloadURL(piperBinaryName, version)
version = binaryURL.split('/').slice(-2)[0]
}
Expand Down Expand Up @@ -87,7 +89,7 @@ async function getPiperReleases (version: string, api: string, token: string, ow
}

const octokit = new Octokit(options)
info(`Getting releases from ${api}/repos/${owner}/${repository}/releases/${tag}`)
debug(`Fetching release info from ${api}/repos/${owner}/${repository}/releases/${tag}`)
const response = await octokit.request(`GET /repos/${owner}/${repository}/releases/${tag}`)
if (response.status !== 200) {
throw new Error(`can't get release by tag ${tag}: ${response.status}`)
Expand Down
33 changes: 21 additions & 12 deletions test/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ describe('GitHub package tests', () => {
})

await downloadPiperBinary(osStep, 'latest', githubApiURL, '', owner, repo)
expect(core.debug).toHaveBeenNthCalledWith(1, 'Fetching binary from URL')
expect(core.debug).toHaveBeenCalledTimes(1)
expect(core.info).toHaveBeenCalledWith(`Downloading 'https://github.com/SAP/jenkins-library/releases/download/v1.1.1/piper' as '${process.cwd()}/${version.replace(/\./g, '_')}/piper'`)
expect(core.info).toHaveBeenCalledTimes(1)
})

test('downloadPiperBinary - SAP step latest', async () => {
Expand All @@ -79,10 +82,12 @@ describe('GitHub package tests', () => {
})

await downloadPiperBinary(sapStep, 'latest', githubApiURL, token, owner, repo)
expect(core.debug).toHaveBeenCalledWith(`Found asset URL: ${assetUrl} and tag: ${version}`)
expect(core.info).toHaveBeenNthCalledWith(1, `Getting releases from ${githubApiURL}/repos/${owner}/${repo}/releases/latest`)
expect(core.info).toHaveBeenNthCalledWith(2, expect.stringContaining(`Downloading '${assetUrl}' as '${process.cwd()}/${version.replace(/\./g, '_')}/sap-piper'`))
expect(core.info).toHaveBeenCalledTimes(2)
expect(core.debug).toHaveBeenNthCalledWith(1, 'Fetching binary from GitHub API')
expect(core.debug).toHaveBeenNthCalledWith(2, `Fetching release info from ${githubApiURL}/repos/${owner}/${repo}/releases/latest`)
expect(core.debug).toHaveBeenNthCalledWith(5, `Found asset URL: ${assetUrl} and tag: ${version}`)
expect(core.debug).toHaveBeenCalledTimes(5)
expect(core.info).toHaveBeenNthCalledWith(1, expect.stringContaining(`Downloading '${assetUrl}' as '${process.cwd()}/${version.replace(/\./g, '_')}/sap-piper'`))
expect(core.info).toHaveBeenCalledTimes(1)
})

test('downloadPiperBinary - OS step, master', async () => {

Check warning on line 93 in test/github.test.ts

View check run for this annotation

In Solidarity / Inclusive Language

Match Found

Please consider an alternative to `master`. Possibilities include: `primary`, `main`, `leader`, `active`, `writer`
Raw output
/\b(?!masterdata|masterdata\w+\b)master/gi
Expand All @@ -102,10 +107,12 @@ describe('GitHub package tests', () => {
})

await downloadPiperBinary(osStep, 'master', githubApiURL, token, owner, repo)

Check warning on line 109 in test/github.test.ts

View check run for this annotation

In Solidarity / Inclusive Language

Match Found

Please consider an alternative to `master`. Possibilities include: `primary`, `main`, `leader`, `active`, `writer`
Raw output
/\b(?!masterdata|masterdata\w+\b)master/gi
expect(core.debug).toHaveBeenCalledWith(`Found asset URL: ${assetUrl} and tag: ${version}`)
expect(core.info).toHaveBeenNthCalledWith(1, `Getting releases from ${githubApiURL}/repos/${owner}/${repo}/releases/latest`)
expect(core.info).toHaveBeenNthCalledWith(2, expect.stringContaining(`Downloading '${assetUrl}' as '${process.cwd()}/${version.replace(/\./g, '_')}/piper_master'`))
expect(core.info).toHaveBeenCalledTimes(2)
expect(core.debug).toHaveBeenNthCalledWith(1, 'Fetching binary from GitHub API')
expect(core.debug).toHaveBeenNthCalledWith(2, `Fetching release info from ${githubApiURL}/repos/${owner}/${repo}/releases/latest`)
expect(core.debug).toHaveBeenNthCalledWith(5, `Found asset URL: ${assetUrl} and tag: ${version}`)
expect(core.debug).toHaveBeenCalledTimes(5)
expect(core.info).toHaveBeenNthCalledWith(1, expect.stringContaining(`Downloading '${assetUrl}' as '${process.cwd()}/${version.replace(/\./g, '_')}/piper_master'`))
expect(core.info).toHaveBeenCalledTimes(1)
})

test('downloadPiperBinary - OS step, exact version', async () => {
Expand All @@ -125,10 +132,12 @@ describe('GitHub package tests', () => {
})

await downloadPiperBinary(osStep, version, githubApiURL, token, owner, repo)
expect(core.debug).toHaveBeenCalledWith(`Found asset URL: ${assetUrl} and tag: ${version}`)
expect(core.info).toHaveBeenNthCalledWith(1, `Getting releases from ${githubApiURL}/repos/${owner}/${repo}/releases/tags/${version}`)
expect(core.info).toHaveBeenNthCalledWith(2, expect.stringContaining(`Downloading '${assetUrl}' as '${process.cwd()}/${version.replace(/\./g, '_')}/piper'`))
expect(core.info).toHaveBeenCalledTimes(2)
expect(core.debug).toHaveBeenNthCalledWith(1, 'Fetching binary from GitHub API')
expect(core.debug).toHaveBeenNthCalledWith(2, `Fetching release info from ${githubApiURL}/repos/${owner}/${repo}/releases/tags/${version}`)
expect(core.debug).toHaveBeenNthCalledWith(5, `Found asset URL: ${assetUrl} and tag: ${version}`)
expect(core.debug).toHaveBeenCalledTimes(5)
expect(core.info).toHaveBeenNthCalledWith(1, expect.stringContaining(`Downloading '${assetUrl}' as '${process.cwd()}/${version.replace(/\./g, '_')}/piper'`))
expect(core.info).toHaveBeenCalledTimes(1)
})

test('Get dev Piper', async () => {
Expand Down

0 comments on commit 12e2006

Please sign in to comment.