Repository navigation
82 lines (71 loc) · 3.76 KB
/
Copy pathrelease.yml
File metadata and controls
82 lines (71 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 打 v* tag 推送后自动发布:windows-latest 构建单文件 exe → GitHub Release → CNB Release(镜像)。
# 发布文案 = CHANGELOG.md 中该 tag 的段落(手写,缺失/为空直接 fail)。
# CNB_TOKEN secret 需要 repo-code 读写(推 tag)+ repo-contents 读写(创建 release / 上传附件)。
name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write # GITHUB_TOKEN 创建 GitHub Release 所需
jobs:
release:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # 推 tag 到 CNB 镜像需要完整历史(浅克隆缺祖先提交无法推送)
# 发版 tag 必须与 csproj <Version> 一致(版本号唯一来源,SDK 据此生成
# AssemblyInformationalVersion —— 软件内"关于"版本号)——不一致直接失败,
# 绝不让"关于"版本号和发版标签脱节。
- name: Verify tag matches csproj Version
shell: pwsh
run: |
$tag = $env:GITHUB_REF_NAME -replace '^v', ''
$m = Select-String -Path task_monitor.csproj -Pattern '<Version>([^<]+)</Version>'
if (-not $m) { throw '<Version> not found in task_monitor.csproj' }
$ver = $m.Matches[0].Groups[1].Value
if ($ver -ne $tag) { throw "tag $($env:GITHUB_REF_NAME) != csproj <Version> $ver —— 先发版前同步 task_monitor.csproj" }
Write-Host "version check OK: $ver"
- name: Build
run: dotnet build -c Release
- name: Changelog and asset
shell: pwsh
run: |
$tag = $env:GITHUB_REF_NAME
$exe = "bin/Release/net48/task_monitor.exe"
if (-not (Test-Path $exe)) { throw "artifact missing: $exe" }
# release 文案 = CHANGELOG.md 中该 tag 的段落(下一个 '## ' 标题前为止)。
# 缺失/为空直接 fail,绝不悄悄回退到自动提取 commit 列表。
$heading = "^##\s+$([regex]::Escape($tag))\s*$"
$inSection = $false
$section = foreach ($line in Get-Content CHANGELOG.md -Encoding UTF8) {
if ($line -match '^##\s') {
if ($inSection) { break }
$inSection = $line -match $heading
} elseif ($inSection) { $line }
}
if (-not $inSection) { throw "CHANGELOG.md 缺少 '## $tag' 段落 —— 发版前先写好该版本文案" }
$notes = ($section -join "`n").Trim()
if (-not $notes) { throw "CHANGELOG.md 的 '## $tag' 段落为空 —— 发版前先写好该版本文案" }
# 走文件而非 GITHUB_ENV:不受多行 heredoc 定界符/大小限制
Set-Content -Path release-notes.md -Value $notes -Encoding utf8 -NoNewline
# 附件名带架构(当前仅 x64)
$asset = "task_monitor-$tag-x64.exe"
Copy-Item $exe $asset
"ASSET_NAME=$asset" >> $env:GITHUB_ENV
Write-Host "asset: $asset ($([math]::Round((Get-Item $asset).Length / 1MB, 2)) MB)"
Write-Host "---- release notes ----`n$notes`n-----------------------"
- name: Create GitHub Release
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create $env:GITHUB_REF_NAME $env:ASSET_NAME --title $env:GITHUB_REF_NAME --notes-file release-notes.md
- name: Publish Release to CNB
shell: pwsh
env:
CNB_TOKEN: ${{ secrets.CNB_TOKEN }}
run: |
$tag = $env:GITHUB_REF_NAME
# CNB 的 release 挂在 tag 上 —— 先把 tag(连同缺失的祖先提交)推到 CNB 镜像
git push "https://cnb:$($env:CNB_TOKEN)@cnb.cool/linesoft2/TaskMonitor.git" "$tag"
tools/publish-cnb-release.ps1 -Tag $tag -Notes (Get-Content -Raw release-notes.md)