mirror of
https://github.com/feigeCode/navop.git
synced 2026-09-22 16:01:30 +00:00
只改 CHANGELOG.md / main/Cargo.toml / Cargo.lock 的发布 PR 此前仍要跑 macOS / Linux / Windows 三平台全量测试(Windows job 约 25 分钟),而改动里 没有任何代码,这些测试没有意义。 - ci.yml 新增 classify job:PR 场景下用 script/release_pr.py 判定是否只包含 发布改动,是则跳过 test 与 windows-rdp-probe,改为就地校验发布元数据 - script/release_pr.py:分类规则为「改动文件全部属于发布白名单」且 「Cargo.toml / Cargo.lock 的差异只有 version = "..." 行」;命中后校验 main/Cargo.toml 与 Cargo.lock 中 main 包版本一致,且该版本的双语 changelog 条目完整(更新内容/修复与优化 + What's New/Fixes and Improvements,含 CNB 镜像行);无法算出 diff 时回退到全量测试 - ci-gate 仍是唯一必需状态检查,分类或校验失败都会拦住合并 - .github/RELEASE.md 记录该快速通道 - windows_rdp_host 契约测试钉住 classify/needs/if 结构与脚本白名单 验证: - python3 -m unittest discover -s script/tests -p "test_release_pr.py" — 16 passed - cargo test -p windows_rdp_host --test contract — 40 passed - ruby -ryaml 解析 ci.yml,核对 classify/test/windows-rdp-probe/ci-gate 的 needs 与 if 表达式 - rustfmt --edition 2024 --check crates/windows_rdp_host/tests/contract.rs
222 lines
7.4 KiB
YAML
222 lines
7.4 KiB
YAML
name: CI
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
inputs:
|
|
platform:
|
|
description: "Run all platforms or only one platform"
|
|
required: true
|
|
type: choice
|
|
default: all
|
|
options:
|
|
- all
|
|
- linux
|
|
- windows
|
|
- macos
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
RUSTC_WRAPPER: sccache
|
|
SCCACHE_GHA_ENABLED: "true"
|
|
SCCACHE_IDLE_TIMEOUT: "7200"
|
|
|
|
jobs:
|
|
prepare:
|
|
name: Prepare CI matrix
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
matrix: ${{ steps.matrix.outputs.matrix }}
|
|
|
|
steps:
|
|
- name: Resolve requested platforms
|
|
id: matrix
|
|
env:
|
|
REQUESTED_PLATFORM: ${{ inputs.platform }}
|
|
run: |
|
|
set -euo pipefail
|
|
platform="${REQUESTED_PLATFORM:-all}"
|
|
linux='{"target":"x86_64-unknown-linux-gnu","run_on":"ubuntu-latest","platform":"linux"}'
|
|
windows='{"target":"x86_64-pc-windows-msvc","run_on":"windows-2022","platform":"windows"}'
|
|
macos='{"target":"aarch64-apple-darwin","run_on":"macos-latest","platform":"macos"}'
|
|
case "$platform" in
|
|
all) matrix="[$macos,$linux,$windows]" ;;
|
|
linux) matrix="[$linux]" ;;
|
|
windows) matrix="[$windows]" ;;
|
|
macos) matrix="[$macos]" ;;
|
|
*) echo "::error::Unsupported platform: $platform"; exit 1 ;;
|
|
esac
|
|
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
|
|
|
|
# 发布 PR 只改 CHANGELOG + 版本号,跑全平台测试没有意义:这一层只做分类,
|
|
# 并在判定为发布改动时就地校验 changelog 与版本号;其余 PR 照旧跑全量测试。
|
|
classify:
|
|
name: Classify changes
|
|
if: ${{ github.event_name == 'pull_request' }}
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
release_only: ${{ steps.check.outputs.release_only }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Classify and validate release-only changes
|
|
id: check
|
|
env:
|
|
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
|
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
run: python3 script/release_pr.py check
|
|
|
|
test:
|
|
name: Test (${{ matrix.platform }}, ${{ matrix.target }})
|
|
needs: [prepare, classify]
|
|
if: ${{ needs.classify.outputs.release_only != 'true' }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include: ${{ fromJSON(needs.prepare.outputs.matrix) }}
|
|
runs-on: ${{ matrix.run_on }}
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
- name: Install NASM
|
|
if: ${{ matrix.platform == 'windows' }}
|
|
shell: pwsh
|
|
run: |
|
|
choco install nasm --no-progress --yes
|
|
$nasmDir = Join-Path $env:ProgramFiles "NASM"
|
|
$nasmExe = Join-Path $nasmDir "nasm.exe"
|
|
if (-not (Test-Path -LiteralPath $nasmExe -PathType Leaf)) {
|
|
throw "NASM executable was not found at '$nasmExe'"
|
|
}
|
|
$env:Path = "$nasmDir;$env:Path"
|
|
$nasmDir | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
|
nasm -v
|
|
- name: Test release packaging
|
|
if: ${{ matrix.run_on == 'ubuntu-latest' }}
|
|
run: node --test script/test-release-packaging.mjs
|
|
- name: Setup Rust toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
target: ${{ matrix.target }}
|
|
cache: false
|
|
# sccache 只是构建加速器:GitHub Release CDN 偶发 504 会让下载安装失败,
|
|
# 此时必须退化成无缓存构建,而不是让整个测试 job 失败。
|
|
- name: Setup sccache
|
|
id: sccache
|
|
uses: mozilla-actions/sccache-action@v0.0.10
|
|
continue-on-error: true
|
|
- name: Initialize sccache
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
if [ "${{ steps.sccache.outcome }}" != "success" ]; then
|
|
echo "::warning::sccache 安装失败,本次构建退化为无编译器缓存"
|
|
echo "RUSTC_WRAPPER=" >> "$GITHUB_ENV"
|
|
exit 0
|
|
fi
|
|
sccache --start-server
|
|
sccache --zero-stats
|
|
sccache --show-stats
|
|
- name: Restore shared Cargo inputs
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index/
|
|
~/.cargo/registry/cache/
|
|
~/.cargo/git/db/
|
|
key: navop-cargo-inputs-v1-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
navop-cargo-inputs-v1-${{ runner.os }}-
|
|
release-cargo-inputs-${{ runner.os }}-${{ matrix.target }}-
|
|
- name: Install system dependencies
|
|
if: ${{ matrix.platform != 'windows' }}
|
|
run: script/bootstrap
|
|
- name: Install lrzsz on Linux
|
|
if: ${{ matrix.platform == 'linux' }}
|
|
run: sudo apt-get update && sudo apt-get install -y lrzsz
|
|
- name: Install lrzsz on macOS
|
|
if: ${{ matrix.platform == 'macos' }}
|
|
run: brew list lrzsz >/dev/null 2>&1 || brew install lrzsz
|
|
- name: Install wasm-tools
|
|
run: cargo install wasm-tools --locked --version 1.251.0
|
|
- name: Test Linux
|
|
if: ${{ matrix.platform == 'linux' }}
|
|
run: |
|
|
cargo test --all
|
|
- name: Test Windows
|
|
if: ${{ matrix.platform == 'windows' }}
|
|
shell: pwsh
|
|
run: ./script/test-windows.ps1
|
|
- name: Test MacOS
|
|
if: ${{ matrix.platform == 'macos' }}
|
|
run: |
|
|
cargo test --all
|
|
- name: Show sccache statistics
|
|
if: always()
|
|
shell: bash
|
|
run: sccache --show-stats || true
|
|
|
|
windows-rdp-probe:
|
|
name: Windows RDP probe (${{ matrix.target }})
|
|
needs: [classify]
|
|
if: >-
|
|
${{
|
|
(inputs.platform == '' ||
|
|
inputs.platform == 'all' ||
|
|
inputs.platform == 'windows') &&
|
|
needs.classify.outputs.release_only != 'true'
|
|
}}
|
|
runs-on: windows-2022
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
target:
|
|
- x86_64-pc-windows-msvc
|
|
- i686-pc-windows-msvc
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
- name: Install NASM
|
|
shell: pwsh
|
|
run: |
|
|
choco install nasm --no-progress --yes
|
|
$nasmDir = Join-Path $env:ProgramFiles "NASM"
|
|
$nasmExe = Join-Path $nasmDir "nasm.exe"
|
|
if (-not (Test-Path -LiteralPath $nasmExe -PathType Leaf)) {
|
|
throw "NASM executable was not found at '$nasmExe'"
|
|
}
|
|
$env:Path = "$nasmDir;$env:Path"
|
|
$nasmDir | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
|
nasm -v
|
|
- name: Setup Rust toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
target: ${{ matrix.target }}
|
|
cache: false
|
|
- name: Build ATL/MSVC probe
|
|
shell: pwsh
|
|
run: >-
|
|
./script/build-windows-rdp-probe.ps1
|
|
-Target "${{ matrix.target }}"
|
|
|
|
ci-gate:
|
|
name: CI gate
|
|
needs: [prepare, classify, test, windows-rdp-probe]
|
|
if: always()
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Fail if any CI job failed
|
|
run: |
|
|
if [ "${{ contains(needs.*.result, 'failure') }}" = "true" ] || [ "${{ contains(needs.*.result, 'cancelled') }}" = "true" ]; then
|
|
echo "::error::One or more CI jobs failed"
|
|
exit 1
|
|
fi
|