Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Release

# main に入ったら、server/Mado.csproj の版のタグがまだ無ければ MSI を作ってリリースする(タグもここで打つ)。
# 版を上げない変更(依存の更新など)はリリースしない。
# v1.2.3 の形のタグを push したら、その版で MSI を作ってリリースする。版の数字はタグから取り、csproj には書かない。
# 署名の鍵を使うので、main に入っているコミットに打たれたタグだけを出す。
# - mado.msi: サービス・タスクトレイ・ファイアウォール・ProgramData の権限まで入れる(installer/mado.wxs)
# - mado.msi.sig: ECDSA P-256 の署名(`mado <タグ> <MSI の SHA-256>`)。動いている mado はこれを確かめてから入れる(server/Updater.cs)
# - mado.msi.sha256 と出どころの証明(gh attestation verify): 入れる側(gitops の setup.ps1)が確かめる
on:
push:
branches: [main]
workflow_dispatch:
tags: ["v*"]

permissions: {}

Expand All @@ -18,27 +17,26 @@ concurrency:

jobs:
release:
# 署名鍵を使うので main だけ(workflow_dispatch をほかの枝から動かしても、main に無いコミットを出さない)
if: github.ref == 'refs/heads/main'
runs-on: windows-latest
permissions:
contents: write
id-token: write
attestations: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- id: version
shell: pwsh
run: |
$version = ([xml](Get-Content server/Mado.csproj)).Project.PropertyGroup.Version | Where-Object { $_ } | Select-Object -First 1
"tag=v$version" >> $env:GITHUB_OUTPUT
# その版のリリースがもうあれば何もしない
gh release view "v$version" --repo $env:GITHUB_REPOSITORY 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) { "v$version はもうある。リリースしない"; "release=false" >> $env:GITHUB_OUTPUT }
else { "release=true" >> $env:GITHUB_OUTPUT }
exit 0
env:
GH_TOKEN: ${{ github.token }}
$tag = $env:GITHUB_REF_NAME
if ($tag -notmatch '^v\d+\.\d+\.\d+$') { throw "タグは v1.2.3 の形にする: $tag" }
# main に無いコミットは出さない(署名の鍵を使うので)
git merge-base --is-ancestor $env:GITHUB_SHA origin/main
if ($LASTEXITCODE -ne 0) { throw "$tag のコミットが main に無い" }
"tag=$tag" >> $env:GITHUB_OUTPUT
"version=$($tag.TrimStart('v'))" >> $env:GITHUB_OUTPUT
"release=true" >> $env:GITHUB_OUTPUT
- if: steps.version.outputs.release == 'true'
uses: oven-sh/setup-bun@v2
- if: steps.version.outputs.release == 'true'
Expand All @@ -62,9 +60,9 @@ jobs:
- if: steps.version.outputs.release == 'true'
run: dotnet run --project tests/Mado.Tests.csproj
- if: steps.version.outputs.release == 'true'
run: dotnet publish server/Mado.csproj -c Release -r win-x64 -o publish
run: dotnet publish server/Mado.csproj -c Release -r win-x64 -o publish -p:Version=${{ steps.version.outputs.version }}
- if: steps.version.outputs.release == 'true'
run: dotnet publish tray/MadoTray.csproj -c Release -r win-x64 -o publish
run: dotnet publish tray/MadoTray.csproj -c Release -r win-x64 -o publish -p:Version=${{ steps.version.outputs.version }}
- if: steps.version.outputs.release == 'true'
shell: pwsh
run: |
Expand All @@ -75,7 +73,7 @@ jobs:
wix extension add -g WixToolset.Firewall.wixext/5.0.2
wix extension add -g WixToolset.Util.wixext/5.0.2
wix build installer/mado.wxs -arch x64 -ext WixToolset.Firewall.wixext -ext WixToolset.Util.wixext `
-d Version=$("${{ steps.version.outputs.tag }}".TrimStart('v')) -d PublishDir=publish -o dist/mado.msi
-d Version=${{ steps.version.outputs.version }} -d PublishDir=publish -o dist/mado.msi
$sha = (Get-FileHash dist/mado.msi -Algorithm SHA256).Hash.ToLower()
$sha + ' mado.msi' | Set-Content dist/mado.msi.sha256 -NoNewline
# 自動更新のための署名。秘密鍵は secret の MADO_SIGNING_KEY(PKCS#8 の base64)。署名したあと、exe に入れた公開鍵で確かめ直す
Expand All @@ -99,10 +97,10 @@ jobs:
uses: actions/attest-build-provenance@v4
with:
subject-path: dist/mado.msi
# タグはここで、このコミットに打つ
# タグは push されたものを使う
- if: steps.version.outputs.release == 'true'
shell: pwsh
run: gh release create $env:TAG dist/mado.msi dist/mado.msi.sha256 dist/mado.msi.sig --target $env:GITHUB_SHA --generate-notes
run: gh release create $env:TAG dist/mado.msi dist/mado.msi.sha256 dist/mado.msi.sig --verify-tag --generate-notes
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ dotnet run tray/make-icon.cs tray/mado.ico # アイコンを作り直す
bun run check # 画面の biome、tsc、テスト(bun test web)
```

main にマージすると自動でリリースする。`server/Mado.csproj` の `<Version>` を上げていれば、その版のタグを打って MSI を出す(`release.yml`)。版を上げていなければリリースしない。
リリースは `v1.2.3` の形のタグを push すると自動で行う(`git tag v1.2.3 && git push origin v1.2.3`)。版の数字はタグから取るので、csproj は書き換えない。main に入っているコミットに打ったタグだけを出す(`release.yml`)。

bun や .NET が手元に無ければ、`oven/bun` と `mcr.microsoft.com/dotnet/sdk:10.0` のコンテナで同じことができる。
exe(Native AOT)と MSI は Windows でしか作れないので、CI(`windows-latest`)で作る。
Expand Down
3 changes: 2 additions & 1 deletion server/Mado.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>mado</AssemblyName>
<RootNamespace>Mado</RootNamespace>
<Version>0.8.6</Version>
<!-- 版はリリースのときにタグ(v1.2.3)から入れる(release.yml)。手元のビルドは 0.0.0 -->
<Version>0.0.0</Version>
<!-- 常駐 1 プロセスで動的コードも無いので Native AOT。exe 1 つで .NET を入れなくても動く -->
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
Expand Down
3 changes: 2 additions & 1 deletion tray/MadoTray.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>mado-tray</AssemblyName>
<RootNamespace>Mado.Tray</RootNamespace>
<Version>0.8.6</Version>
<!-- 版はリリースのときにタグ(v1.2.3)から入れる(release.yml)。手元のビルドは 0.0.0 -->
<Version>0.0.0</Version>
<!-- Win32 を直接呼ぶ(WinForms は Native AOT に対応していない) -->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishAot>true</PublishAot>
Expand Down
Loading