-
-
Notifications
You must be signed in to change notification settings - Fork 1
202 lines (173 loc) · 6.59 KB
/
Copy pathrelease.yml
File metadata and controls
202 lines (173 loc) · 6.59 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Release
# MANUAL TRIGGER ONLY - Creates a new GitHub Release with desktop app artifacts.
# Go to Actions → Release → Run workflow → Enter version (e.g., 0.1.0)
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 0.1.0) - without "v" prefix'
required: true
type: string
skip_tag:
description: 'Skip tag creation (assumes you already pushed the tag manually)'
required: false
type: boolean
default: false
jobs:
validate:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
version: ${{ steps.validate.outputs.version }}
tag: ${{ steps.validate.outputs.tag }}
steps:
- name: Validate version format
id: validate
run: |
VERSION="${{ inputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid version format. Use semantic versioning (e.g., 0.1.0)"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
echo "✅ Version: $VERSION, Tag: v$VERSION"
build-desktop:
needs: validate
runs-on: windows-2025-vs2026
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x'
- name: Publish Desktop App (win-x64)
shell: pwsh
run: |
dotnet publish OpenSourceToolkit.NET/OpenSourceToolkit.NET.csproj `
-c Release `
-r win-x64 `
--self-contained true `
-p:PublishSingleFile=true `
-p:IncludeNativeLibrariesForSelfExtract=true `
-p:EnableCompressionInSingleFile=true `
-p:UseLocalFlowery=false `
-o ./publish
- name: Zip artifact
shell: pwsh
run: |
$artifactName = "OpenSourceToolkit.NET-Desktop-Windows-x64"
Compress-Archive -Path ./publish/* -DestinationPath "./$artifactName.zip"
- name: Upload desktop artifact
uses: actions/upload-artifact@v7
with:
name: OpenSourceToolkit.NET-Desktop-Windows-x64
path: |
./OpenSourceToolkit.NET-Desktop-Windows-x64.zip
publish:
needs: [validate, build-desktop]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Verify version in OpenSourceToolkit.NET.csproj
run: |
CSPROJ_VERSION=$(grep -oP '(?<=<Version>)[^<]+' OpenSourceToolkit.NET/OpenSourceToolkit.NET.csproj | head -n 1)
if [ -z "$CSPROJ_VERSION" ]; then
echo "::error::No <Version> found in OpenSourceToolkit.NET/OpenSourceToolkit.NET.csproj"
exit 1
fi
if [ "$CSPROJ_VERSION" != "${{ needs.validate.outputs.version }}" ]; then
echo "::error::Version mismatch! csproj has $CSPROJ_VERSION but you specified ${{ needs.validate.outputs.version }}"
echo "::error::Please update OpenSourceToolkit.NET/OpenSourceToolkit.NET.csproj first!"
exit 1
fi
echo "✅ Version matches: $CSPROJ_VERSION"
- name: Download all artifacts
uses: actions/download-artifact@v7
with:
path: ./release-artifacts
- name: Collect artifacts
run: |
mkdir -p ./final
find ./release-artifacts -name "*.zip" -exec cp {} ./final/ \;
echo "=== Release artifacts ==="
ls -la ./final/
- name: Extract changelog
id: changelog
run: |
VERSION="${{ needs.validate.outputs.version }}"
# Extract the section for this version from CHANGELOG.md
# Matches from "## [X.Y.Z]" until the next "## [" or end of file
CHANGELOG=$(awk -v ver="$VERSION" '
/^## \[/ {
if (found) exit
if ($0 ~ "\\[" ver "\\]") found=1
}
found && !/^## \[/ { print }
' CHANGELOG.md)
if [ -z "$CHANGELOG" ]; then
echo "::error::No changelog entry found for version $VERSION in CHANGELOG.md"
exit 1
fi
# Write to file for multiline support
echo "$CHANGELOG" > changelog_section.md
echo "✅ Extracted changelog for v$VERSION"
- name: Create and push tag
if: ${{ inputs.skip_tag != true }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ needs.validate.outputs.tag }}
git push origin ${{ needs.validate.outputs.tag }}
echo "✅ Created tag: ${{ needs.validate.outputs.tag }}"
- name: Skip tag creation
if: ${{ inputs.skip_tag == true }}
run: echo "⏭️ Skipping tag creation (tag already exists)"
- name: Build release notes
run: |
cat > release_notes.md << 'HEADER'
## 📋 What's Changed
HEADER
cat changelog_section.md >> release_notes.md
cat >> release_notes.md << 'FOOTER'
---
FOOTER
cat >> release_notes.md << 'APP'
## 🖥️ Desktop App (Windows)
Self-contained executable - no .NET installation required!
| Platform | Download |
|----------|----------|
| Windows x64 | `OpenSourceToolkit.NET-Desktop-Windows-x64.zip` |
APP
echo "=== Release Notes ==="
cat release_notes.md
- name: Load custom release notes
id: release_body
run: |
{
echo 'body<<EOF'
cat release_notes.md
echo ''
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.validate.outputs.tag }}
name: "v${{ needs.validate.outputs.version }}"
files: ./final/*
generate_release_notes: true
body: ${{ steps.release_body.outputs.body }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
echo "## 🎉 Release Complete!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tag:** ${{ needs.validate.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **Release:** ${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ needs.validate.outputs.tag }}" >> $GITHUB_STEP_SUMMARY