Skip to content

Commit 92d56b6

Browse files
committed
Another attempt
1 parent ab14ee4 commit 92d56b6

File tree

1 file changed

+36
-29
lines changed
  • .github/actions/pr-title-labeler

1 file changed

+36
-29
lines changed

.github/actions/pr-title-labeler/index.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,34 @@ const { Octokit } = require('@octokit/rest');
99
const yaml = require('js-yaml');
1010
const fs = require('fs');
1111
const path = require('path');
12-
const { execSync } = require('child_process');
1312

1413
/**
15-
* Get labels that were added by this action using GitHub Actions cache
14+
* Get labels that were added by this action using a simple file-based cache
1615
*/
1716
async function getLabelsAddedByAction(owner, repo, issueNumber) {
1817
try {
19-
const cacheKey = `pr-title-labeler-${owner}-${repo}-${issueNumber}`;
20-
const cachePath = `/tmp/pr-title-labeler-cache-${issueNumber}.json`;
18+
const cacheDir = '/tmp/pr-title-labeler-cache';
19+
const cacheFile = path.join(
20+
cacheDir,
21+
`${owner}-${repo}-${issueNumber}.json`
22+
);
2123

22-
// Try to restore from cache
23-
try {
24-
execSync(`gh cache restore ${cacheKey} --path ${cachePath}`, {
25-
stdio: 'pipe'
26-
});
24+
// Ensure cache directory exists
25+
if (!fs.existsSync(cacheDir)) {
26+
fs.mkdirSync(cacheDir, { recursive: true });
27+
}
2728

28-
if (fs.existsSync(cachePath)) {
29-
const cacheData = JSON.parse(fs.readFileSync(cachePath, 'utf8'));
30-
const labels = new Set(cacheData.labels || []);
31-
console.log(
32-
`💾 Retrieved from cache: [${Array.from(labels).join(', ')}]`
33-
);
34-
return labels;
35-
}
36-
} catch (error) {
37-
// Cache miss or error - this is normal for first run
38-
console.log('💾 No cache found, starting fresh');
29+
// Try to read from cache file
30+
if (fs.existsSync(cacheFile)) {
31+
const cacheData = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
32+
const labels = new Set(cacheData.labels || []);
33+
console.log(
34+
`💾 Retrieved from cache: [${Array.from(labels).join(', ')}]`
35+
);
36+
return labels;
3937
}
4038

39+
console.log('💾 No cache found, starting fresh');
4140
return new Set();
4241
} catch (error) {
4342
console.log('⚠️ Could not retrieve cache:', error.message);
@@ -46,24 +45,32 @@ async function getLabelsAddedByAction(owner, repo, issueNumber) {
4645
}
4746

4847
/**
49-
* Save labels that were added by this action to GitHub Actions cache
48+
* Save labels that were added by this action to file-based cache
5049
*/
5150
async function saveLabelsAddedByAction(owner, repo, issueNumber, labels) {
5251
try {
53-
const cacheKey = `pr-title-labeler-${owner}-${repo}-${issueNumber}`;
54-
const cachePath = `/tmp/pr-title-labeler-cache-${issueNumber}.json`;
52+
const cacheDir = '/tmp/pr-title-labeler-cache';
53+
const cacheFile = path.join(
54+
cacheDir,
55+
`${owner}-${repo}-${issueNumber}.json`
56+
);
57+
58+
// Ensure cache directory exists
59+
if (!fs.existsSync(cacheDir)) {
60+
fs.mkdirSync(cacheDir, { recursive: true });
61+
}
5562

5663
// Create cache data
5764
const cacheData = {
5865
labels: Array.from(labels),
59-
timestamp: new Date().toISOString()
66+
timestamp: new Date().toISOString(),
67+
owner,
68+
repo,
69+
issueNumber
6070
};
6171

62-
// Write to temporary file
63-
fs.writeFileSync(cachePath, JSON.stringify(cacheData, null, 2));
64-
65-
// Save to GitHub Actions cache
66-
execSync(`gh cache save ${cacheKey} ${cachePath}`, { stdio: 'pipe' });
72+
// Write to cache file
73+
fs.writeFileSync(cacheFile, JSON.stringify(cacheData, null, 2));
6774

6875
console.log(`💾 Saved to cache: [${Array.from(labels).join(', ')}]`);
6976
} catch (error) {

0 commit comments

Comments
 (0)