From d60dbbc7918fb0d293b871d82a00f41d41f07a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Mon, 7 Apr 2025 21:26:26 +0800 Subject: [PATCH] windows: Add `update-workspace-hack.ps1` script (#28219) Release Notes: - N/A --- .github/workflows/ci.yml | 4 ++-- script/update-workspace-hack.ps1 | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 script/update-workspace-hack.ps1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9341ff6144..45dc7c5168 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,13 +131,13 @@ jobs: - name: Check workspace-hack Cargo.toml is up-to-date run: | cargo hakari generate --diff || { - echo "To fix, run script/update-workspace-hack"; + echo "To fix, run script/update-workspace-hack or script/update-workspace-hack.ps1"; false } - name: Check all crates depend on workspace-hack run: | cargo hakari manage-deps --dry-run || { - echo "To fix, run script/update-workspace-hack" + echo "To fix, run script/update-workspace-hack or script/update-workspace-hack.ps1" false } diff --git a/script/update-workspace-hack.ps1 b/script/update-workspace-hack.ps1 new file mode 100644 index 0000000000..0606607249 --- /dev/null +++ b/script/update-workspace-hack.ps1 @@ -0,0 +1,36 @@ +$ErrorActionPreference = "Stop" + +$HAKARI_VERSION = "0.9" + +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location (Split-Path -Parent $scriptPath) + +$hakariInstalled = $false +try { + $versionOutput = cargo hakari --version 2>&1 + if ($versionOutput -match "cargo-hakari $HAKARI_VERSION") { + $hakariInstalled = $true + } +} +catch { + $hakariInstalled = $false +} + +if (-not $hakariInstalled) { + Write-Host "Installing cargo-hakari@^$HAKARI_VERSION..." + cargo install "cargo-hakari@^$HAKARI_VERSION" + if ($LASTEXITCODE -ne 0) { + throw "Failed to install cargo-hakari@^$HAKARI_VERSION" + } +} +else { + Write-Host "cargo-hakari@^$HAKARI_VERSION is already installed." +} + +# update the workspace-hack crate +cargo hakari generate +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +# make sure workspace-hack is added as a dep for all crates in the workspace +cargo hakari manage-deps +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }