Skip to content

Commit

Permalink
Add a PR build workflow (#78)
Browse files Browse the repository at this point in the history
Obviously,
* you can't test GH actions locally
* and you can't test the actions in the repo without the actual source code
* and you don't want to include the actions with the initial source code commit if its _wrong_ 

So, here's the GH action to test this that we _think_ is right
  • Loading branch information
zadjii-msft authored Jun 4, 2024
1 parent e5ce5c6 commit fa15df4
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -Ccontrol-flow-guard: Enable Control Flow Guard, needed for OneBranch's post-build analysis (https://learn.microsoft.com/en-us/cpp/build/reference/guard-enable-control-flow-guard).
[target.'cfg(target_os = "windows")']
rustflags = [
"-Dwarnings",
"-Ccontrol-flow-guard",
"-Ctarget-feature=+crt-static",
"-Clink-args=/DEFAULTLIB:ucrt.lib /NODEFAULTLIB:vcruntime.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libucrt.lib"
Expand Down
44 changes: 44 additions & 0 deletions .github/actions/fix-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Fix environment
description: GitHub VMs aren't configured correctly
# Shamelessly borrowed from https://github.com/microsoft/windows-rs/blob/master/.github/actions/fix-environment/action.yml
runs:
using: "composite"
steps:
- name: Configure environment
shell: pwsh
run: |
$vs_root = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
-latest -property installationPath -format value
switch -Wildcard ("${{ matrix.target }}")
{
"*-pc-windows-gnu"
{
"C:\msys64\mingw64\bin;C:\msys64\mingw32\bin" >> $env:GITHUB_PATH
}
"i686*"
{
"${env:ProgramFiles(x86)}\Windows Kits\10\bin\10.0.22000.0\x86" >> $env:GITHUB_PATH
((Resolve-Path "$vs_root\VC\Tools\MSVC\*\bin\Hostx86\x86")
| Sort-Object -Descending | Select -First 1).ToString() >> $env:GITHUB_PATH
}
"x86_64*"
{
"${env:ProgramFiles(x86)}\Windows Kits\10\bin\10.0.22000.0\x64" >> $env:GITHUB_PATH
((Resolve-Path "$vs_root\VC\Tools\MSVC\*\bin\Hostx64\x64")
| Sort-Object -Descending | Select -First 1).ToString() >> $env:GITHUB_PATH
}
"aarch64*"
{
"${env:ProgramFiles(x86)}\Windows Kits\10\bin\10.0.22000.0\x64" >> $env:GITHUB_PATH
((Resolve-Path "$vs_root\VC\Tools\MSVC\*\bin\Hostx64\x64")
| Sort-Object -Descending | Select -First 1).ToString() >> $env:GITHUB_PATH
}
"*"
{
(Join-Path $env:GITHUB_WORKSPACE "target\debug\deps").ToString() >> $env:GITHUB_PATH
(Join-Path $env:GITHUB_WORKSPACE "target\test\debug\deps").ToString() >> $env:GITHUB_PATH
"INCLUDE=${env:ProgramFiles(x86)}\Windows Kits\10\include\10.0.22000.0\winrt;${env:ProgramFiles(x86)}\Windows Kits\10\include\10.0.22000.0\cppwinrt" `
>> $env:GITHUB_ENV
}
}
52 changes: 52 additions & 0 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: PR Build & Test

on:
pull_request:
push:
paths-ignore:
- '.github/ISSUE_TEMPLATE/**'
branches:
- main

jobs:
check:
runs-on: windows-2022

strategy:
matrix:
# Apparently ARM targets aren't usable in GH actions
# target: [x86_64-pc-windows-msvc, i686-pc-windows-msvc, aarch64-pc-windows-msvc]
target: [x86_64-pc-windows-msvc, i686-pc-windows-msvc]
branding: [Inbox, Stable, Dev]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Update toolchain
run: rustup update --no-self-update stable && rustup default stable-${{ matrix.target }}

- name: Add toolchain target
run: rustup target add ${{ matrix.target }}

- name: Install fmt
run: rustup component add rustfmt

- name: Install clippy
run: rustup component add clippy

- name: Fix environment
uses: ./.github/actions/fix-environment

- name: Clean
run: cargo clean

- name: Run fmt
run: cargo fmt --all -- --check

# Test will build the code, then also test it.
- name: Test
run: cargo test --no-default-features --features ${{matrix.branding}} --target ${{ matrix.target }}

- name: Run clippy
run: cargo clippy --no-default-features --features ${{matrix.branding}} --target ${{matrix.target}} 2>&1

0 comments on commit fa15df4

Please sign in to comment.