chore: use nushell in ci #492
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: nu {0} | |
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: | |
- if: matrix.os != 'windows-11-preview_aarch64' | |
uses: hustcer/setup-nu@main | |
with: | |
version: '*' | |
- if: matrix.os == 'windows-11-preview_aarch64' | |
uses: robinraju/release-downloader@v1 | |
with: | |
repository: 'git-for-windows/git' | |
tag: 'v2.48.0-rc1.windows.1' | |
filename: 'Git-2.48.0-rc1-arm64.exe' | |
- if: matrix.os == 'windows-11-preview_aarch64' | |
uses: robinraju/release-downloader@v1 | |
with: | |
repository: 'llvm/llvm-project' | |
tag: 'llvmorg-19.1.5' | |
filename: 'LLVM-19.1.5-woa64.exe' | |
- name: "Install nushell" | |
if: matrix.os == 'windows-11-preview_aarch64' | |
shell: powershell | |
run: | | |
function Install-Package { | |
param ( | |
[string]$packageUrl, # URL to download the package from | |
[string]$packageName # Name of the package (for path management) | |
) | |
# Define file paths | |
$archivePath = "$env:RUNNER_TEMP\$packageName.zip" | |
$extractPath = "$env:RUNNER_TEMP\$packageName" | |
$msixPath = "$env:RUNNER_TEMP\Microsoft.DesktopAppInstaller.msixbundle" | |
# Download the package | |
Invoke-WebRequest -Uri $packageUrl -OutFile $archivePath -UseBasicParsing | |
# If it's a .zip file (for .appx), extract it | |
if ($packageUrl -like "*nuget*") { | |
New-Item -ItemType Directory -Force -Path $extractPath | |
Expand-Archive -Path $archivePath -DestinationPath $extractPath | |
$appxFile = Get-ChildItem -Path "$extractPath\tools\AppX\x64\Release" -Filter "*.appx" | Select-Object -First 1 | |
if ($appxFile) { | |
Add-AppxPackage -Path $appxFile.FullName | |
} else { | |
Write-Error "No .appx file found" | |
} | |
# Clean up .zip and extracted folder | |
Remove-Item -Path $archivePath, $extractPath -Recurse | |
} | |
# If it's an MSIX bundle (for .msix), just install it | |
elseif ($packageUrl -like "*msixbundle*") { | |
Add-AppxPackage -Path $archivePath | |
# Clean up MSIX bundle | |
Remove-Item -Path $archivePath -Force | |
} | |
else { | |
Write-Error "Unsupported file type" | |
} | |
} | |
# Define URLs and paths | |
$nugetUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/" | |
$msixUrl = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" | |
# Install the .appx package | |
Install-Package -packageUrl $nugetUrl -packageName "Microsoft.UI.Xaml" | |
# Install the MSIX bundle | |
Install-Package -packageUrl $msixUrl -packageName "Microsoft.DesktopAppInstaller" | |
# Repair WinGet package manager and install Nushell | |
Repair-WinGetPackageManager -IncludePrerelease | |
winget install nushell | |
- name: Use nushell | |
if: matrix.os == 'windows-11-preview_aarch64' | |
run: | | |
use std log | |
let $nu_version = nu --version; | |
log info "Using `nu` version `$nu_version`" | |
log info "Installing LLVM 19.1.5 (aarch64)..." | |
^r#'${{github.workspace}}\LLVM-19.1.5-woa64.exe'# /S | |
log info "LLVM 19.1.5 (aarch64) installation completed." | |
log info "Installing Git 2.48.0-rc1 (aarch64)..." | |
^r#'${{github.workspace}}\Git-2.48.0-rc1-arm64.exe'# /VERYSILENT | |
log info "Git 2.48.0-rc1 (aarch64) installation completed." | |
log info "Installing Visual Studio 2022 Build Tools (aarch64)..." | |
choco install visualstudio2022buildtools -y --no-progress --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621" | |
log info "Visual Studio 2022 Build Tools (aarch64) installation completed." | |
http get "https://win.rustup.rs/aarch64" | save r#'${{github.workspace}}\rustup-init.exe'# | |
^r#'${{github.workspace}}\rustup-init.exe'# --default-host aarch64-pc-windows-msvc --default-toolchain nightly -y | |
log info "Rust (nightly, aarch64) installation completed." | |
let exports = [ | |
$'($env.USERPROFILE)/.cargo/bin', # Rust | |
$'($env.ProgramFiles)/Git/cmd', # Git | |
$'($env.ProgramFiles)/Git/bin', # Bash | |
] | |
for path in $exports { | |
$'($path)' | save $env.GITHUB_PATH --append | |
log info $'added `($path)` to `$env.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 | |
- 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: | | |
let $arch = '${{ matrix.target }}' | split row '-' | first | |
let $arch = if $arch == 'i686' { 'x86' } else { $arch } | |
echo $'ARCH=($arch)' | save $env.GITHUB_ENV --append | |
let output = glob target/${{ matrix.target }}/release/build/**/$($arch)_bindgen.rs | first | |
cp $output $'src/ffi/($arch)_bindgen.rs' | |
echo $'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@v3 | |
- name: Download generated files | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: "*bindgen.rs" | |
path: src/ffi | |
merge-multiple: true | |
- name: Configure Git | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
- name: Commit and push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
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 |