-
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (69 loc) · 3.3 KB
/
release.yml
File metadata and controls
85 lines (69 loc) · 3.3 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
83
84
85
name: TimeTask Auto Release
on:
push:
branches: [ "master", "main" ]
workflow_dispatch:
permissions:
contents: write
jobs:
release:
runs-on: windows-latest
env:
Main_Project_Path: TimeTask.csproj
Build_Configuration: Release
Build_Platform: AnyCPU
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2
- name: Restore
run: msbuild $env:Main_Project_Path /t:Restore /p:Configuration=$env:Build_Configuration /p:Platform=$env:Build_Platform
- name: Build
run: msbuild $env:Main_Project_Path /p:Configuration=$env:Build_Configuration /p:Platform=$env:Build_Platform /m
- name: Resolve version and release metadata
id: meta
shell: pwsh
run: |
$assemblyInfoPath = Join-Path $env:GITHUB_WORKSPACE "Properties\AssemblyInfo.cs"
if (-not (Test-Path $assemblyInfoPath)) {
throw "AssemblyInfo.cs not found: $assemblyInfoPath"
}
$assemblyInfo = Get-Content $assemblyInfoPath -Raw
$versionMatch = [regex]::Match($assemblyInfo, 'AssemblyFileVersion\("(?<v>\d+\.\d+\.\d+)(?:\.\d+)?"\)')
if (-not $versionMatch.Success) {
throw "Unable to parse AssemblyFileVersion from $assemblyInfoPath"
}
$baseVersion = $versionMatch.Groups['v'].Value
$buildNo = "${{ github.run_number }}"
$shortSha = "${{ github.sha }}".Substring(0, 7)
$tagName = "v$baseVersion-build.$buildNo"
$releaseName = "TimeTask $baseVersion (build $buildNo)"
$assetName = "TimeTask-win-x64-$baseVersion-build.$buildNo-$shortSha.zip"
"base_version=$baseVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
"tag_name=$tagName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
"release_name=$releaseName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
"asset_name=$assetName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
- name: Package app
id: package
shell: pwsh
run: |
$outputDir = Join-Path $env:GITHUB_WORKSPACE "bin\Release"
if (-not (Test-Path (Join-Path $outputDir "TimeTask.exe"))) {
throw "TimeTask.exe not found in $outputDir"
}
$stagingDir = Join-Path $env:RUNNER_TEMP "TimeTask"
if (Test-Path $stagingDir) { Remove-Item $stagingDir -Recurse -Force }
New-Item -ItemType Directory -Path $stagingDir -Force | Out-Null
Copy-Item -Path (Join-Path $outputDir "*") -Destination $stagingDir -Recurse -Force
$zipPath = Join-Path $env:GITHUB_WORKSPACE "${{ steps.meta.outputs.asset_name }}"
if (Test-Path $zipPath) { Remove-Item $zipPath -Force }
Compress-Archive -Path (Join-Path $stagingDir "*") -DestinationPath $zipPath -Force
"zip_path=$zipPath" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
- name: Create release and upload asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.meta.outputs.tag_name }}
name: ${{ steps.meta.outputs.release_name }}
files: ${{ steps.package.outputs.zip_path }}
generate_release_notes: true