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