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

Sanitize workflow name when generating cache key #757

Merged
merged 2 commits into from
Jun 29, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/demo-job-summary.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Demo Job Summary for Gradle builds
name: Demo Job Summary, for Gradle builds

on:
workflow_dispatch:
Expand Down
9 changes: 7 additions & 2 deletions dist/dependency-graph-generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71597,7 +71597,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getCacheKeyForJob = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(2186));
const cache = __importStar(__nccwpck_require__(7799));
const github = __importStar(__nccwpck_require__(5438));
Expand Down Expand Up @@ -71665,8 +71665,13 @@ function getCacheKeyEnvironment() {
return process.env[CACHE_KEY_OS_VAR] || runnerOs;
}
function getCacheKeyJob() {
return process.env[CACHE_KEY_JOB_VAR] || `${github.context.workflow}-${github.context.job}`;
return process.env[CACHE_KEY_JOB_VAR] || getCacheKeyForJob(github.context.workflow, github.context.job);
}
function getCacheKeyForJob(workflowName, jobId) {
const sanitizedWorkflow = workflowName.replace(/,/g, '').toLowerCase();
return `${sanitizedWorkflow}-${jobId}`;
}
exports.getCacheKeyForJob = getCacheKeyForJob;
function getCacheKeyJobInstance() {
const override = process.env[CACHE_KEY_JOB_INSTANCE_VAR];
if (override) {
Expand Down
2 changes: 1 addition & 1 deletion dist/dependency-graph-generate/index.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64382,7 +64382,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getCacheKeyForJob = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(2186));
const cache = __importStar(__nccwpck_require__(7799));
const github = __importStar(__nccwpck_require__(5438));
Expand Down Expand Up @@ -64450,8 +64450,13 @@ function getCacheKeyEnvironment() {
return process.env[CACHE_KEY_OS_VAR] || runnerOs;
}
function getCacheKeyJob() {
return process.env[CACHE_KEY_JOB_VAR] || `${github.context.workflow}-${github.context.job}`;
return process.env[CACHE_KEY_JOB_VAR] || getCacheKeyForJob(github.context.workflow, github.context.job);
}
function getCacheKeyForJob(workflowName, jobId) {
const sanitizedWorkflow = workflowName.replace(/,/g, '').toLowerCase();
return `${sanitizedWorkflow}-${jobId}`;
}
exports.getCacheKeyForJob = getCacheKeyForJob;
function getCacheKeyJobInstance() {
const override = process.env[CACHE_KEY_JOB_INSTANCE_VAR];
if (override) {
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63485,7 +63485,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getCacheKeyForJob = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(2186));
const cache = __importStar(__nccwpck_require__(7799));
const github = __importStar(__nccwpck_require__(5438));
Expand Down Expand Up @@ -63553,8 +63553,13 @@ function getCacheKeyEnvironment() {
return process.env[CACHE_KEY_OS_VAR] || runnerOs;
}
function getCacheKeyJob() {
return process.env[CACHE_KEY_JOB_VAR] || `${github.context.workflow}-${github.context.job}`;
return process.env[CACHE_KEY_JOB_VAR] || getCacheKeyForJob(github.context.workflow, github.context.job);
}
function getCacheKeyForJob(workflowName, jobId) {
const sanitizedWorkflow = workflowName.replace(/,/g, '').toLowerCase();
return `${sanitizedWorkflow}-${jobId}`;
}
exports.getCacheKeyForJob = getCacheKeyForJob;
function getCacheKeyJobInstance() {
const override = process.env[CACHE_KEY_JOB_INSTANCE_VAR];
if (override) {
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ function getCacheKeyEnvironment(): string {
}

function getCacheKeyJob(): string {
return process.env[CACHE_KEY_JOB_VAR] || `${github.context.workflow}-${github.context.job}`
return process.env[CACHE_KEY_JOB_VAR] || getCacheKeyForJob(github.context.workflow, github.context.job)
}

export function getCacheKeyForJob(workflowName: string, jobId: string): string {
const sanitizedWorkflow = workflowName.replace(/,/g, '').toLowerCase()
return `${sanitizedWorkflow}-${jobId}`
}

function getCacheKeyJobInstance(): string {
Expand Down
6 changes: 6 additions & 0 deletions test/jest/cache-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ describe('cacheUtils-utils', () => {
expect(posixHash).toBe(windowsHash)
})
})
describe('sanitizes workflow name in cache key', () => {
it('with comma', () => {
const cacheKey = cacheUtils.getCacheKeyForJob("Workflow, with,commas", "JOB_ID")
expect(cacheKey).toBe('workflow withcommas-JOB_ID')
})
})
})
Loading