-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (118 loc) · 4.4 KB
/
Copy pathdotnet-release.yml
File metadata and controls
140 lines (118 loc) · 4.4 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Release .NET Project
permissions:
contents: write
on:
push:
branches:
- 'release/*'
jobs:
build:
name: Build & Zip Projects
runs-on: ubuntu-latest
strategy:
matrix:
os: [windows, macos, ubuntu]
arch: [x64, arm64]
outputs:
version: ${{ steps.extract_version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ vars.DOTNET_VERSION }}
- name: Extract version from branch
id: extract_version
shell: pwsh
run: |
$version = $env:GITHUB_REF -replace '^refs/heads/release/', ''
Add-Content $env:GITHUB_OUTPUT "version=$version"
- name: Update project versions
shell: pwsh
run: |
$version = "${{ steps.extract_version.outputs.version }}"
Write-Host "Updating all projects to version $version"
Get-ChildItem -Recurse -Filter *.csproj | ForEach-Object {
$proj = $_.FullName
$content = Get-Content $proj
if ($content -match "<AssemblyVersion>.*</AssemblyVersion>") {
$content -replace '<AssemblyVersion>.*</AssemblyVersion>', "<AssemblyVersion>$version</AssemblyVersion>" | Set-Content $proj
} else {
$content -replace '<PropertyGroup>', "<PropertyGroup>`n <AssemblyVersion>$version</AssemblyVersion>" | Set-Content $proj
}
}
- name: Build and Zip Projects
shell: pwsh
run: |
$version = "${{ steps.extract_version.outputs.version }}"
$os = "${{ matrix.os }}"
$arch = "${{ matrix.arch }}"
$osName = switch ($os) {
"windows" { "win" }
"macos" { "mac" }
"ubuntu" { "linux" }
}
$rid = switch ($os) {
"windows" { "win-$arch" }
"macos" { "osx-$arch" }
"ubuntu" { "linux-$arch" }
}
$projects = @(
@{ name="cmd"; path="Parallel.Cli/Parallel.Cli.csproj" }
)
$distRoot = Join-Path $env:GITHUB_WORKSPACE "dist"
New-Item -ItemType Directory -Force -Path $distRoot
foreach ($proj in $projects) {
$outputDir = Join-Path $env:GITHUB_WORKSPACE "dist/$($proj.name)/$os/$arch"
New-Item -ItemType Directory -Force -Path $outputDir
dotnet publish $proj.path -c Release -r $rid /p:PublishSingleFile=true /p:DebugType=None /p:DebugSymbols=false /p:PublishDir=$outputDir
$repoName = $repoName = "${{ github.event.repository.name }}"
$zipName = "$repoName-$version-$($proj.name)-$osName-$arch.zip"
Compress-Archive -Path "$outputDir/*" -DestinationPath "$distRoot/$zipName" -Force
}
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}
path: dist/*.zip
if-no-files-found: error
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: release
- name: Flatten release folder
shell: pwsh
run: |
Get-ChildItem -Recurse release -Filter '*.zip' | ForEach-Object {
Copy-Item $_.FullName -Destination "release/$($_.Name)" -Force
}
- name: Generate Release Notes
id: release_notes
shell: pwsh
run: |
$version = "${{ needs.build.outputs.version }}"
$notes = ""
if (Test-Path "CHANGELOG.md") {
$content = Get-Content "CHANGELOG.md" -Raw
if ($content -match "## \[$version\](.*?)(## \[|$)") {
$notes = $matches[1].Trim()
}
}
Add-Content -Path $env:GITHUB_OUTPUT -Value "notes=$notes"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.build.outputs.version }}
name: "${{ github.event.repository.name }} ${{ needs.build.outputs.version }}"
body: ${{ steps.release_notes.outputs.notes }}
files: release/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}