binary-collections 2.0.7 → 2.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dir-tree.cmd +7 -0
- package/bin/git-diff +4 -0
- package/bin/git-diff.cmd +5 -2
- package/bin/{git-fix-encoding → git-fix} +1 -4
- package/bin/git-fix.cmd +7 -0
- package/bin/nodekill +0 -0
- package/bin/nodekill.ps1 +0 -0
- package/bin/{submodule → submodule.txt} +0 -0
- package/lib/binary-collections-config.cjs +14 -0
- package/lib/binary-collections-config.d.mts +18 -0
- package/lib/binary-collections-config.d.ts +16 -0
- package/lib/binary-collections-config.js +39 -0
- package/lib/binary-collections-config.mjs +6 -0
- package/lib/binary-collections.cjs +123 -0
- package/lib/binary-collections.d.cts +2 -0
- package/lib/binary-collections.d.mts +137 -0
- package/lib/binary-collections.d.ts +137 -0
- package/lib/binary-collections.mjs +300 -0
- package/lib/changelog.cjs +328 -0
- package/lib/changelog.d.mts +2 -0
- package/lib/changelog.d.ts +1 -0
- package/lib/changelog.js +226 -0
- package/lib/changelog.mjs +199 -0
- package/lib/chunk-4BYBVEYC.mjs +30 -0
- package/lib/{chunk-FB6YIQYR.mjs → chunk-AASHBCRW.mjs} +17 -2
- package/lib/chunk-APBWENF6.mjs +135 -0
- package/lib/{chunk-4LEXWIIF.mjs → chunk-DPKAJKFO.mjs} +2 -4
- package/lib/chunk-EGSSKVDH.mjs +66 -0
- package/lib/{chunk-3LOB2P54.mjs → chunk-G3THLIDT.mjs} +3 -5
- package/lib/chunk-JGR2NW6D.mjs +187 -0
- package/lib/chunk-ONIBBBQ3.mjs +108 -0
- package/lib/chunk-SH3L6HHV.mjs +27 -0
- package/lib/chunk-VVEZVNIV.mjs +81 -0
- package/lib/{chunk-JL32QDSH.mjs → chunk-W3ENOM53.mjs} +2 -4
- package/lib/chunk-YV7DO3YV.mjs +48 -0
- package/lib/{chunk-BSD5CIRU.mjs → chunk-YX5U7XDR.mjs} +11 -5
- package/lib/chunk-ZYAQRPUL.mjs +28 -0
- package/lib/clean-github-actions-caches.cjs +162 -0
- package/lib/clean-github-actions-caches.d.cts +1 -0
- package/lib/clean-github-actions-caches.d.mts +169 -0
- package/lib/clean-github-actions-caches.d.ts +169 -0
- package/lib/clean-github-actions-caches.mjs +132 -0
- package/lib/del-gradle.cjs +87 -3
- package/lib/del-gradle.js +1 -1
- package/lib/del-gradle.mjs +4 -6
- package/lib/del-node-modules.cjs +86 -2
- package/lib/del-node-modules.mjs +3 -5
- package/lib/del-ps.cjs +89 -5
- package/lib/del-ps.js +2 -2
- package/lib/del-ps.mjs +6 -8
- package/lib/del-yarn-caches.cjs +86 -2
- package/lib/del-yarn-caches.mjs +3 -5
- package/lib/find-node-modules-cli.cjs +8 -0
- package/lib/find-node-modules-cli.mjs +2 -3
- package/lib/find-node-modules.cjs +8 -0
- package/lib/find-node-modules.d.mts +3 -0
- package/lib/find-node-modules.d.ts +3 -0
- package/lib/find-node-modules.js +12 -0
- package/lib/find-node-modules.mjs +2 -3
- package/lib/git/gitattributes.cjs +171 -0
- package/lib/git/gitattributes.d.mts +35 -0
- package/lib/git/gitattributes.d.ts +33 -0
- package/lib/git/gitattributes.js +223 -0
- package/lib/git/gitattributes.mjs +6 -0
- package/lib/git/line-endings.cjs +74 -0
- package/lib/git/line-endings.d.cts +7 -0
- package/lib/git/line-endings.d.mts +83 -0
- package/lib/git/line-endings.d.ts +83 -0
- package/lib/git/line-endings.mjs +8 -0
- package/lib/git/normalize.cjs +42 -0
- package/lib/git/normalize.d.cts +6 -0
- package/lib/git/normalize.d.mts +43 -0
- package/lib/git/normalize.d.ts +43 -0
- package/lib/git/normalize.mjs +6 -0
- package/lib/git/permissions.cjs +15 -0
- package/lib/git/permissions.d.cts +6 -0
- package/lib/git/permissions.d.mts +17 -0
- package/lib/git/permissions.d.ts +17 -0
- package/lib/git/permissions.mjs +7 -0
- package/lib/git/pull-strategy.cjs +13 -0
- package/lib/git/pull-strategy.d.cts +5 -0
- package/lib/git/pull-strategy.d.mts +15 -0
- package/lib/git/pull-strategy.d.ts +15 -0
- package/lib/git/pull-strategy.mjs +7 -0
- package/lib/git/user-config.cjs +100 -0
- package/lib/git/user-config.d.cts +10 -0
- package/lib/git/user-config.d.mts +105 -0
- package/lib/git/user-config.d.ts +105 -0
- package/lib/git/user-config.mjs +8 -0
- package/lib/git/utils.cjs +70 -0
- package/lib/git/utils.d.cts +20 -0
- package/lib/git/utils.d.mts +69 -0
- package/lib/git/utils.d.ts +69 -0
- package/lib/git/utils.mjs +6 -0
- package/lib/git-diff.cjs +23 -24
- package/lib/git-diff.d.mts +25 -28
- package/lib/git-diff.d.ts +25 -28
- package/lib/git-diff.mjs +32 -27
- package/lib/git-fix.cjs +129 -0
- package/lib/git-fix.d.cts +2 -0
- package/lib/git-fix.d.mts +141 -0
- package/lib/git-fix.d.ts +141 -0
- package/lib/git-fix.mjs +151 -0
- package/lib/git-purge.cjs +86 -2
- package/lib/git-purge.mjs +3 -5
- package/lib/index.cjs +8 -0
- package/lib/index.mjs +3 -5
- package/lib/npm-run-series.cjs +140 -1
- package/lib/npm-run-series.js +2 -1
- package/lib/npm-run-series.mjs +7 -5
- package/lib/package-resolutions-updater.cjs +447 -0
- package/lib/package-resolutions-updater.d.mts +1 -0
- package/lib/package-resolutions-updater.d.ts +352 -0
- package/lib/package-resolutions-updater.mjs +339 -0
- package/lib/print-directory-tree.cjs +241 -0
- package/lib/print-directory-tree.d.cts +1 -0
- package/lib/print-directory-tree.d.mts +234 -0
- package/lib/print-directory-tree.d.ts +234 -0
- package/lib/print-directory-tree.mjs +182 -0
- package/lib/ps/connected-domain.mjs +2 -3
- package/lib/ps/index.cjs +3 -3
- package/lib/ps/index.d.mjs +1 -2
- package/lib/ps/index.js +6 -3
- package/lib/ps/index.mjs +9 -11
- package/lib/ps/isWin.mjs +2 -3
- package/lib/ps/table-parser.mjs +3 -4
- package/lib/submodule-install.cjs +18 -35
- package/lib/submodule-install.d.mts +17 -37
- package/lib/submodule-install.d.ts +17 -37
- package/lib/submodule-install.mjs +21 -29
- package/lib/utils.cjs +86 -2
- package/lib/utils.d.mts +29 -9
- package/lib/utils.d.ts +28 -8
- package/lib/utils.js +139 -8
- package/lib/utils.mjs +2 -3
- package/lib/yarn-reinstall.cjs +9 -7
- package/lib/yarn-reinstall.d.mts +12 -8
- package/lib/yarn-reinstall.d.ts +12 -8
- package/lib/yarn-reinstall.mjs +14 -10
- package/package.json +109 -80
- package/readme.md +74 -11
- package/src/package-resolutions-updater.mjs +350 -0
- package/src/print-directory-tree.cjs +234 -0
- package/src/ps/index.js +4 -3
- package/src/yarn-reinstall.cjs +49 -0
- package/test-project/package.json +16 -0
- package/tmp/test-repo/package.json +7 -0
- package/bin/git-fix-encoding.cmd +0 -6
- package/lib/chunk-OKYLF2MU.mjs +0 -53
- package/lib/chunk-VXZQNLPU.mjs +0 -23
- package/lib/package-resolutions.cjs +0 -28
- package/lib/package-resolutions.d.mts +0 -25
- package/lib/package-resolutions.d.ts +0 -25
- package/lib/package-resolutions.mjs +0 -31
- /package/bin/{submodule-install → submodule-install.txt} +0 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const axios = require("axios");
|
|
12
|
+
const { parseGitRemotes } = require("./utils");
|
|
13
|
+
const path = require("upath");
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const projectDir = process.cwd();
|
|
16
|
+
const envPath = path.join(projectDir, ".env");
|
|
17
|
+
// Load the .env file using dotenv
|
|
18
|
+
if (fs.existsSync(envPath)) {
|
|
19
|
+
require("dotenv").config({ path: envPath });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.warn(`.env file not found at ${envPath}`);
|
|
23
|
+
}
|
|
24
|
+
// delete caches leaving single last cache based on creation date
|
|
25
|
+
const ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
|
|
26
|
+
if (!ACCESS_TOKEN) {
|
|
27
|
+
throw new Error("Access token is not provided. Please set ACCESS_TOKEN or GITHUB_TOKEN in your environment variables.");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Deletes a GitHub Actions cache.
|
|
31
|
+
* @param {string} GH_REPO - The GitHub repository in the format "owner/repo".
|
|
32
|
+
* @param {string} cacheId - The ID of the cache to delete.
|
|
33
|
+
* @returns {Promise} - A promise that resolves on success and rejects on error.
|
|
34
|
+
*/
|
|
35
|
+
function deleteGitHubActionsCache(GH_REPO, cacheId) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches/${cacheId}`;
|
|
38
|
+
const token = ACCESS_TOKEN;
|
|
39
|
+
if (!token) {
|
|
40
|
+
return reject(new Error("Access token is not provided"));
|
|
41
|
+
}
|
|
42
|
+
axios
|
|
43
|
+
.delete(url, {
|
|
44
|
+
headers: {
|
|
45
|
+
Authorization: `token ${token}`,
|
|
46
|
+
Accept: "application/vnd.github.v3+json"
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
.then((response) => {
|
|
50
|
+
console.log(`Cache (${cacheId}) deleted successfully`, response.data);
|
|
51
|
+
resolve(response.data); // Resolve with the response data
|
|
52
|
+
})
|
|
53
|
+
.catch((error) => {
|
|
54
|
+
var _a;
|
|
55
|
+
console.error("Error deleting cache:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message || "Unknown error");
|
|
56
|
+
reject(error); // Reject with the error
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* list github actions caches
|
|
62
|
+
* @param {string} GH_REPO
|
|
63
|
+
* @returns {Promise<Record<string, Record<string, any>[]>>}
|
|
64
|
+
*/
|
|
65
|
+
function get_caches(GH_REPO) {
|
|
66
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches`;
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
axios
|
|
69
|
+
.get(url, {
|
|
70
|
+
headers: {
|
|
71
|
+
Accept: "application/vnd.github.v3+json",
|
|
72
|
+
Authorization: `token ${ACCESS_TOKEN}`
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
.then((response) => {
|
|
76
|
+
/**
|
|
77
|
+
* @type {Record<string, any>[]}
|
|
78
|
+
*/
|
|
79
|
+
const data = response.data.actions_caches;
|
|
80
|
+
// resolve(response.data);
|
|
81
|
+
/**
|
|
82
|
+
* extract the prefix from the key
|
|
83
|
+
* @param {string} key
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
const getPrefix = (key) => {
|
|
87
|
+
const split = key.split(/[-_]/);
|
|
88
|
+
if (split.length == 3) {
|
|
89
|
+
return `${split[0]}-${split[1]}`;
|
|
90
|
+
}
|
|
91
|
+
else if (split.length > 3) {
|
|
92
|
+
return `${split[0]}-${split[1]}-${split[2]}`;
|
|
93
|
+
}
|
|
94
|
+
return split[0];
|
|
95
|
+
};
|
|
96
|
+
// Group by prefix
|
|
97
|
+
const grouped = data.reduce(
|
|
98
|
+
/**
|
|
99
|
+
* @param {Record<string, Record<string, any>[]>} acc
|
|
100
|
+
* @param {Record<string, any>} item
|
|
101
|
+
* @returns {Record<string, Record<string, any>[]>}
|
|
102
|
+
*/
|
|
103
|
+
(acc, item) => {
|
|
104
|
+
const prefix = getPrefix(item.key);
|
|
105
|
+
if (!acc[prefix]) {
|
|
106
|
+
acc[prefix] = [];
|
|
107
|
+
}
|
|
108
|
+
acc[prefix].push(item);
|
|
109
|
+
return acc;
|
|
110
|
+
}, {});
|
|
111
|
+
// Convert the grouped object into an array of arrays
|
|
112
|
+
// const result = Object.values(grouped);
|
|
113
|
+
resolve(grouped);
|
|
114
|
+
})
|
|
115
|
+
.catch((error) => {
|
|
116
|
+
console.error("Error fetching data:", error);
|
|
117
|
+
reject(error); // Reject the promise with the error
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Deletes old GitHub Actions caches for the current repository (origin remote),
|
|
123
|
+
* keeping only the most recent cache for each prefix (based on creation date).
|
|
124
|
+
* Retrieves caches, groups by prefix, sorts by creation date, and deletes all but the latest.
|
|
125
|
+
*/
|
|
126
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
try {
|
|
128
|
+
const remotes = yield parseGitRemotes();
|
|
129
|
+
const GH_REPO = remotes.origin;
|
|
130
|
+
const caches = yield get_caches(GH_REPO);
|
|
131
|
+
for (const key in caches) {
|
|
132
|
+
if (Object.hasOwnProperty.call(caches, key)) {
|
|
133
|
+
const items = caches[key]
|
|
134
|
+
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))
|
|
135
|
+
.map((item) => (Object.assign(Object.assign({}, item), { human_readable_date: new Date(item.created_at).toLocaleString() })));
|
|
136
|
+
if (items.length > 1) {
|
|
137
|
+
const ids = items.map((o) => o.id);
|
|
138
|
+
ids.shift(); // keep the most recent cache
|
|
139
|
+
if (ids.length > 0) {
|
|
140
|
+
for (const id of ids) {
|
|
141
|
+
try {
|
|
142
|
+
yield deleteGitHubActionsCache(GH_REPO, id);
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
console.error(`Error deleting cache ${id}:`, err);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.log(`cache prefix ${key} no cache left`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
console.log(`cache prefix ${key} only have 1 cache`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (e) {
|
|
160
|
+
console.error(`Error: ${e}`);
|
|
161
|
+
}
|
|
162
|
+
}))();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
const { parseGitRemotes } = require("./utils");
|
|
3
|
+
const path = require("upath");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const projectDir = process.cwd();
|
|
6
|
+
const envPath = path.join(projectDir, ".env");
|
|
7
|
+
|
|
8
|
+
// Load the .env file using dotenv
|
|
9
|
+
if (fs.existsSync(envPath)) {
|
|
10
|
+
require("dotenv").config({ path: envPath });
|
|
11
|
+
} else {
|
|
12
|
+
console.warn(`.env file not found at ${envPath}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// delete caches leaving single last cache based on creation date
|
|
16
|
+
|
|
17
|
+
const ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
|
|
18
|
+
|
|
19
|
+
if (!ACCESS_TOKEN) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
"Access token is not provided. Please set ACCESS_TOKEN or GITHUB_TOKEN in your environment variables."
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Deletes a GitHub Actions cache.
|
|
27
|
+
* @param {string} GH_REPO - The GitHub repository in the format "owner/repo".
|
|
28
|
+
* @param {string} cacheId - The ID of the cache to delete.
|
|
29
|
+
* @returns {Promise} - A promise that resolves on success and rejects on error.
|
|
30
|
+
*/
|
|
31
|
+
function deleteGitHubActionsCache(GH_REPO, cacheId) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches/${cacheId}`;
|
|
34
|
+
const token = ACCESS_TOKEN;
|
|
35
|
+
|
|
36
|
+
if (!token) {
|
|
37
|
+
return reject(new Error("Access token is not provided"));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
axios
|
|
41
|
+
.delete(url, {
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `token ${token}`,
|
|
44
|
+
Accept: "application/vnd.github.v3+json"
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
.then((response) => {
|
|
48
|
+
console.log(`Cache (${cacheId}) deleted successfully`, response.data);
|
|
49
|
+
resolve(response.data); // Resolve with the response data
|
|
50
|
+
})
|
|
51
|
+
.catch((error) => {
|
|
52
|
+
console.error("Error deleting cache:", error.response?.data || error.message || "Unknown error");
|
|
53
|
+
reject(error); // Reject with the error
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* list github actions caches
|
|
60
|
+
* @param {string} GH_REPO
|
|
61
|
+
* @returns {Promise<Record<string, Record<string, any>[]>>}
|
|
62
|
+
*/
|
|
63
|
+
function get_caches(GH_REPO) {
|
|
64
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches`;
|
|
65
|
+
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
axios
|
|
68
|
+
.get(url, {
|
|
69
|
+
headers: {
|
|
70
|
+
Accept: "application/vnd.github.v3+json",
|
|
71
|
+
Authorization: `token ${ACCESS_TOKEN}`
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.then((response) => {
|
|
75
|
+
/**
|
|
76
|
+
* @type {Record<string, any>[]}
|
|
77
|
+
*/
|
|
78
|
+
const data = response.data.actions_caches;
|
|
79
|
+
// resolve(response.data);
|
|
80
|
+
/**
|
|
81
|
+
* extract the prefix from the key
|
|
82
|
+
* @param {string} key
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
const getPrefix = (key) => {
|
|
86
|
+
const split = key.split(/[-_]/);
|
|
87
|
+
if (split.length == 3) {
|
|
88
|
+
return `${split[0]}-${split[1]}`;
|
|
89
|
+
} else if (split.length > 3) {
|
|
90
|
+
return `${split[0]}-${split[1]}-${split[2]}`;
|
|
91
|
+
}
|
|
92
|
+
return split[0];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Group by prefix
|
|
96
|
+
const grouped = data.reduce(
|
|
97
|
+
/**
|
|
98
|
+
* @param {Record<string, Record<string, any>[]>} acc
|
|
99
|
+
* @param {Record<string, any>} item
|
|
100
|
+
* @returns {Record<string, Record<string, any>[]>}
|
|
101
|
+
*/
|
|
102
|
+
(acc, item) => {
|
|
103
|
+
const prefix = getPrefix(item.key);
|
|
104
|
+
|
|
105
|
+
if (!acc[prefix]) {
|
|
106
|
+
acc[prefix] = [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
acc[prefix].push(item);
|
|
110
|
+
|
|
111
|
+
return acc;
|
|
112
|
+
},
|
|
113
|
+
{}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Convert the grouped object into an array of arrays
|
|
117
|
+
// const result = Object.values(grouped);
|
|
118
|
+
resolve(grouped);
|
|
119
|
+
})
|
|
120
|
+
.catch((error) => {
|
|
121
|
+
console.error("Error fetching data:", error);
|
|
122
|
+
reject(error); // Reject the promise with the error
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Deletes old GitHub Actions caches for the current repository (origin remote),
|
|
129
|
+
* keeping only the most recent cache for each prefix (based on creation date).
|
|
130
|
+
* Retrieves caches, groups by prefix, sorts by creation date, and deletes all but the latest.
|
|
131
|
+
*/
|
|
132
|
+
(async () => {
|
|
133
|
+
try {
|
|
134
|
+
const remotes = await parseGitRemotes();
|
|
135
|
+
const GH_REPO = remotes.origin;
|
|
136
|
+
const caches = await get_caches(GH_REPO);
|
|
137
|
+
|
|
138
|
+
for (const key in caches) {
|
|
139
|
+
if (Object.hasOwnProperty.call(caches, key)) {
|
|
140
|
+
const items = caches[key]
|
|
141
|
+
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))
|
|
142
|
+
.map((item) => ({
|
|
143
|
+
...item,
|
|
144
|
+
human_readable_date: new Date(item.created_at).toLocaleString()
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
if (items.length > 1) {
|
|
148
|
+
const ids = items.map((o) => o.id);
|
|
149
|
+
ids.shift(); // keep the most recent cache
|
|
150
|
+
if (ids.length > 0) {
|
|
151
|
+
for (const id of ids) {
|
|
152
|
+
try {
|
|
153
|
+
await deleteGitHubActionsCache(GH_REPO, id);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
console.error(`Error deleting cache ${id}:`, err);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
console.log(`cache prefix ${key} no cache left`);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
console.log(`cache prefix ${key} only have 1 cache`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.error(`Error: ${e}`);
|
|
168
|
+
}
|
|
169
|
+
})();
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
const { parseGitRemotes } = require("./utils");
|
|
3
|
+
const path = require("upath");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const projectDir = process.cwd();
|
|
6
|
+
const envPath = path.join(projectDir, ".env");
|
|
7
|
+
|
|
8
|
+
// Load the .env file using dotenv
|
|
9
|
+
if (fs.existsSync(envPath)) {
|
|
10
|
+
require("dotenv").config({ path: envPath });
|
|
11
|
+
} else {
|
|
12
|
+
console.warn(`.env file not found at ${envPath}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// delete caches leaving single last cache based on creation date
|
|
16
|
+
|
|
17
|
+
const ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
|
|
18
|
+
|
|
19
|
+
if (!ACCESS_TOKEN) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
"Access token is not provided. Please set ACCESS_TOKEN or GITHUB_TOKEN in your environment variables."
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Deletes a GitHub Actions cache.
|
|
27
|
+
* @param {string} GH_REPO - The GitHub repository in the format "owner/repo".
|
|
28
|
+
* @param {string} cacheId - The ID of the cache to delete.
|
|
29
|
+
* @returns {Promise} - A promise that resolves on success and rejects on error.
|
|
30
|
+
*/
|
|
31
|
+
function deleteGitHubActionsCache(GH_REPO, cacheId) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches/${cacheId}`;
|
|
34
|
+
const token = ACCESS_TOKEN;
|
|
35
|
+
|
|
36
|
+
if (!token) {
|
|
37
|
+
return reject(new Error("Access token is not provided"));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
axios
|
|
41
|
+
.delete(url, {
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `token ${token}`,
|
|
44
|
+
Accept: "application/vnd.github.v3+json"
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
.then((response) => {
|
|
48
|
+
console.log(`Cache (${cacheId}) deleted successfully`, response.data);
|
|
49
|
+
resolve(response.data); // Resolve with the response data
|
|
50
|
+
})
|
|
51
|
+
.catch((error) => {
|
|
52
|
+
console.error("Error deleting cache:", error.response?.data || error.message || "Unknown error");
|
|
53
|
+
reject(error); // Reject with the error
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* list github actions caches
|
|
60
|
+
* @param {string} GH_REPO
|
|
61
|
+
* @returns {Promise<Record<string, Record<string, any>[]>>}
|
|
62
|
+
*/
|
|
63
|
+
function get_caches(GH_REPO) {
|
|
64
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches`;
|
|
65
|
+
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
axios
|
|
68
|
+
.get(url, {
|
|
69
|
+
headers: {
|
|
70
|
+
Accept: "application/vnd.github.v3+json",
|
|
71
|
+
Authorization: `token ${ACCESS_TOKEN}`
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.then((response) => {
|
|
75
|
+
/**
|
|
76
|
+
* @type {Record<string, any>[]}
|
|
77
|
+
*/
|
|
78
|
+
const data = response.data.actions_caches;
|
|
79
|
+
// resolve(response.data);
|
|
80
|
+
/**
|
|
81
|
+
* extract the prefix from the key
|
|
82
|
+
* @param {string} key
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
const getPrefix = (key) => {
|
|
86
|
+
const split = key.split(/[-_]/);
|
|
87
|
+
if (split.length == 3) {
|
|
88
|
+
return `${split[0]}-${split[1]}`;
|
|
89
|
+
} else if (split.length > 3) {
|
|
90
|
+
return `${split[0]}-${split[1]}-${split[2]}`;
|
|
91
|
+
}
|
|
92
|
+
return split[0];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Group by prefix
|
|
96
|
+
const grouped = data.reduce(
|
|
97
|
+
/**
|
|
98
|
+
* @param {Record<string, Record<string, any>[]>} acc
|
|
99
|
+
* @param {Record<string, any>} item
|
|
100
|
+
* @returns {Record<string, Record<string, any>[]>}
|
|
101
|
+
*/
|
|
102
|
+
(acc, item) => {
|
|
103
|
+
const prefix = getPrefix(item.key);
|
|
104
|
+
|
|
105
|
+
if (!acc[prefix]) {
|
|
106
|
+
acc[prefix] = [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
acc[prefix].push(item);
|
|
110
|
+
|
|
111
|
+
return acc;
|
|
112
|
+
},
|
|
113
|
+
{}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Convert the grouped object into an array of arrays
|
|
117
|
+
// const result = Object.values(grouped);
|
|
118
|
+
resolve(grouped);
|
|
119
|
+
})
|
|
120
|
+
.catch((error) => {
|
|
121
|
+
console.error("Error fetching data:", error);
|
|
122
|
+
reject(error); // Reject the promise with the error
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Deletes old GitHub Actions caches for the current repository (origin remote),
|
|
129
|
+
* keeping only the most recent cache for each prefix (based on creation date).
|
|
130
|
+
* Retrieves caches, groups by prefix, sorts by creation date, and deletes all but the latest.
|
|
131
|
+
*/
|
|
132
|
+
(async () => {
|
|
133
|
+
try {
|
|
134
|
+
const remotes = await parseGitRemotes();
|
|
135
|
+
const GH_REPO = remotes.origin;
|
|
136
|
+
const caches = await get_caches(GH_REPO);
|
|
137
|
+
|
|
138
|
+
for (const key in caches) {
|
|
139
|
+
if (Object.hasOwnProperty.call(caches, key)) {
|
|
140
|
+
const items = caches[key]
|
|
141
|
+
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))
|
|
142
|
+
.map((item) => ({
|
|
143
|
+
...item,
|
|
144
|
+
human_readable_date: new Date(item.created_at).toLocaleString()
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
if (items.length > 1) {
|
|
148
|
+
const ids = items.map((o) => o.id);
|
|
149
|
+
ids.shift(); // keep the most recent cache
|
|
150
|
+
if (ids.length > 0) {
|
|
151
|
+
for (const id of ids) {
|
|
152
|
+
try {
|
|
153
|
+
await deleteGitHubActionsCache(GH_REPO, id);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
console.error(`Error deleting cache ${id}:`, err);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
console.log(`cache prefix ${key} no cache left`);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
console.log(`cache prefix ${key} only have 1 cache`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.error(`Error: ${e}`);
|
|
168
|
+
}
|
|
169
|
+
})();
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
require_utils
|
|
4
|
+
} from "./chunk-APBWENF6.mjs";
|
|
5
|
+
import {
|
|
6
|
+
__commonJS,
|
|
7
|
+
__require,
|
|
8
|
+
init_esm_shims
|
|
9
|
+
} from "./chunk-AASHBCRW.mjs";
|
|
10
|
+
|
|
11
|
+
// src/clean-github-actions-caches.cjs
|
|
12
|
+
var require_clean_github_actions_caches = __commonJS({
|
|
13
|
+
"src/clean-github-actions-caches.cjs"() {
|
|
14
|
+
init_esm_shims();
|
|
15
|
+
var axios = __require("axios");
|
|
16
|
+
var { parseGitRemotes } = require_utils();
|
|
17
|
+
var path = __require("upath");
|
|
18
|
+
var fs = __require("fs");
|
|
19
|
+
var projectDir = process.cwd();
|
|
20
|
+
var envPath = path.join(projectDir, ".env");
|
|
21
|
+
if (fs.existsSync(envPath)) {
|
|
22
|
+
__require("dotenv").config({ path: envPath });
|
|
23
|
+
} else {
|
|
24
|
+
console.warn(`.env file not found at ${envPath}`);
|
|
25
|
+
}
|
|
26
|
+
var ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
|
|
27
|
+
if (!ACCESS_TOKEN) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"Access token is not provided. Please set ACCESS_TOKEN or GITHUB_TOKEN in your environment variables."
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function deleteGitHubActionsCache(GH_REPO, cacheId) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches/${cacheId}`;
|
|
35
|
+
const token = ACCESS_TOKEN;
|
|
36
|
+
if (!token) {
|
|
37
|
+
return reject(new Error("Access token is not provided"));
|
|
38
|
+
}
|
|
39
|
+
axios.delete(url, {
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `token ${token}`,
|
|
42
|
+
Accept: "application/vnd.github.v3+json"
|
|
43
|
+
}
|
|
44
|
+
}).then((response) => {
|
|
45
|
+
console.log(`Cache (${cacheId}) deleted successfully`, response.data);
|
|
46
|
+
resolve(response.data);
|
|
47
|
+
}).catch((error) => {
|
|
48
|
+
var _a;
|
|
49
|
+
console.error("Error deleting cache:", ((_a = error.response) == null ? void 0 : _a.data) || error.message || "Unknown error");
|
|
50
|
+
reject(error);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function get_caches(GH_REPO) {
|
|
55
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches`;
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
axios.get(url, {
|
|
58
|
+
headers: {
|
|
59
|
+
Accept: "application/vnd.github.v3+json",
|
|
60
|
+
Authorization: `token ${ACCESS_TOKEN}`
|
|
61
|
+
}
|
|
62
|
+
}).then((response) => {
|
|
63
|
+
const data = response.data.actions_caches;
|
|
64
|
+
const getPrefix = (key) => {
|
|
65
|
+
const split = key.split(/[-_]/);
|
|
66
|
+
if (split.length == 3) {
|
|
67
|
+
return `${split[0]}-${split[1]}`;
|
|
68
|
+
} else if (split.length > 3) {
|
|
69
|
+
return `${split[0]}-${split[1]}-${split[2]}`;
|
|
70
|
+
}
|
|
71
|
+
return split[0];
|
|
72
|
+
};
|
|
73
|
+
const grouped = data.reduce(
|
|
74
|
+
/**
|
|
75
|
+
* @param {Record<string, Record<string, any>[]>} acc
|
|
76
|
+
* @param {Record<string, any>} item
|
|
77
|
+
* @returns {Record<string, Record<string, any>[]>}
|
|
78
|
+
*/
|
|
79
|
+
(acc, item) => {
|
|
80
|
+
const prefix = getPrefix(item.key);
|
|
81
|
+
if (!acc[prefix]) {
|
|
82
|
+
acc[prefix] = [];
|
|
83
|
+
}
|
|
84
|
+
acc[prefix].push(item);
|
|
85
|
+
return acc;
|
|
86
|
+
},
|
|
87
|
+
{}
|
|
88
|
+
);
|
|
89
|
+
resolve(grouped);
|
|
90
|
+
}).catch((error) => {
|
|
91
|
+
console.error("Error fetching data:", error);
|
|
92
|
+
reject(error);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
(async () => {
|
|
97
|
+
try {
|
|
98
|
+
const remotes = await parseGitRemotes();
|
|
99
|
+
const GH_REPO = remotes.origin;
|
|
100
|
+
const caches = await get_caches(GH_REPO);
|
|
101
|
+
for (const key in caches) {
|
|
102
|
+
if (Object.hasOwnProperty.call(caches, key)) {
|
|
103
|
+
const items = caches[key].sort((a, b) => new Date(b.created_at) - new Date(a.created_at)).map((item) => ({
|
|
104
|
+
...item,
|
|
105
|
+
human_readable_date: new Date(item.created_at).toLocaleString()
|
|
106
|
+
}));
|
|
107
|
+
if (items.length > 1) {
|
|
108
|
+
const ids = items.map((o) => o.id);
|
|
109
|
+
ids.shift();
|
|
110
|
+
if (ids.length > 0) {
|
|
111
|
+
for (const id of ids) {
|
|
112
|
+
try {
|
|
113
|
+
await deleteGitHubActionsCache(GH_REPO, id);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error(`Error deleting cache ${id}:`, err);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
console.log(`cache prefix ${key} no cache left`);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
console.log(`cache prefix ${key} only have 1 cache`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.error(`Error: ${e}`);
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
export default require_clean_github_actions_caches();
|