mirror of
https://github.com/Swatinem/rust-cache
synced 2026-04-19 04:20:18 +00:00
Merge d3825ba554 into f51f967e15
This commit is contained in:
commit
05782d4e28
2 changed files with 42 additions and 12 deletions
34
.github/workflows/binstall.yml
vendored
Normal file
34
.github/workflows/binstall.yml
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
name: binstall
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
binstall:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
|
name: Test `cargo binstall` on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
- uses: cargo-bins/cargo-binstall@v1.17.9
|
||||||
|
|
||||||
|
- uses: ./
|
||||||
|
|
||||||
|
- run: cargo binstall -y cargo-deny
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
@ -77,16 +77,16 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
|
||||||
|
|
||||||
export async function getCargoBins(): Promise<Set<string>> {
|
export async function getCargoBins(): Promise<Set<string>> {
|
||||||
const bins = new Set<string>();
|
const bins = new Set<string>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { installs }: { installs: { [key: string]: { bins: Array<string> } } } = JSON.parse(
|
const dir = await fs.promises.opendir(path.join(CARGO_HOME, "bin"));
|
||||||
await fs.promises.readFile(path.join(CARGO_HOME, ".crates2.json"), "utf8"),
|
for await (const dirent of dir) {
|
||||||
);
|
if (dirent.isFile()) {
|
||||||
for (const pkg of Object.values(installs)) {
|
bins.add(dirent.name);
|
||||||
for (const bin of pkg.bins) {
|
|
||||||
bins.add(bin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
return bins;
|
return bins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,15 +97,11 @@ export async function getCargoBins(): Promise<Set<string>> {
|
||||||
* @param oldBins The binaries that existed when the action started.
|
* @param oldBins The binaries that existed when the action started.
|
||||||
*/
|
*/
|
||||||
export async function cleanBin(oldBins: Array<string>) {
|
export async function cleanBin(oldBins: Array<string>) {
|
||||||
const bins = await getCargoBins();
|
const binsToRemove = new Set<string>(oldBins);
|
||||||
|
|
||||||
for (const bin of oldBins) {
|
|
||||||
bins.delete(bin);
|
|
||||||
}
|
|
||||||
|
|
||||||
const dir = await fs.promises.opendir(path.join(CARGO_HOME, "bin"));
|
const dir = await fs.promises.opendir(path.join(CARGO_HOME, "bin"));
|
||||||
for await (const dirent of dir) {
|
for await (const dirent of dir) {
|
||||||
if (dirent.isFile() && !bins.has(dirent.name)) {
|
if (dirent.isFile() && binsToRemove.has(dirent.name)) {
|
||||||
await rm(dir.path, dirent);
|
await rm(dir.path, dirent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue