Skip to content

Commit 652a772

Browse files
committed
ci: add GitHub Actions build and release workflow
1 parent 3ac6167 commit 652a772

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [ main, master, refactor/improvements ]
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
branches: [ main, master ]
10+
workflow_dispatch:
11+
12+
env:
13+
PROJECT_PATH: src/EnergyStarZ/EnergyStarZ.csproj
14+
OUTPUT_DIR: publish
15+
16+
jobs:
17+
build:
18+
name: Build ${{ matrix.runtime }}-${{ matrix.arch }}
19+
runs-on: windows-latest
20+
21+
strategy:
22+
matrix:
23+
include:
24+
# x64 自带运行时
25+
- arch: x64
26+
runtime: win-x64
27+
self_contained: true
28+
label: x64-SelfContained
29+
30+
# x64 框架依赖
31+
- arch: x64
32+
runtime: win-x64
33+
self_contained: false
34+
label: x64-FrameworkDependent
35+
36+
# x86 自带运行时
37+
- arch: x86
38+
runtime: win-x86
39+
self_contained: true
40+
label: x86-SelfContained
41+
42+
# x86 框架依赖
43+
- arch: x86
44+
runtime: win-x86
45+
self_contained: false
46+
label: x86-FrameworkDependent
47+
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
with:
52+
fetch-depth: 0
53+
54+
- name: Setup .NET
55+
uses: actions/setup-dotnet@v4
56+
with:
57+
dotnet-version: '10.0.x'
58+
59+
- name: Restore dependencies
60+
run: dotnet restore ${{ env.PROJECT_PATH }}
61+
62+
- name: Build
63+
run: dotnet build ${{ env.PROJECT_PATH }} -c Release --no-restore
64+
65+
- name: Publish
66+
run: |
67+
dotnet publish ${{ env.PROJECT_PATH }} `
68+
-c Release `
69+
-r ${{ matrix.runtime }} `
70+
-o "${{ env.OUTPUT_DIR }}/${{ matrix.label }}" `
71+
--self-contained ${{ matrix.self_contained }} `
72+
-p:PublishSingleFile=true `
73+
-p:PublishTrimmed=false `
74+
-p:IncludeNativeLibrariesForSelfExtract=true `
75+
-p:DebugType=none `
76+
-p:EnableCompressionInSingleFile=true
77+
78+
- name: Copy config files
79+
run: |
80+
Copy-Item "src/EnergyStarZ/appsettings.json" "${{ env.OUTPUT_DIR }}/${{ matrix.label }}/" -Force
81+
Copy-Item "src/EnergyStarZ/Resources/Localization.json" "${{ env.OUTPUT_DIR }}/${{ matrix.label }}/Resources/" -Force
82+
83+
- name: Create ZIP archive
84+
run: |
85+
$version = if ($env:GITHUB_REF -match 'refs/tags/v(.*)') { $matches[1] } else { "dev-${{ github.sha.Substring(0,7) }}" }
86+
$zipName = "EnergyStarZ-${{ matrix.label }}-$version.zip"
87+
Compress-Archive -Path "${{ env.OUTPUT_DIR }}/${{ matrix.label }}/*" -DestinationPath "${{ env.OUTPUT_DIR }}/$zipName" -Force
88+
echo "ZIP_NAME=$zipName" >> $env:GITHUB_ENV
89+
90+
- name: Upload artifact
91+
uses: actions/upload-artifact@v4
92+
with:
93+
name: ${{ matrix.label }}
94+
path: ${{ env.OUTPUT_DIR }}/${{ env.ZIP_NAME }}
95+
retention-days: 30
96+
97+
release:
98+
name: Create Release
99+
needs: build
100+
runs-on: ubuntu-latest
101+
if: startsWith(github.ref, 'refs/tags/v')
102+
103+
steps:
104+
- name: Download artifacts
105+
uses: actions/download-artifact@v4
106+
with:
107+
path: artifacts
108+
109+
- name: Create GitHub Release
110+
uses: softprops/action-gh-release@v2
111+
with:
112+
files: artifacts/**/*.zip
113+
draft: false
114+
prerelease: false
115+
generate_release_notes: true
116+
env:
117+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)