-
Notifications
You must be signed in to change notification settings - Fork 0
290 lines (258 loc) · 9.92 KB
/
Copy pathbuild-and-release.yml
File metadata and controls
290 lines (258 loc) · 9.92 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# =============================================================================
# Build and Release — Every push to main creates a release
# Single workflow. Single team. No silos.
# =============================================================================
name: Build and Release
on:
push:
branches: [master, main]
pull_request:
branches: [master, main]
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
jobs:
# ===========================================================================
# Build and Test (runs on every push/PR)
# ===========================================================================
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: Setup Java
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
- name: Install Android workload
run: dotnet workload install android
- name: Setup Keystore
id: keystore
shell: bash
run: |
if [[ -n "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" ]]; then
echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > "$GITHUB_WORKSPACE/android.keystore"
echo "path=$GITHUB_WORKSPACE/android.keystore" >> "$GITHUB_OUTPUT"
echo "available=true" >> "$GITHUB_OUTPUT"
else
keytool -genkey -v -keystore "$GITHUB_WORKSPACE/android.keystore" \
-alias myalias -keyalg RSA -keysize 2048 -validity 1 \
-storepass dummypassword -keypass dummypassword \
-dname "CN=Dummy, OU=Dummy, O=Dummy, L=Dummy, ST=Dummy, C=US" \
2>/dev/null || true
echo "path=$GITHUB_WORKSPACE/android.keystore" >> "$GITHUB_OUTPUT"
echo "available=false" >> "$GITHUB_OUTPUT"
fi
- name: Restore
run: dotnet restore
- name: Build
run: |
SIGN_PASS="${{ secrets.ANDROID_SIGNING_PASSWORD }}"
if [[ "${{ steps.keystore.outputs.available }}" != "true" ]]; then
SIGN_PASS="dummypassword"
fi
dotnet build --configuration Release --no-restore \
-p:BuildNumber=${{ github.run_number }} \
-p:AndroidKeyStore=true \
-p:AndroidSigningKeyStore="${{ steps.keystore.outputs.path }}" \
-p:AndroidSigningStorePass="$SIGN_PASS" \
-p:AndroidSigningKeyPass="$SIGN_PASS" \
-p:AndroidSigningKeyAlias=myalias
- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal
# ===========================================================================
# Build Desktop Releases
# ===========================================================================
build-desktop:
needs: build-and-test
if: github.event_name == 'push'
strategy:
matrix:
include:
- os: ubuntu-latest
rid: linux-x64
artifact: linux-x64
- os: ubuntu-latest
rid: linux-arm64
artifact: linux-arm64
- os: windows-latest
rid: win-x64
artifact: win-x64
- os: windows-latest
rid: win-arm64
artifact: win-arm64
- os: macos-latest
rid: osx-x64
artifact: osx-x64
- os: macos-latest
rid: osx-arm64
artifact: osx-arm64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: Publish
shell: bash
run: |
dotnet publish src/MyAdventure.Desktop/MyAdventure.Desktop.csproj \
--configuration Release \
-r ${{ matrix.rid }} \
--self-contained true \
-p:PublishSingleFile=true \
-p:IncludeNativeLibrariesForSelfExtract=true \
-p:Version=1.0.${{ github.run_number }} \
--output ./publish
- name: Create archive (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
cd ./publish
tar -czvf ../MyAdventure-${{ matrix.artifact }}.tar.gz .
- name: Create archive (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
Compress-Archive -Path ./publish/* -DestinationPath ./MyAdventure-${{ matrix.artifact }}.zip
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact }}
path: |
./MyAdventure-${{ matrix.artifact }}.tar.gz
./MyAdventure-${{ matrix.artifact }}.zip
if-no-files-found: error
retention-days: 7
# ===========================================================================
# Build Android APK
# ===========================================================================
build-android:
needs: build-and-test
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: Setup Java
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
- name: Install Android workload
run: dotnet workload install android
- name: Setup Keystore
id: keystore
shell: bash
run: |
if [[ -n "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" ]]; then
echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > "$GITHUB_WORKSPACE/android.keystore"
echo "path=$GITHUB_WORKSPACE/android.keystore" >> "$GITHUB_OUTPUT"
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=false" >> "$GITHUB_OUTPUT"
fi
- name: Build Android APK (Signed)
if: steps.keystore.outputs.available == 'true'
shell: bash
run: |
dotnet publish src/MyAdventure.Android/MyAdventure.Android.csproj \
--configuration Release \
-p:ApplicationVersion=${{ github.run_number }} \
-p:ApplicationDisplayVersion=1.0.${{ github.run_number }} \
-p:AndroidKeyStore=true \
-p:AndroidSigningKeyStore="${{ steps.keystore.outputs.path }}" \
-p:AndroidSigningStorePass="${{ secrets.ANDROID_SIGNING_PASSWORD }}" \
-p:AndroidSigningKeyPass="${{ secrets.ANDROID_SIGNING_PASSWORD }}" \
-p:AndroidSigningKeyAlias=myalias \
-p:AndroidUseAapt2Daemon=false \
--output ./publish/android
- name: Build Android APK (Unsigned)
if: steps.keystore.outputs.available != 'true'
shell: bash
run: |
dotnet publish src/MyAdventure.Android/MyAdventure.Android.csproj \
--configuration Release \
-p:ApplicationVersion=${{ github.run_number }} \
-p:ApplicationDisplayVersion=1.0.${{ github.run_number }} \
-p:AndroidUseAapt2Daemon=false \
--output ./publish/android
- name: Rename APK
shell: bash
run: |
APK_PATH=$(find ./publish/android -name "*-Signed.apk" -o -name "*.apk" | grep -v "\.aab$" | head -1)
if [[ -n "$APK_PATH" ]]; then
cp "$APK_PATH" "./MyAdventure-android-${{ github.run_number }}.apk"
else
echo "ERROR: No APK found!"
find ./publish -type f -name "*.apk" || echo "No APK files"
exit 1
fi
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: android
path: ./MyAdventure-android-${{ github.run_number }}.apk
if-no-files-found: error
retention-days: 7
# ===========================================================================
# Create GitHub Release
# ===========================================================================
create-release:
needs: [build-desktop, build-android]
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v7
with:
path: ./artifacts
- name: Prepare release files
shell: bash
run: |
mkdir -p ./release
find ./artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" -o -name "*.apk" \) -exec cp {} ./release/ \;
echo "=== Release files ==="
ls -la ./release/
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v1.0.${{ github.run_number }}
name: Release v1.0.${{ github.run_number }}
draft: false
prerelease: false
generate_release_notes: true
files: ./release/*
body: |
## MyAdventure v1.0.${{ github.run_number }}
### Downloads
| Platform | File |
|----------|------|
| Windows x64 | `MyAdventure-win-x64.zip` |
| Windows ARM64 | `MyAdventure-win-arm64.zip` |
| Linux x64 | `MyAdventure-linux-x64.tar.gz` |
| Linux ARM64 | `MyAdventure-linux-arm64.tar.gz` |
| macOS x64 (Intel) | `MyAdventure-osx-x64.tar.gz` |
| macOS ARM64 (Apple Silicon) | `MyAdventure-osx-arm64.tar.gz` |
| Android | `MyAdventure-android-${{ github.run_number }}.apk` |
### Android Users (Obtainium)
Point Obtainium to this repository's releases for automatic updates.
The APK version code increments with each release.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}