From fa15df4fc48023bf7acf018b9312418af540e184 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 4 Jun 2024 11:26:58 -0500 Subject: [PATCH] Add a PR build workflow (#78) 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 --- .cargo/config.toml | 1 + .github/actions/fix-environment/action.yml | 44 ++++++++++++++++++ .github/workflows/pr-build.yaml | 52 ++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 .github/actions/fix-environment/action.yml create mode 100644 .github/workflows/pr-build.yaml diff --git a/.cargo/config.toml b/.cargo/config.toml index f222047..b4178fb 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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" diff --git a/.github/actions/fix-environment/action.yml b/.github/actions/fix-environment/action.yml new file mode 100644 index 0000000..5c8ad63 --- /dev/null +++ b/.github/actions/fix-environment/action.yml @@ -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 + } + } diff --git a/.github/workflows/pr-build.yaml b/.github/workflows/pr-build.yaml new file mode 100644 index 0000000..bb4ae33 --- /dev/null +++ b/.github/workflows/pr-build.yaml @@ -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