CurtHagenlocher commented on code in PR #350: URL: https://github.com/apache/arrow-dotnet/pull/350#discussion_r3185870082
########## dev/release/verify_rc.ps1: ########## @@ -0,0 +1,275 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +<# +.SYNOPSIS + Verifies an Apache Arrow .NET release candidate. +.DESCRIPTION + Downloads and verifies an Apache Arrow .NET release candidate, + including GPG signature verification, checksum verification, + and optionally building and testing source and binary distributions. +.PARAMETER Version + The release version (e.g., 22.0.0). +.PARAMETER RC + The release candidate number (e.g., 0). +.EXAMPLE + .\verify_rc.ps1 22.0.0 0 +#> + +[CmdletBinding()] +param( + [Parameter(Mandatory = $true, Position = 0)] + [string]$Version, + + [Parameter(Mandatory = $true, Position = 1)] + [string]$RC +) + +$ErrorActionPreference = "Stop" + +# In PowerShell 7.3+, this makes native command failures respect +# $ErrorActionPreference. On older versions, we rely on Invoke-Block below. +if ($null -ne (Get-Variable PSNativeCommandUseErrorActionPreference -ErrorAction SilentlyContinue)) { + $PSNativeCommandUseErrorActionPreference = $true +} + +function Invoke-Block { + # Execute a script block containing native commands and throw on failure. + param([scriptblock]$Block) + & $Block + if ($LASTEXITCODE -ne 0) { + throw "Command failed with exit code ${LASTEXITCODE}: $Block" + } +} + +$SourceDir = Split-Path -Parent $PSCommandPath +$TopSourceDir = Split-Path -Parent (Split-Path -Parent $SourceDir) + +$ArrowDistBaseUrl = "https://dist.apache.org/repos/dist/release/arrow" +$DownloadRCBaseUrl = "https://github.com/apache/arrow-dotnet/releases/download/v${Version}-rc${RC}" +$ArchiveBaseName = "apache-arrow-dotnet-${Version}" + +if (-not (Test-Path env:VERIFY_DEFAULT)) { $env:VERIFY_DEFAULT = "1" } +if (-not (Test-Path env:VERIFY_BINARY)) { $env:VERIFY_BINARY = $env:VERIFY_DEFAULT } +if (-not (Test-Path env:VERIFY_DOWNLOAD)){ $env:VERIFY_DOWNLOAD = $env:VERIFY_DEFAULT } +if (-not (Test-Path env:VERIFY_SIGN)) { $env:VERIFY_SIGN = $env:VERIFY_DEFAULT } +if (-not (Test-Path env:VERIFY_SOURCE)) { $env:VERIFY_SOURCE = $env:VERIFY_DEFAULT } + +$VerifySuccess = $false + +function GitHub-Actions-Group-Begin([string]$Name) { + Write-Host "::group::$Name" +} + +function GitHub-Actions-Group-End { + Write-Host "::endgroup::" +} + +function Download([string]$Url) { + Invoke-Block { curl.exe --fail --location --remote-name --show-error --silent $Url } +} + +function Download-RC-File([string]$FileName) { + if ([int]$env:VERIFY_DOWNLOAD -gt 0) { + Download "${DownloadRCBaseUrl}/${FileName}" + } else { + Copy-Item (Join-Path $TopSourceDir $FileName) -Destination $FileName + } +} + +function Import-GPG-Keys { + if ([int]$env:VERIFY_SIGN -gt 0) { + Download "${ArrowDistBaseUrl}/KEYS" + Invoke-Block { gpg --import KEYS } + } +} + +function Verify-SHA([string]$Algorithm, [string]$ChecksumFile) { + $ExpectedLine = (Get-Content $ChecksumFile -Raw).Trim() + # Format is "hash filename" or "hash *filename" + $Parts = $ExpectedLine -split '\s+', 2 + $ExpectedHash = $Parts[0] + $FileName = ($Parts[1] -replace '^\*', '').Trim() + + $ActualHash = (Get-FileHash -Algorithm $Algorithm -Path $FileName).Hash.ToLower() + if ($ActualHash -ne $ExpectedHash.ToLower()) { + throw "$Algorithm checksum mismatch for ${FileName}: expected ${ExpectedHash}, got ${ActualHash}" + } + Write-Host "${FileName}: OK (${Algorithm})" +} + +function Fetch-Artifact([string]$Artifact) { + Download-RC-File $Artifact + if ([int]$env:VERIFY_SIGN -gt 0) { + Download-RC-File "${Artifact}.asc" + Invoke-Block { gpg --verify "${Artifact}.asc" $Artifact } + } + Download-RC-File "${Artifact}.sha256" + Verify-SHA "SHA256" "${Artifact}.sha256" + Download-RC-File "${Artifact}.sha512" + Verify-SHA "SHA512" "${Artifact}.sha512" +} + +function Fetch-Archive { + Fetch-Artifact "${ArchiveBaseName}.tar.gz" +} + +function Ensure-Source-Directory { + Invoke-Block { tar xf "${ArchiveBaseName}.tar.gz" } +} + +function Get-TestTarget { + # Prefer the solution filter if available, fall back to the solution file. + if (Test-Path "Apache.Arrow.Tests.slnf") { + return "Apache.Arrow.Tests.slnf" + } + return "Apache.Arrow.sln" +} + +function Test-Source-Distribution { + if ([int]$env:VERIFY_SOURCE -le 0) { + return + } + + Invoke-Block { dotnet build } + + # Python and PyArrow are required for C Data Interface tests. + if (-not (Test-Path env:PYTHON)) { + if (Get-Command python3 -ErrorAction SilentlyContinue) { Review Comment: Thanks for calling this out; I'd forgotten that I ended up having to manually copy `python.exe` on top of `python3.exe` which is silly. I'll fix the script instead. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
