Skip to content

Commit 7c0a9f9

Browse files
committed
add auto release
1 parent dc7109c commit 7c0a9f9

1 file changed

Lines changed: 38 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
name: TimeTask Release
1+
name: TimeTask Auto Release
22

33
on:
44
push:
5-
tags:
6-
- "v*"
5+
branches: [ "master", "main" ]
76
workflow_dispatch:
87

98
permissions:
@@ -16,7 +15,6 @@ jobs:
1615
Main_Project_Path: TimeTask.csproj
1716
Build_Configuration: Release
1817
Build_Platform: AnyCPU
19-
Artifact_Name: TimeTask-win-x64.zip
2018

2119
steps:
2220
- name: Checkout
@@ -31,7 +29,35 @@ jobs:
3129
- name: Build
3230
run: msbuild $env:Main_Project_Path /p:Configuration=$env:Build_Configuration /p:Platform=$env:Build_Platform /m
3331

32+
- name: Resolve version and release metadata
33+
id: meta
34+
shell: pwsh
35+
run: |
36+
$assemblyInfoPath = Join-Path $env:GITHUB_WORKSPACE "Properties\AssemblyInfo.cs"
37+
if (-not (Test-Path $assemblyInfoPath)) {
38+
throw "AssemblyInfo.cs not found: $assemblyInfoPath"
39+
}
40+
41+
$assemblyInfo = Get-Content $assemblyInfoPath -Raw
42+
$versionMatch = [regex]::Match($assemblyInfo, 'AssemblyFileVersion\("(?<v>\d+\.\d+\.\d+)(?:\.\d+)?"\)')
43+
if (-not $versionMatch.Success) {
44+
throw "Unable to parse AssemblyFileVersion from $assemblyInfoPath"
45+
}
46+
47+
$baseVersion = $versionMatch.Groups['v'].Value
48+
$buildNo = "${{ github.run_number }}"
49+
$shortSha = "${{ github.sha }}".Substring(0, 7)
50+
$tagName = "v$baseVersion-build.$buildNo"
51+
$releaseName = "TimeTask $baseVersion (build $buildNo)"
52+
$assetName = "TimeTask-win-x64-$baseVersion-build.$buildNo-$shortSha.zip"
53+
54+
"base_version=$baseVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
55+
"tag_name=$tagName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
56+
"release_name=$releaseName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
57+
"asset_name=$assetName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
58+
3459
- name: Package app
60+
id: package
3561
shell: pwsh
3662
run: |
3763
$outputDir = Join-Path $env:GITHUB_WORKSPACE "bin\Release"
@@ -40,15 +66,20 @@ jobs:
4066
}
4167
4268
$stagingDir = Join-Path $env:RUNNER_TEMP "TimeTask"
69+
if (Test-Path $stagingDir) { Remove-Item $stagingDir -Recurse -Force }
4370
New-Item -ItemType Directory -Path $stagingDir -Force | Out-Null
4471
Copy-Item -Path (Join-Path $outputDir "*") -Destination $stagingDir -Recurse -Force
4572
46-
$zipPath = Join-Path $env:GITHUB_WORKSPACE $env:Artifact_Name
73+
$zipPath = Join-Path $env:GITHUB_WORKSPACE "${{ steps.meta.outputs.asset_name }}"
4774
if (Test-Path $zipPath) { Remove-Item $zipPath -Force }
4875
Compress-Archive -Path (Join-Path $stagingDir "*") -DestinationPath $zipPath -Force
4976
50-
- name: Create release
77+
"zip_path=$zipPath" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
78+
79+
- name: Create release and upload asset
5180
uses: softprops/action-gh-release@v2
5281
with:
53-
files: TimeTask-win-x64.zip
82+
tag_name: ${{ steps.meta.outputs.tag_name }}
83+
name: ${{ steps.meta.outputs.release_name }}
84+
files: ${{ steps.package.outputs.zip_path }}
5485
generate_release_notes: true

0 commit comments

Comments
 (0)