Skip to content

Commit

Permalink
✨ Merge pull request #29 from shyim/main
Browse files Browse the repository at this point in the history
Add cache key setting
  • Loading branch information
tiulpin committed Dec 28, 2021
2 parents ef23511 + f149f4b commit d88382a
Show file tree
Hide file tree
Showing 9 changed files with 2,558 additions and 2,539 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ You can set up [GitHub code scanning](https://docs.github.com/en/code-security/c
| `profile-path` | Absolute path to the profile file. Optional. | - |
| `upload-result` | Upload Qodana results as an artifact to the job. Optional. | `true` |
| `use-caches` | Utilize GitHub caches for Qodana runs. Optional. | `true` |
| `additional-cache-hash` | Allows customizing the generated cache hash. Optional. | |
| `use-annotations` | Use annotation to mark the results in the GitHub user interface. Optional. | `true` |
| `github-token` | GitHub token to be used for uploading results. Optional. | `${{ github.token }}` |

Expand Down
1 change: 1 addition & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function inputsDefaultFixture(): Inputs {
projectDir: '${{ github.workspace }}',
resultsDir: '${{ runner.temp }}/qodana-results',
cacheDir: '${{ runner.temp }}/qodana-caches',
additionalCacheHash: '',
additionalVolumes: [],
additionalEnvVars: [],
inspectedDir: '',
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description: 'Directory to store Qodana caches'
required: false
default: "${{ runner.temp }}/qodana/caches"
additional-cache-hash:
description: 'Pass additional cache hash extension'
required: false
default: "${{ github.sha }}"
idea-config-dir:
description: 'IntelliJ IDEA configuration directory'
required: false
Expand Down
5,061 changes: 2,532 additions & 2,529 deletions dist/index.js

Large diffs are not rendered by default.

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.1.1",
"version": "4.2.0",
"description": "Qodana is a code quality monitoring tool that identifies bugs, duplications, and imperfections.",
"main": "lib/main.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Inputs {
projectDir: string
resultsDir: string
cacheDir: string
additionalCacheHash: string
additionalVolumes: string[]
additionalEnvVars: string[]
inspectedDir: string
Expand Down Expand Up @@ -36,6 +37,7 @@ export function getInputs(): Inputs {
projectDir: core.getInput('project-dir'),
resultsDir: core.getInput('results-dir'),
cacheDir: core.getInput('cache-dir'),
additionalCacheHash: core.getInput('additional-cache-hash'),
additionalVolumes: core.getMultilineInput('additional-volumes'),
additionalEnvVars: core.getMultilineInput('additional-env-variables'),
inspectedDir: core.getInput('inspected-dir'),
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function main(): Promise<void> {
await io.mkdirP(inputs.resultsDir)

if (inputs.useCaches) {
await restoreCaches(inputs.cacheDir)
await restoreCaches(inputs.cacheDir, inputs.additionalCacheHash)
}

const args = getQodanaRunArgs(inputs)
Expand All @@ -52,7 +52,7 @@ async function main(): Promise<void> {
const failedByThreshold = isFailedByThreshold(dockerExec.exitCode)
if (isExecutionSuccessful(dockerExec.exitCode)) {
if (inputs.useCaches) {
await uploadCaches(inputs.cacheDir)
await uploadCaches(inputs.cacheDir, inputs.additionalCacheHash)
}

if (inputs.useAnnotations) {
Expand Down
20 changes: 14 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ export function validateContext(inputs: Inputs): Inputs {
/**
* 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
*/
export async function restoreCaches(cacheDir: string): Promise<void> {
export async function restoreCaches(
cacheDir: string,
additionalCacheHash: string
): Promise<void> {
try {
await cache.restoreCache(
[cacheDir],
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}`,
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}${additionalCacheHash}`,
[
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}-`,
`${process.env['RUNNER_OS']}-qodana-`
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}-${additionalCacheHash}`,
`${process.env['RUNNER_OS']}-qodana-${additionalCacheHash}`
]
)
} catch (error) {
Expand All @@ -71,12 +75,16 @@ export async function restoreCaches(cacheDir: string): Promise<void> {
/**
* 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
*/
export async function uploadCaches(cacheDir: string): Promise<void> {
export async function uploadCaches(
cacheDir: string,
additionalCacheHash: string
): Promise<void> {
try {
await cache.saveCache(
[cacheDir],
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}-${process.env['GITHUB_SHA']}`
`${process.env['RUNNER_OS']}-qodana-${process.env['GITHUB_REF']}-${additionalCacheHash}`
)
} catch (error) {
core.warning(`Failed to upload caches – ${(error as Error).message}`)
Expand Down

0 comments on commit d88382a

Please sign in to comment.