diff --git a/src/github/artifact.ts b/src/github/artifact.ts index 623f6d7..52a2f45 100644 --- a/src/github/artifact.ts +++ b/src/github/artifact.ts @@ -4,12 +4,12 @@ import { ArtifactClient, DefaultArtifactClient } from "@actions/artifact/lib/internal/client.js"; +import { WORKFLOW_HASH } from "../helpers/constants.js"; function generateArtifactName(): string { const prefix: string = "vmd-report"; const randomHash: string = Math.floor(Math.random() * 1e8).toString(); - const timestamp: string = Date.now().toString(); - return `${prefix}-${randomHash}-${timestamp}`; + return `${prefix}-${WORKFLOW_HASH}-${randomHash}`; } export async function uploadOutputArtifact( diff --git a/src/github/cache.ts b/src/github/cache.ts index 79cd9d9..a616026 100644 --- a/src/github/cache.ts +++ b/src/github/cache.ts @@ -1,16 +1,14 @@ import * as core from "@actions/core"; import * as cache from "@actions/cache"; -import * as github from "@actions/github"; import { VMDAnalysis } from "../types.js"; import { parseAnalysisOutput } from "../helpers/parser.js"; - -const workflow: string = github.context.workflow; +import { WORKFLOW_HASH } from "../helpers/constants.js"; export async function saveCache( filePath: string, branch: string ): Promise { - const cacheId: string = `vmd-analysis-${branch}-${workflow}`; + const cacheId: string = `vmd-analysis-${branch}-${WORKFLOW_HASH}`; const cachePaths: string[] = [filePath]; try { await cache.saveCache(cachePaths, cacheId); @@ -23,7 +21,7 @@ export async function restoreCache( branch: string, cachePath: string ): Promise { - const cacheId: string = `vmd-analysis-${branch}-${workflow}`; + const cacheId: string = `vmd-analysis-${branch}-${WORKFLOW_HASH}`; try { const cacheKey: string | undefined = await cache.restoreCache( [cachePath], diff --git a/src/helpers/constants.ts b/src/helpers/constants.ts index 8121091..b6aae66 100644 --- a/src/helpers/constants.ts +++ b/src/helpers/constants.ts @@ -1,3 +1,6 @@ +import crypto from "node:crypto"; +import * as github from "@actions/github"; + export const ERROR_WEIGHT: number = 1.5; export const LOW_HEALTH_THRESHOLD: number = 75; export const MEDIUM_HEALTH_THRESHOLD: number = 85; @@ -8,3 +11,8 @@ export const ASSETS_URL: string = export const ISSUES_URL: string = "https://github.com/brenoepics/vmd-action/issues/"; export const REPORT_PATH: string = "vmd-analysis.json"; + +export const WORKFLOW_HASH: string = crypto + .createHash("sha256") + .update(github.context.workflow) + .digest("hex");