Skip to content

Commit 82b1de8

Browse files
committed
fix(get-package-manager): ignore created cache symlink
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 03d95a5 commit 82b1de8

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

actions/get-package-manager/action.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,30 @@ runs:
9999
if (relativeWorkingDirectory.startsWith('../')) {
100100
// Working directory is outside GITHUB_WORKSPACE
101101
// Create a symlink inside GITHUB_WORKSPACE to enable caching
102-
const symlinkName = '.github-actions-cache';
102+
const symlinkName = '.ci-github-nodejs-cache';
103103
const symlinkPath = path.join(process.env.GITHUB_WORKSPACE, symlinkName);
104+
const ensureIgnoreEntry = (filePath, entry) => {
105+
const normalizedEntry = entry.trim();
106+
if (!normalizedEntry) {
107+
return;
108+
}
109+
110+
if (fs.existsSync(filePath)) {
111+
const contents = fs.readFileSync(filePath, 'utf8');
112+
const lines = contents.split(/\r?\n/);
113+
114+
if (lines.includes(normalizedEntry)) {
115+
return;
116+
}
117+
118+
const needsNewline = contents.length > 0 && !contents.endsWith('\n');
119+
const prefix = needsNewline ? '\n' : '';
120+
fs.appendFileSync(filePath, `${prefix}${normalizedEntry}\n`);
121+
return;
122+
}
123+
124+
fs.writeFileSync(filePath, `${normalizedEntry}\n`);
125+
};
104126
105127
try {
106128
// Remove existing symlink if it exists
@@ -111,6 +133,12 @@ runs:
111133
// Create symlink pointing to the working directory
112134
fs.symlinkSync(workingDirectory, symlinkPath, 'dir');
113135
core.info(`Created symlink at "${symlinkPath}" pointing to "${workingDirectory}" to enable caching.`);
136+
137+
const gitignorePath = path.join(process.env.GITHUB_WORKSPACE, '.gitignore');
138+
const dockerignorePath = path.join(process.env.GITHUB_WORKSPACE, '.dockerignore');
139+
ensureIgnoreEntry(gitignorePath, symlinkName);
140+
ensureIgnoreEntry(dockerignorePath, symlinkName);
141+
114142
cacheDependencyPathPrefix = symlinkName;
115143
} catch (error) {
116144
core.warning(`Failed to create symlink for caching: ${error.message}. Caching will be disabled.`);

0 commit comments

Comments
 (0)