GitHub Actions Windows
windows-latest runner、与 ci.yml 关系。
25 分钟
GitHub Actions Windows
GitHub Actions 提供 windows-latest runner,预装 PowerShell 5.1 与 pwsh。本站 .github/workflows/ci.yml 主 CI 跑在 ubuntu-latest;Windows job 适合测 PowerShell 脚本、.NET 或跨平台兼容性。
学习目标
- 在 workflow 里使用
runs-on: windows-latest - 写 PowerShell 步骤与 Bash 步骤的差异
- 理解 ci.yml 与 Windows 专项 job 的关系
核心内容
ci.yml 现状
仓库根目录 .github/workflows/ci.yml:
jobs:
backend:
runs-on: ubuntu-latest
# mvn verify
platform:
runs-on: ubuntu-latest
# npm ci / lint / test / build
Java 与 Node 构建均在 Linux runner 完成(gha-java、gha-node)。
添加 Windows job 示例
ps-scripts:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: List deploy scripts
shell: pwsh
run: Get-ChildItem deploy/scripts/*.ps1 | Select-Object Name
shell: pwsh 用 PowerShell 7;省略时 Windows 默认 powershell(5.1)。步骤内用 $env:VAR 读 secrets,勿 echo 敏感值。
步骤 shell 对照
| shell 值 | 环境 |
|---|---|
bash | Linux/macOS 默认 |
pwsh | PowerShell 7(跨平台) |
powershell | Windows 5.1 |
cmd | Windows CMD |
路径用反斜杠或正斜杠均可(gha-steps)。
何时需要 Windows runner
- 验证
sync-courses.ps1、package-prod.bat在干净 Windows 环境可执行 - 构建依赖 Windows SDK 的项目
- 多数 CodeRoadMap CI 不必 Windows——Linux 已覆盖 backend + platform
练习
- 打开 ci.yml,确认两个 job 的
runs-on - 写一段 workflow 片段: + +