Skip to content

Commit

Permalink
fix: artifact names
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed Oct 13, 2024
1 parent a1c6eaa commit 167b3ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/github/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions src/github/cache.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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);
Expand All @@ -23,7 +21,7 @@ export async function restoreCache(
branch: string,
cachePath: string
): Promise<VMDAnalysis | undefined> {
const cacheId: string = `vmd-analysis-${branch}-${workflow}`;
const cacheId: string = `vmd-analysis-${branch}-${WORKFLOW_HASH}`;
try {
const cacheKey: string | undefined = await cache.restoreCache(
[cachePath],
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");

0 comments on commit 167b3ea

Please sign in to comment.