Skip to content

Commit 3f2513f

Browse files
committed
avoid calling cargo metadata on pre-cleanup
1 parent 19c4658 commit 3f2513f

File tree

6 files changed

+63
-40
lines changed

6 files changed

+63
-40
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.0.2
4+
5+
- Avoid calling `cargo metadata` on pre-cleanup.
6+
37
## 2.0.1
48

59
- Primarily just updating dependencies to fix GitHub deprecation notices.

dist/restore/index.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64476,6 +64476,7 @@ async function getCmdOutput(cmd, args = [], options = {}) {
6447664476
;// CONCATENATED MODULE: ./src/workspace.ts
6447764477

6447864478

64479+
6447964480
const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
6448064481
class Workspace {
6448164482
constructor(root, target) {
@@ -64485,9 +64486,11 @@ class Workspace {
6448564486
async getPackages() {
6448664487
let packages = [];
6448764488
try {
64489+
lib_core.debug(`collecting metadata for "${this.root}"`);
6448864490
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], {
6448964491
cwd: this.root,
6449064492
}));
64493+
lib_core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
6449164494
for (const pkg of meta.packages) {
6449264495
if (pkg.manifest_path.startsWith(this.root)) {
6449364496
continue;
@@ -64840,30 +64843,34 @@ async function cleanGit(packages) {
6484064843
}
6484164844
const ONE_WEEK = 7 * 24 * 3600 * 1000;
6484264845
/**
64843-
* Removes all files or directories in `dirName`, except the ones matching
64844-
* any string in the `keepPrefix` set.
64845-
*
64846-
* The matching strips and trailing `-$hash` suffix.
64846+
* Removes all files or directories in `dirName` matching some criteria.
6484764847
*
6484864848
* When the `checkTimestamp` flag is set, this will also remove anything older
6484964849
* than one week.
64850+
*
64851+
* Otherwise, it will remove everything that does not match any string in the
64852+
* `keepPrefix` set.
64853+
* The matching strips and trailing `-$hash` suffix.
6485064854
*/
6485164855
async function rmExcept(dirName, keepPrefix, checkTimestamp = false) {
6485264856
const dir = await external_fs_default().promises.opendir(dirName);
6485364857
for await (const dirent of dir) {
64858+
if (checkTimestamp) {
64859+
const fileName = external_path_default().join(dir.path, dirent.name);
64860+
const { mtime } = await external_fs_default().promises.stat(fileName);
64861+
const isOutdated = Date.now() - mtime.getTime() > ONE_WEEK;
64862+
if (isOutdated) {
64863+
await rm(dir.path, dirent);
64864+
}
64865+
return;
64866+
}
6485464867
let name = dirent.name;
6485564868
// strip the trailing hash
6485664869
const idx = name.lastIndexOf("-");
6485764870
if (idx !== -1) {
6485864871
name = name.slice(0, idx);
6485964872
}
64860-
let isOutdated = false;
64861-
if (checkTimestamp) {
64862-
const fileName = external_path_default().join(dir.path, dirent.name);
64863-
const { mtime } = await external_fs_default().promises.stat(fileName);
64864-
isOutdated = Date.now() - mtime.getTime() > ONE_WEEK;
64865-
}
64866-
if (!keepPrefix.has(name) || isOutdated) {
64873+
if (!keepPrefix.has(name)) {
6486764874
await rm(dir.path, dirent);
6486864875
}
6486964876
}
@@ -64933,8 +64940,7 @@ async function run() {
6493364940
// pre-clean the target directory on cache mismatch
6493464941
for (const workspace of config.workspaces) {
6493564942
try {
64936-
const packages = await workspace.getPackages();
64937-
await cleanTargetDir(workspace.target, packages, true);
64943+
await cleanTargetDir(workspace.target, [], true);
6493864944
}
6493964945
catch { }
6494064946
}

dist/save/index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64476,6 +64476,7 @@ async function getCmdOutput(cmd, args = [], options = {}) {
6447664476
;// CONCATENATED MODULE: ./src/workspace.ts
6447764477

6447864478

64479+
6447964480
const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
6448064481
class Workspace {
6448164482
constructor(root, target) {
@@ -64485,9 +64486,11 @@ class Workspace {
6448564486
async getPackages() {
6448664487
let packages = [];
6448764488
try {
64489+
core.debug(`collecting metadata for "${this.root}"`);
6448864490
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], {
6448964491
cwd: this.root,
6449064492
}));
64493+
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
6449164494
for (const pkg of meta.packages) {
6449264495
if (pkg.manifest_path.startsWith(this.root)) {
6449364496
continue;
@@ -64840,30 +64843,34 @@ async function cleanGit(packages) {
6484064843
}
6484164844
const ONE_WEEK = 7 * 24 * 3600 * 1000;
6484264845
/**
64843-
* Removes all files or directories in `dirName`, except the ones matching
64844-
* any string in the `keepPrefix` set.
64845-
*
64846-
* The matching strips and trailing `-$hash` suffix.
64846+
* Removes all files or directories in `dirName` matching some criteria.
6484764847
*
6484864848
* When the `checkTimestamp` flag is set, this will also remove anything older
6484964849
* than one week.
64850+
*
64851+
* Otherwise, it will remove everything that does not match any string in the
64852+
* `keepPrefix` set.
64853+
* The matching strips and trailing `-$hash` suffix.
6485064854
*/
6485164855
async function rmExcept(dirName, keepPrefix, checkTimestamp = false) {
6485264856
const dir = await external_fs_default().promises.opendir(dirName);
6485364857
for await (const dirent of dir) {
64858+
if (checkTimestamp) {
64859+
const fileName = external_path_default().join(dir.path, dirent.name);
64860+
const { mtime } = await external_fs_default().promises.stat(fileName);
64861+
const isOutdated = Date.now() - mtime.getTime() > ONE_WEEK;
64862+
if (isOutdated) {
64863+
await rm(dir.path, dirent);
64864+
}
64865+
return;
64866+
}
6485464867
let name = dirent.name;
6485564868
// strip the trailing hash
6485664869
const idx = name.lastIndexOf("-");
6485764870
if (idx !== -1) {
6485864871
name = name.slice(0, idx);
6485964872
}
64860-
let isOutdated = false;
64861-
if (checkTimestamp) {
64862-
const fileName = external_path_default().join(dir.path, dirent.name);
64863-
const { mtime } = await external_fs_default().promises.stat(fileName);
64864-
isOutdated = Date.now() - mtime.getTime() > ONE_WEEK;
64865-
}
64866-
if (!keepPrefix.has(name) || isOutdated) {
64873+
if (!keepPrefix.has(name)) {
6486764874
await rm(dir.path, dirent);
6486864875
}
6486964876
}

src/cleanup.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,29 @@ export async function cleanGit(packages: Packages) {
180180
const ONE_WEEK = 7 * 24 * 3600 * 1000;
181181

182182
/**
183-
* Removes all files or directories in `dirName`, except the ones matching
184-
* any string in the `keepPrefix` set.
185-
*
186-
* The matching strips and trailing `-$hash` suffix.
187-
*
183+
* Removes all files or directories in `dirName` matching some criteria.
184+
*
188185
* When the `checkTimestamp` flag is set, this will also remove anything older
189186
* than one week.
187+
*
188+
* Otherwise, it will remove everything that does not match any string in the
189+
* `keepPrefix` set.
190+
* The matching strips and trailing `-$hash` suffix.
190191
*/
191192
async function rmExcept(dirName: string, keepPrefix: Set<string>, checkTimestamp = false) {
192193
const dir = await fs.promises.opendir(dirName);
193194
for await (const dirent of dir) {
195+
if (checkTimestamp) {
196+
const fileName = path.join(dir.path, dirent.name);
197+
const { mtime } = await fs.promises.stat(fileName);
198+
const isOutdated = Date.now() - mtime.getTime() > ONE_WEEK;
199+
200+
if (isOutdated) {
201+
await rm(dir.path, dirent);
202+
}
203+
return;
204+
}
205+
194206
let name = dirent.name;
195207

196208
// strip the trailing hash
@@ -199,14 +211,7 @@ async function rmExcept(dirName: string, keepPrefix: Set<string>, checkTimestamp
199211
name = name.slice(0, idx);
200212
}
201213

202-
let isOutdated = false;
203-
if (checkTimestamp) {
204-
const fileName = path.join(dir.path, dirent.name);
205-
const { mtime } = await fs.promises.stat(fileName);
206-
isOutdated = Date.now() - mtime.getTime() > ONE_WEEK;
207-
}
208-
209-
if (!keepPrefix.has(name) || isOutdated) {
214+
if (!keepPrefix.has(name)) {
210215
await rm(dir.path, dirent);
211216
}
212217
}

src/restore.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ async function run() {
4343
// pre-clean the target directory on cache mismatch
4444
for (const workspace of config.workspaces) {
4545
try {
46-
const packages = await workspace.getPackages();
47-
48-
await cleanTargetDir(workspace.target, packages, true);
46+
await cleanTargetDir(workspace.target, [], true);
4947
} catch {}
5048
}
5149
}

src/workspace.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as core from "@actions/core";
12
import path from "path";
23

34
import { getCmdOutput } from "./utils";
@@ -10,11 +11,13 @@ export class Workspace {
1011
public async getPackages(): Promise<Packages> {
1112
let packages: Packages = [];
1213
try {
14+
core.debug(`collecting metadata for "${this.root}"`);
1315
const meta: Meta = JSON.parse(
1416
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], {
1517
cwd: this.root,
1618
}),
1719
);
20+
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
1821
for (const pkg of meta.packages) {
1922
if (pkg.manifest_path.startsWith(this.root)) {
2023
continue;

0 commit comments

Comments
 (0)