chore: improve ci powershell #629
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "cargo" | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
bindgen: | |
defaults: | |
run: | |
shell: powershell | |
strategy: | |
matrix: | |
os: [windows-11-preview_aarch64, windows-2025] | |
target: [aarch64-pc-windows-msvc, x86_64-pc-windows-msvc, i686-pc-windows-msvc] | |
exclude: | |
- os: windows-11-preview_aarch64 | |
target: x86_64-pc-windows-msvc | |
- os: windows-11-preview_aarch64 | |
target: i686-pc-windows-msvc | |
- os: windows-2025 | |
target: aarch64-pc-windows-msvc | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Install Build Tools | |
if: matrix.os == 'windows-11-preview_aarch64' | |
run: | | |
function Log { | |
param( | |
[Parameter(Mandatory=$true)] [string]$Message, | |
[string]$Level = "INFO" | |
) | |
$timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' | |
if ($Level -eq "ERROR") { | |
Write-Error "$timestamp [ERROR] - $Message" | |
} else { | |
Write-Host "$timestamp [$Level] - $Message" | |
} | |
} | |
Set-ExecutionPolicy Bypass -Scope Process -Force | |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
$installs = @( | |
@{ Name = 'Chocolatey'; Url = 'https://chocolatey.org/install.ps1'; Hash = $null; | |
Action = { & 'install.ps1' }}, | |
@{ Name = 'Visual Studio 2022 Build Tools (aarch64)'; Hash = $null; Url = $null; | |
Action = { choco install visualstudio2022buildtools -y --no-progress --silent --package-parameters '--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621' }}, | |
@{ Name = 'Rust (nightly, aarch64)'; | |
Url = 'https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe'; | |
Hash = 'https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe.sha256'; | |
Action = { & 'rustup-init.exe' --default-host aarch64-pc-windows-msvc --default-toolchain nightly -y }}, | |
@{ Name = 'LLVM 19.1.5'; | |
Url = 'https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.5/LLVM-19.1.5-woa64.exe'; | |
Hash = '63D479C19C3908F8C973331EDC9B576485EAB6AB0809F58C79DF5D209FDD8F96'; | |
Action = { & 'LLVM-19.1.5-woa64.exe' /S }}, | |
@{ Name = 'Git 2.48.0-rc1'; | |
Url = 'https://github.com/git-for-windows/git/releases/download/v2.48.0-rc2.windows.1/Git-2.48.0-rc2-arm64.exe'; | |
Hash = '712739bb49832d571732e3e74b111d7cb4a63cd622ef3e87d01efe35046d9a4f'; | |
Action = { & 'Git-2.48.0-rc2-arm64.exe' /VERYSILENT }} | |
) | |
$installs | ForEach-Object { | |
if ($_.Url -ne $null) { | |
Log "Downloading $($_.Name) from $($_.Url)..." | |
$install_file = Join-Path '${{ github.workspace }}' (Split-Path $_.Url -Leaf) | |
Invoke-WebRequest -Uri $_.Url -OutFile $install_file | |
} | |
if ($_.Hash -ne $null) { | |
$expected_hash = if ($_.Hash -like "*.sha256") { | |
$hash_file = Join-Path '${{ github.workspace }}' (Split-Path $_.Hash -Leaf) | |
Invoke-WebRequest -Uri $_.Hash -OutFile $hash_file | |
(Get-Content -Path $hash_file).Trim() | |
} else { | |
$_.Hash | |
} | |
$downloaded_hash = (Get-FileHash -Path $install_file -Algorithm SHA256).Hash | |
if ($downloaded_hash -eq $expected_hash) { | |
Log "Hash verified successfully." | |
} else { | |
Log "Hash mismatch for $($_.Name). Expected: $expected_hash, Got: $downloaded_hash" -Level "ERROR" | |
exit 1 | |
} | |
} else { | |
Log "No hash specified, skipping verification." | |
} | |
Log "Starting installation of $($_.Name)..." | |
try { | |
& $_.Action > $null 2>&1 | |
Log "$($_.Name) installation completed." | |
} catch { | |
Log "Failed to install $($_.Name)." -Level "ERROR" | |
} | |
} | |
$paths = @( | |
"$env:ProgramFiles\Git\cmd", # Git | |
"$env:ProgramFiles\Git\bin", # Bash | |
"$env:ProgramData\chocolatey\bin", # Chocolatey | |
"$env:USERPROFILE\.cargo\bin" # Rust | |
) | |
$paths | ForEach-Object { | |
Add-Content -Path $env:GITHUB_PATH -Value $_ | |
Log "Added $_ to `$GITHUB_PATH" | |
} | |
- name: Install Rust | |
if: matrix.os != 'windows-11-preview_aarch64' | |
uses: dtolnay/rust-toolchain@nightly | |
with: | |
targets: ${{ matrix.target }} | |
components: rustfmt | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
- name: Run tests and generate bindings | |
env: | |
PHNT_VERSION: PHNT_WIN11_24H2 | |
PHNT_MODE: PHNT_MODE_USER | |
run: | | |
cargo test --release -vv -F regenerate --target ${{ matrix.target }} | |
- name: Extract architecture from target triple and move bindings | |
run: | | |
$arch = '${{ matrix.target }}' -split '-' | Select-Object -First 1 | |
$arch = if ($arch -eq 'i686') { 'x86' } else { $arch } | |
Add-Content -Path $env:GITHUB_ENV -Value "ARCH=$arch" | |
$output = Get-ChildItem -Path "target/${{ matrix.target }}/release/build/**/$($arch)_bindgen.rs" -Recurse | Select-Object -First 1 | |
Copy-Item -Path $output.FullName -Destination "src/ffi/$($arch)_bindgen.rs" | |
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] - Moved $output to src/ffi/$($arch)_bindgen.rs" | |
- name: Upload generated file as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARCH }}_bindgen.rs | |
path: src/ffi/${{ env.ARCH }}_bindgen.rs | |
commit-and-push: | |
runs-on: ubuntu-latest | |
needs: bindgen | |
if: success() # Run only if the generate-bindgen job succeeds | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download generated files | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: "*bindgen.rs" | |
path: src/ffi | |
merge-multiple: true | |
- name: Commit and push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git add src/ffi | |
# Check if there are any changes to commit | |
if git diff --quiet --exit-code --cached; then | |
echo "No changes to commit." | |
else | |
git commit -m "chore: update vendored bindings" | |
git push --force | |
fi |