Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add more core reporting for the GitHub tools #54

Merged
merged 1 commit into from
Feb 2, 2022
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
73 changes: 55 additions & 18 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qodana-action",
"version": "4.2.4",
"version": "4.2.5",
"description": "Qodana is a code quality monitoring tool that identifies bugs, duplications, and imperfections.",
"main": "lib/main.js",
"scripts": {
Expand Down
95 changes: 73 additions & 22 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import * as core from '@actions/core'
import * as glob from '@actions/glob'
import path from 'path'

// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
// throw an uncaught exception. Instead of failing this action, just warn.
process.on('uncaughtException', e => core.warning(e.message))

export const QODANA_CHECK_NAME = 'Qodana'
export const QODANA_SARIF_NAME = 'qodana.sarif.json'
export const QODANA_HELP_STRING = `
Expand Down Expand Up @@ -34,12 +39,12 @@ export const NOT_SUPPORTED_IMAGES = [
]

/**
* Restores the cache from GitHub Actions cache to the given path.
* @param cacheDir The path to restore the cache to.
* @param additionalCacheHash Addition to the generated cache hash.
* Uploads the cache to GitHub Actions cache from the given path.
* @param cacheDir The path to upload the cache from.
* @param additionalCacheHash Addition to the generated cache hash
* @param execute whether to execute promise or not.
*/
export async function restoreCaches(
export async function uploadCaches(
cacheDir: string,
additionalCacheHash: string,
execute: boolean
Expand All @@ -48,26 +53,35 @@ export async function restoreCaches(
return
}
try {
await cache.restoreCache(
[cacheDir],
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}${additionalCacheHash}`,
[
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}-${additionalCacheHash}`,
`${process.env['RUNNER_OS']}-qodana-${additionalCacheHash}`
]
)
if (isGhes()) {
core.warning(
'Cache is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details'
)
return
}
const primaryKey = `qodana-${process.env['GITHUB_REF']}-${additionalCacheHash}`
try {
await cache.saveCache([cacheDir], primaryKey)
core.info(`Cache saved with key ${primaryKey}`)
} catch (error) {
core.warning(
`Failed to save cache with key ${primaryKey} – ${
(error as Error).message
}`
)
}
} catch (error) {
core.warning(`Failed to download caches – ${(error as Error).message}`)
core.warning(`Failed to upload caches – ${(error as Error).message}`)
}
}

/**
* Uploads the cache to GitHub Actions cache from the given path.
* @param cacheDir The path to upload the cache from.
* @param additionalCacheHash Addition to the generated cache hash
* Restores the cache from GitHub Actions cache to the given path.
* @param cacheDir The path to restore the cache to.
* @param additionalCacheHash Addition to the generated cache hash.
* @param execute whether to execute promise or not.
*/
export async function uploadCaches(
export async function restoreCaches(
cacheDir: string,
additionalCacheHash: string,
execute: boolean
Expand All @@ -76,12 +90,38 @@ export async function uploadCaches(
return
}
try {
await cache.saveCache(
[cacheDir],
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}-${additionalCacheHash}`
)
if (isGhes()) {
core.warning(
'Cache is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details'
)
return
}
const primaryKey = `qodana-${process.env['GITHUB_REF']}-${additionalCacheHash}`
const restoreKeys = [`qodana-${process.env['GITHUB_REF']}-`, `qodana-`]
try {
const cacheKey = await cache.restoreCache(
[cacheDir],
primaryKey,
restoreKeys
)
if (!cacheKey) {
core.info(
`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(
', '
)}`
)
return
}
core.info(`Cache restored from key: ${cacheKey}`)
} catch (error) {
core.warning(
`Failed to restore cache with key ${primaryKey} – ${
(error as Error).message
}`
)
}
} catch (error) {
core.warning(`Failed to upload caches – ${(error as Error).message}`)
core.warning(`Failed to download caches – ${(error as Error).message}`)
}
}

Expand All @@ -100,6 +140,7 @@ export async function uploadReport(
return
}
try {
core.info('Uploading report...')
const globber = await glob.create(`${resultsDir}/*`)
const files = await globber.glob()
await artifact
Expand Down Expand Up @@ -129,3 +170,13 @@ export function isExecutionSuccessful(exitCode: number): boolean {
export function isFailedByThreshold(exitCode: number): boolean {
return exitCode === QODANA_FAILTHRESHOLD_EXIT_CODE
}

/**
* Check if the action is run on GHE.
*/
export function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
)
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
}