Skip to content

fix(ci): scope workflow write permissions #4405

fix(ci): scope workflow write permissions

fix(ci): scope workflow write permissions #4405

Workflow file for this run

name: Windows MSVC
on:
push:
branches:
- windows
pull_request:
types: [opened, synchronize, reopened, labeled]
workflow_dispatch:
permissions:
contents: read
# Labeling a PR with anything but test:windows starts a run that skips every
# job. Give that run its own group so it cannot cancel a real one.
concurrency:
group: >-
${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}${{
github.event.action == 'labeled' && github.event.label.name != 'test:windows'
&& format('-{0}', github.run_id) || '' }}
cancel-in-progress: true
env:
# sccache cannot cache incremental Rust compilations, and rust-cache removes
# incremental artifacts before saving the target directory.
CARGO_INCREMENTAL: "0"
jobs:
pr-check:
name: PR lint and test (${{ matrix.arch }})
if: >-
github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'test:windows') &&
(github.event.action != 'labeled' || github.event.label.name == 'test:windows')
strategy:
fail-fast: false
matrix:
include:
- arch: x64
runner: windows-2025
rust_target: x86_64-pc-windows-msvc
- arch: arm64
runner: windows-11-arm
rust_target: aarch64-pc-windows-msvc
runs-on: ${{ matrix.runner }}
env:
READ_ONLY_GITHUB_TOKEN: ${{ github.token }}
SCCACHE_GHA_ENABLED: "true"
SCCACHE_GHA_VERSION: windows-msvc-${{ matrix.arch }}
SCCACHE_CLIENT_SIDE: "1"
SCCACHE_BASEDIRS: ${{ github.workspace }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
with:
install: false
experimental: true
- name: Configure GHA sccache backend
uses: mozilla-actions/sccache-action@9e7fa8a12102821edf02ca5dbea1acd0f89a2696 # v0.0.10
- name: Isolate Rust toolchains
# rust-cache hashes every installed toolchain, including unused runner defaults.
run: '"RUSTUP_HOME=$env:RUNNER_TEMP/openshell-rustup" >> $env:GITHUB_ENV'
- name: Install Rust toolchain
# GitHub-hosted runners include rustup. With no toolchain argument,
# rustup installs the checked-in rust-toolchain.toml configuration:
# https://github.com/dtolnay/rust-toolchain/issues/133#issuecomment-2610825530
run: |
rustup set profile minimal
rustup toolchain install
rustup component add clippy
rustup target add ${{ matrix.rust_target }}
- name: Install cargo-nextest
run: mise install --locked github:nextest-rs/nextest
- name: Cache Rust target and registry
uses: Swatinem/rust-cache@6a7bc3ebce750e0a16a430dd57485acfdb38b05f
env:
# Keep rust-cache's cargo metadata calls independent of the compiler
# wrapper; build steps still inherit sccache from the job.
RUSTC_WRAPPER: ""
with:
shared-key: windows-msvc-${{ matrix.arch }}
cache-targets: "true"
cache-on-failure: "true"
cache-bin: "false"
- name: Lint Windows-supported crates
run: mise run --skip-tools windows:lint:${{ matrix.arch }}
- name: Test
run: mise run --skip-tools windows:test:${{ matrix.arch }}
- name: sccache stats
if: always()
run: sccache --show-stats
cache-seed:
name: Seed cache (${{ matrix.arch }})
# Keep release-branch Windows validation advisory while the lane matures.
continue-on-error: true
if: github.ref == 'refs/heads/windows'
strategy:
fail-fast: false
matrix:
include:
- arch: x64
runner: windows-2025
rust_target: x86_64-pc-windows-msvc
- arch: arm64
runner: windows-11-arm
rust_target: aarch64-pc-windows-msvc
runs-on: ${{ matrix.runner }}
env:
READ_ONLY_GITHUB_TOKEN: ${{ github.token }}
SCCACHE_GHA_ENABLED: "true"
SCCACHE_GHA_VERSION: windows-msvc-${{ matrix.arch }}
SCCACHE_CLIENT_SIDE: "1"
SCCACHE_BASEDIRS: ${{ github.workspace }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
with:
install: false
experimental: true
- name: Configure GHA sccache backend
uses: mozilla-actions/sccache-action@9e7fa8a12102821edf02ca5dbea1acd0f89a2696 # v0.0.10
- name: Isolate Rust toolchains
run: '"RUSTUP_HOME=$env:RUNNER_TEMP/openshell-rustup" >> $env:GITHUB_ENV'
- name: Install Rust toolchain
run: |
rustup set profile minimal
rustup toolchain install
rustup component add clippy
rustup target add ${{ matrix.rust_target }}
- name: Install cargo-nextest
run: mise install --locked github:nextest-rs/nextest
- name: Cache Rust target and registry
uses: Swatinem/rust-cache@6a7bc3ebce750e0a16a430dd57485acfdb38b05f
env:
RUSTC_WRAPPER: ""
with:
shared-key: windows-msvc-${{ matrix.arch }}
cache-targets: "true"
cache-on-failure: "true"
cache-bin: "false"
- name: Lint Windows-supported crates
# Keep the seed workload identical to the pull-request workload so the
# windows-branch cache reflects the same lint and test commands.
run: mise run --skip-tools windows:lint:${{ matrix.arch }}
- name: Test
run: mise run --skip-tools windows:test:${{ matrix.arch }}
- name: sccache stats
if: always()
run: sccache --show-stats
build:
name: Build binaries (${{ matrix.arch }})
continue-on-error: true
needs: cache-seed
strategy:
fail-fast: false
matrix:
include:
- arch: x64
runner: windows-2025
rust_target: x86_64-pc-windows-msvc
- arch: arm64
runner: windows-11-arm
rust_target: aarch64-pc-windows-msvc
runs-on: ${{ matrix.runner }}
env:
READ_ONLY_GITHUB_TOKEN: ${{ github.token }}
SCCACHE_GHA_ENABLED: "true"
SCCACHE_GHA_VERSION: windows-msvc-${{ matrix.arch }}
SCCACHE_CLIENT_SIDE: "1"
SCCACHE_BASEDIRS: ${{ github.workspace }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
with:
install: false
experimental: true
- name: Configure GHA sccache backend
uses: mozilla-actions/sccache-action@9e7fa8a12102821edf02ca5dbea1acd0f89a2696 # v0.0.10
- name: Isolate Rust toolchains
run: '"RUSTUP_HOME=$env:RUNNER_TEMP/openshell-rustup" >> $env:GITHUB_ENV'
- name: Install Rust toolchain
run: |
rustup set profile minimal
rustup toolchain install
rustup target add ${{ matrix.rust_target }}
- name: Cache Rust target and registry
uses: Swatinem/rust-cache@6a7bc3ebce750e0a16a430dd57485acfdb38b05f
env:
RUSTC_WRAPPER: ""
with:
shared-key: windows-msvc-${{ matrix.arch }}
cache-targets: "true"
cache-on-failure: "true"
cache-bin: "false"
- name: Build release binaries
run: mise run --skip-tools windows:build:${{ matrix.arch }}
- name: sccache stats
if: always()
run: sccache --show-stats