-
Notifications
You must be signed in to change notification settings - Fork 7
270 lines (230 loc) · 10.7 KB
/
release.yml
File metadata and controls
270 lines (230 loc) · 10.7 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
name: Release new version
on:
pull_request:
types: [closed]
branches: [main]
env:
DOTNET_VERSION: 10.0
STANDALONE_PROJECT: StarMap.Loader/StarMap.Loader.csproj
LAUNCHER_PROJECT: StarMap.Launcher/StarMap.Launcher.csproj
API_PROJECT: StarMap.API/StarMap.API.csproj
STANDALONE_OUTPUT_PATH: ./publish/standalone
LAUNCHER_OUTPUT_PATH: ./publish/launcher
OUTPUT_PATH: ./publish
NUGET_SOURCE: "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
EXCLUDE: "*.pdb *.xml"
jobs:
build:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.version.outputs.new_version }}
prev_version: ${{ steps.version.outputs.prev_version }}
hash_version: ${{ steps.version.outputs.hash_version }}
api_changed: ${{ steps.api_check.outputs.api_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Determine version bump
id: version
run: |
# Be defensive and robust: use awk to split version numbers and always quote $GITHUB_OUTPUT
git fetch --tags || true
current=$(git describe --tags --abbrev=0 2>/dev/null || true)
if [ -z "$current" ]; then
echo "No tags found, defaulting to 0.0.0"
current="0.0.0"
fi
# Remove leading 'v' then extract parts using awk
ver=${current#v}
major=$(printf "%s" "$ver" | awk -F. '{print $1+0}')
minor=$(printf "%s" "$ver" | awk -F. '{print $2+0}')
patch=$(printf "%s" "$ver" | awk -F. '{print $3+0}')
# Determine bump type from PR labels (safe interpolation)
LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}"
if printf "%s" "$LABELS" | grep -q "major"; then
major=$((major+1)); minor=0; patch=0; type="major"
elif printf "%s" "$LABELS" | grep -q "minor"; then
minor=$((minor+1)); patch=0; type="minor"
else
patch=$((patch+1)); type="patch"
fi
new_version="${major}.${minor}.${patch}"
echo "Next version: $new_version"
echo "RC version: $hash_version"
echo "prev_version=$current" >> $GITHUB_OUTPUT
echo "new_version=$new_version" >> $GITHUB_OUTPUT
- name: Tag and push new version
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
NEW_VERSION="${{ steps.version.outputs.new_version }}"
git tag "$NEW_VERSION"
git push origin "$NEW_VERSION"
- name: Setup NuGet source
run: |
dotnet nuget add source \
--username ${{ secrets.ORG_PACKAGE_USERNAME }} \
--password ${{ secrets.ORG_PACKAGE_TOKEN }} \
--store-password-in-clear-text \
--name github "${{ env.NUGET_SOURCE }}"
- name: Build launcher
run: |
dotnet publish ${{ env.LAUNCHER_PROJECT }} \
-c Release \
-o ${{ env.LAUNCHER_OUTPUT_PATH }} \
-r win-x64 \
--self-contained false \
/p:PackageVersion=${{ steps.version.outputs.new_version }} \
/p:Version=${{ steps.version.outputs.new_version }} \
/p:AssemblyVersion=${{ steps.version.outputs.new_version }} \
/p:FileVersion=${{ steps.version.outputs.new_version }}
- name: Build standalone
run: |
dotnet publish ${{ env.STANDALONE_PROJECT }} \
-c Release \
-o ${{ env.STANDALONE_OUTPUT_PATH }} \
-r win-x64 \
--self-contained false \
/p:PackageVersion=${{ steps.version.outputs.new_version }} \
/p:Version=${{ steps.version.outputs.new_version }} \
/p:AssemblyVersion=${{ steps.version.outputs.new_version }} \
/p:FileVersion=${{ steps.version.outputs.new_version }}
- name: Rename executables
run: |
mv ${{ env.LAUNCHER_OUTPUT_PATH }}/StarMap.Launcher.exe ${{ env.LAUNCHER_OUTPUT_PATH }}/StarMap.exe
mv ${{ env.STANDALONE_OUTPUT_PATH }}/StarMap.Loader.exe ${{ env.STANDALONE_OUTPUT_PATH }}/StarMap.exe
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: publish
path: |
${{ env.LAUNCHER_OUTPUT_PATH }}
${{ env.STANDALONE_OUTPUT_PATH }}
version.txt
retention-days: 1
- name: Check whether StarMap.API changed since previous tag
id: api_check
run: |
current="${{ steps.version.outputs.new_version }}"
prev="${{ steps.version.outputs.prev_version }}"
echo "previous_tag=$prev" >> $GITHUB_OUTPUT
if [ -z "$prev" ]; then
echo "api_changed=true" >> $GITHUB_OUTPUT
exit 0
fi
echo "Previous tag: $prev"
echo "Current commit: $current"
diff=$(git diff --name-only "$prev" "$current")
{
echo "diff_files<<EOF"
echo "$diff"
echo "EOF"
} >> "$GITHUB_OUTPUT"
if echo "$diff" | grep -qE '^StarMap.API/|^StarMap.API.csproj'; then
echo "api_changed=true" >> $GITHUB_OUTPUT
else
echo "api_changed=false" >> $GITHUB_OUTPUT
fi
publish-nuget:
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.api_changed == true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: publish
path: ./build_artifacts
- name: Setup NuGet source
run: |
dotnet nuget add source \
--username ${{ secrets.ORG_PACKAGE_USERNAME }} \
--password ${{ secrets.ORG_PACKAGE_TOKEN }} \
--store-password-in-clear-text \
--name github "${{ env.NUGET_SOURCE }}"
- name: Pack and push StarMap.API (if changed)
run: |
dotnet restore StarMap.API/StarMap.API.csproj
dotnet pack StarMap.API/StarMap.API.csproj \
-c Release \
-o ./nupkg \
/p:PackageVersion=${{ needs.build.outputs.new_version }} \
/p:Version=${{ needs.build.outputs.new_version }} \
/p:AssemblyVersion=${{ needs.build.outputs.new_version }} \
/p:FileVersion=${{ needs.build.outputs.new_version }}
dotnet nuget push ./nupkg/*.nupkg \
--source https://api.nuget.org/v3/index.json \
--api-key "${{ secrets.NUGET_API_KEY }}" \
--skip-duplicate
release-zip:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: publish
path: ./build_artifacts
- name: Ensure zip is available
run: |
sudo apt-get update -y
sudo apt-get install -y zip
- name: Package launcher ZIP
run: |
cd ./build_artifacts/${{ env.LAUNCHER_OUTPUT_PATH }}
zip -r $GITHUB_WORKSPACE/StarMapLauncher-${{ needs.build.outputs.new_version }}.zip . -x ${{ env.EXCLUDE }}
cd -
- name: Package standalone ZIP
run: |
cd ./build_artifacts/${{ env.STANDALONE_OUTPUT_PATH }}
zip -r $GITHUB_WORKSPACE/StarMapStandalone-${{ needs.build.outputs.new_version }}.zip . -x ${{ env.EXCLUDE }}
cd -
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.build.outputs.new_version }}
name: Release ${{ needs.build.outputs.new_version }}
body: |
Automated release for version ${{ needs.build.outputs.new_version }}
Triggered by PR #${{ github.event.pull_request.number }}
files: |
StarMapLauncher-${{ needs.build.outputs.new_version }}.zip
StarMapStandalone-${{ needs.build.outputs.new_version }}.zip
build-release-installer:
runs-on: windows-latest
needs: build
steps:
- uses: actions/checkout@v4
# Download the published files from Linux job
- name: Download publish folder
uses: actions/download-artifact@v4
with:
name: publish
path: ./build_artifacts
# Install Inno Setup via Chocolatey
- name: Install Inno Setup
run: choco install innosetup --yes
# Build the installer using the same version as ZIP
- name: Build Inno Setup Installer
run: |
ISCC.exe installer\WindowsInstaller.iss /dAppVersion=${{ needs.build.outputs.new_version }} /dOutputName=StarMap-${{ needs.build.outputs.new_version }}
# Attach installer to the release
- name: Attach installer to GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.build.outputs.new_version }}
files: installer/dist/StarMap-${{ needs.build.outputs.new_version }}.exe