From e70c997bc0cc842123d569778d08d2acf51b7ce9 Mon Sep 17 00:00:00 2001 From: PerfectPan Date: Mon, 4 May 2026 17:18:30 +0800 Subject: [PATCH] ci: verify release asset contract --- .github/workflows/ci.yml | 2 ++ .github/workflows/release.yml | 5 ++-- install.sh | 16 +++++++++++-- scripts/check-release-prep.sh | 43 +++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100755 scripts/check-release-prep.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fba3fe9..8403a17 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + - run: sh -n install.sh scripts/*.sh + - run: ./scripts/check-release-prep.sh - run: cargo fmt --check - run: cargo clippy --all-targets -- -D warnings - run: cargo test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4b0b346..891d599 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,7 +47,7 @@ jobs: cp "target/${{ matrix.target }}/release/ocvm" "dist/${name}/" cp README.md LICENSE CHANGELOG.md "dist/${name}/" tar -C dist -czf "dist/${name}.tar.gz" "${name}" - shasum -a 256 "dist/${name}.tar.gz" > "dist/${name}.tar.gz.sha256" + (cd dist && shasum -a 256 "${name}.tar.gz" > "${name}.tar.gz.sha256") - name: Package Windows artifact if: matrix.archive == 'zip' @@ -59,7 +59,7 @@ jobs: Copy-Item README.md,LICENSE,CHANGELOG.md "dist/$name/" Compress-Archive -Path "dist/$name/*" -DestinationPath "dist/$name.zip" $hash = (Get-FileHash "dist/$name.zip" -Algorithm SHA256).Hash.ToLower() - "$hash dist/$name.zip" | Out-File -FilePath "dist/$name.zip.sha256" -Encoding ascii + "$hash $name.zip" | Out-File -FilePath "dist/$name.zip.sha256" -Encoding ascii - uses: actions/upload-artifact@v4 with: @@ -84,4 +84,3 @@ jobs: with: files: release-assets/* generate_release_notes: true - diff --git a/install.sh b/install.sh index ae6663f..12617ef 100755 --- a/install.sh +++ b/install.sh @@ -15,8 +15,8 @@ need() { need curl need tar -system="$(uname -s)" -machine="$(uname -m)" +system="${OCVM_TEST_UNAME_S:-$(uname -s)}" +machine="${OCVM_TEST_UNAME_M:-$(uname -m)}" case "$system" in Darwin) os="apple-darwin" ;; @@ -39,6 +39,18 @@ esac target="${arch}-${os}" asset="ocvm-${target}.tar.gz" + +if [ "${OCVM_INSTALL_DRY_RUN:-}" = "1" ]; then + cat </dev/null || { + echo "expected output to contain: $expected" >&2 + echo "$output" >&2 + exit 1 + } +} + +expect_file_text() { + file="$1" + text="$2" + grep -F "$text" "$file" >/dev/null || { + echo "expected $file to contain: $text" >&2 + exit 1 + } +} + +expect_output "asset=ocvm-x86_64-unknown-linux-gnu.tar.gz" \ + env OCVM_INSTALL_DRY_RUN=1 OCVM_TEST_UNAME_S=Linux OCVM_TEST_UNAME_M=x86_64 ./install.sh + +expect_output "asset=ocvm-x86_64-apple-darwin.tar.gz" \ + env OCVM_INSTALL_DRY_RUN=1 OCVM_TEST_UNAME_S=Darwin OCVM_TEST_UNAME_M=x86_64 ./install.sh + +expect_output "asset=ocvm-aarch64-apple-darwin.tar.gz" \ + env OCVM_INSTALL_DRY_RUN=1 OCVM_TEST_UNAME_S=Darwin OCVM_TEST_UNAME_M=arm64 ./install.sh + +expect_file_text .github/workflows/release.yml "target: x86_64-unknown-linux-gnu" +expect_file_text .github/workflows/release.yml "target: x86_64-apple-darwin" +expect_file_text .github/workflows/release.yml "target: aarch64-apple-darwin" +expect_file_text .github/workflows/release.yml "target: x86_64-pc-windows-msvc" +expect_file_text .github/workflows/release.yml 'shasum -a 256 "${name}.tar.gz" > "${name}.tar.gz.sha256"' +expect_file_text .github/workflows/release.yml '"$hash $name.zip"' + +echo "release prep checks passed"