Update build.yml #55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 定义工作流名称 | |
name: 编译 PCL | |
# 定义触发器 | |
on: | |
# 提交内容修改代码或编辑工作流时 | |
push: | |
paths: | |
- 'Plain Craft Launcher 2/**' | |
- '.github/workflows/**' | |
# 新的PR修改代码或编辑工作流时 | |
pull_request: | |
paths: | |
- 'Plain Craft Launcher 2/**' | |
- '.github/workflows/**' | |
# 手动触发时 | |
workflow_dispatch: | |
# 定义工作列表 | |
jobs: | |
# 唯一的工作:build | |
build: | |
strategy: | |
# 定义矩阵,矩阵中每组都会单独执行,并使矩阵本身成为可用的上下文 | |
matrix: | |
# 五个编译选项 | |
configuration: [Debug, Release, Snapshot, BETA, ReleaseUpdate] | |
# 显然,只有Windows才能构建.NET Framework程序 | |
runs-on: windows-latest | |
# 定义步骤列表 | |
steps: | |
- name: 签出仓库 | |
# 调用actions/checkout仓库的调用预设工作流 | |
uses: actions/checkout@v4 | |
# 调用参数 | |
with: | |
# 只签出第一层 | |
fetch-depth: 0 | |
- name: 导出提交哈希 | |
shell: bash | |
run: | | |
Describe=`git describe --tags` | |
echo "Describe=$Describe" >> $GITHUB_ENV | |
continue-on-error: true | |
# 在极少数情况下,可能没有可用的哈希。详见 https://github.com/Silverteal/PCL2/actions/runs/9518525229/job/26239628548 | |
- name: 若导出提交哈希出错,导出备用描述字符串 | |
shell: bash | |
run: | | |
echo "Describe=unknown" >> $GITHUB_ENV | |
if: ${{ failure() }} | |
- name: 配置 MSBuild | |
uses: microsoft/setup-msbuild@v2 | |
with: | |
# 生成工具使用64位架构 | |
msbuild-architecture: x64 | |
- name: 编译源代码 | |
# 直接运行Powershell命令 | |
# ${{}}括号内的是工作流表达式,此处即当前运行的矩阵的参数,运行时将直接替换 | |
# $env:是Powershell读取环境变量的语法 | |
run: msbuild $env:Project_Path /p:Configuration=${{ matrix.configuration }} | |
env: | |
# 设置单个步骤的环境变量 | |
# 由于路径包含空格,使用环境变量传入路径,避免令人疑惑的引号写法 | |
Project_Path: Plain Craft Launcher 2\Plain Craft Launcher 2.vbproj | |
- name: 打包并上传编译产物 | |
uses: actions/upload-artifact@v4 | |
with: | |
# 文件名格式示例:pcl2_autobuild_a1b23c4_Snapshot.zip | |
name: pcl2_autobuild_${{ env.Describe }}_${{ matrix.configuration }} | |
path: Plain Craft Launcher 2\obj\${{ matrix.configuration }}\Plain Craft Launcher 2.exe | |