@@ -7,6 +7,7 @@ export function parseArgs(argv) {
77 const args = {
88 cwd : process . cwd ( ) ,
99 workingDirectory : '.' ,
10+ cacheKeySuffix : '' ,
1011 githubOutput : process . env . GITHUB_OUTPUT ?? '' ,
1112 } ;
1213
@@ -19,6 +20,9 @@ export function parseArgs(argv) {
1920 } else if ( arg === '--working-directory' ) {
2021 args . workingDirectory = argv [ index + 1 ] ?? '.' ;
2122 index += 1 ;
23+ } else if ( arg === '--cache-key-suffix' ) {
24+ args . cacheKeySuffix = argv [ index + 1 ] ?? '' ;
25+ index += 1 ;
2226 } else if ( arg === '--github-output' ) {
2327 args . githubOutput = argv [ index + 1 ] ?? '' ;
2428 index += 1 ;
@@ -76,6 +80,15 @@ export function buildWorkingDirectoryKey(workingDirectory) {
7680 return `${ slug } -${ digest } ` ;
7781}
7882
83+ export function normalizeCacheKeySuffix ( cacheKeySuffix ) {
84+ const normalized = cacheKeySuffix . trim ( ) ;
85+ if ( normalized === '' ) {
86+ return '' ;
87+ }
88+
89+ return normalized . replace ( / [ ^ A - Z a - z 0 - 9 _ . - ] + / g, '-' ) ;
90+ }
91+
7992export function buildCachePaths ( workingDirectory ) {
8093 const base = workingDirectory === '.' ? '' : `${ workingDirectory } /` ;
8194 return [
@@ -86,8 +99,9 @@ export function buildCachePaths(workingDirectory) {
8699 ] ;
87100}
88101
89- export function buildResult ( { cwd, workingDirectory } ) {
102+ export function buildResult ( { cwd, workingDirectory, cacheKeySuffix = '' } ) {
90103 const resolvedWorkingDirectory = resolveWorkingDirectory ( cwd , workingDirectory ) ;
104+ const normalizedCacheKeySuffix = normalizeCacheKeySuffix ( cacheKeySuffix ) ;
91105
92106 return {
93107 absoluteWorkingDirectory : resolvedWorkingDirectory . absoluteWorkingDirectory ,
@@ -96,6 +110,9 @@ export function buildResult({ cwd, workingDirectory }) {
96110 resolvedWorkingDirectory . workingDirectory ,
97111 ) ,
98112 cachePaths : buildCachePaths ( resolvedWorkingDirectory . workingDirectory ) ,
113+ cacheKeySuffix : normalizedCacheKeySuffix ,
114+ cacheKeySuffixSegment :
115+ normalizedCacheKeySuffix === '' ? '' : `-${ normalizedCacheKeySuffix } ` ,
99116 } ;
100117}
101118
@@ -122,6 +139,7 @@ export function main(argv = process.argv.slice(2)) {
122139 const result = buildResult ( {
123140 cwd : args . cwd ,
124141 workingDirectory : args . workingDirectory ,
142+ cacheKeySuffix : args . cacheKeySuffix ,
125143 } ) ;
126144
127145 writeGithubOutput ( args . githubOutput , result ) ;
0 commit comments