-
Notifications
You must be signed in to change notification settings - Fork 395
251 lines (210 loc) · 7.4 KB
/
build.yml
File metadata and controls
251 lines (210 loc) · 7.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
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
name: Build Selene
on:
push:
tags:
- 'v*'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
actions: write
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- name: android
os: ubuntu-latest
build-args: "--android-only"
- name: macos_ios
os: macos-latest
build-args: "--apple-only --sequential"
- name: windows-amd64
os: windows-latest
runs-on: ${{ matrix.os }}
env:
NDK_VERSION: '29.0.14033849'
NDK_VERSION_DEPS: '27.0.12077973'
name: Build ${{ matrix.name }}
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Clone repository
run: |
git clone https://${{ secrets.PULL_TOKEN }}@${{ secrets.REPO_URL }}.git .
shell: bash
- name: Get version from pubspec.yaml
id: get_version
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
VERSION=$(powershell -Command "(Get-Content pubspec.yaml | Select-String '^version:' | ForEach-Object {\$_ -replace 'version: ', ''}).trim()")
else
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //' | tr -d ' ')
fi
VERSION=$(echo "$VERSION" | cut -d'+' -f1)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
shell: bash
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.44.0'
channel: stable
cache: true
- name: Disable Swift Package Manager for Apple builds
if: matrix.name == 'macos_ios'
run: |
flutter config --no-enable-swift-package-manager
shell: bash
- name: Install Java
if: matrix.name == 'android'
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: 21
- name: Setup Android SDK
if: matrix.name == 'android'
uses: android-actions/setup-android@v3
- name: Cache Gradle
if: matrix.name == 'android'
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
android/.gradle
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache NDK
if: matrix.name == 'android'
id: cache-ndk
uses: actions/cache@v4
with:
path: |
${{ env.ANDROID_HOME }}/ndk/${{ env.NDK_VERSION }}
${{ env.ANDROID_HOME }}/ndk/${{ env.NDK_VERSION_DEPS }}
key: ${{ runner.os }}-ndk-${{ env.NDK_VERSION }}-${{ env.NDK_VERSION_DEPS }}
- name: Install NDK
if: matrix.name == 'android' && steps.cache-ndk.outputs.cache-hit != 'true'
run: |
echo "y" | sdkmanager --install "ndk;${{ env.NDK_VERSION }}"
echo "y" | sdkmanager --install "ndk;${{ env.NDK_VERSION_DEPS }}"
- name: Write sign info
if: matrix.name == 'android'
run: |
if [ ! -z "${{ secrets.SIGNING_KEY }}" ]; then
echo "Writing signing configuration..."
echo ${{ secrets.SIGNING_KEY }} | base64 --decode > ${{ github.workspace }}/key.jks
cat > android/key.properties << EOF
storePassword=${{ secrets.KEY_STORE_PASSWORD }}
keyPassword=${{ secrets.KEY_PASSWORD }}
keyAlias=${{ secrets.ALIAS }}
storeFile=${{ github.workspace }}/key.jks
EOF
echo "Signing configuration written successfully"
else
echo "WARNING: SIGNING_KEY secret is not set!"
fi
shell: bash
- name: Build with build.sh (Android/macOS/iOS)
if: matrix.name != 'windows-amd64'
run: |
chmod +x build.sh
./build.sh ${{ matrix.build-args }}
shell: bash
- name: Build on Windows
if: matrix.name == 'windows-amd64'
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$version = "${{ steps.get_version.outputs.version }}"
Write-Host "Building version: $version" -ForegroundColor Green
flutter pub get
New-Item -ItemType Directory -Force -Path dist | Out-Null
Write-Host "Building Windows..." -ForegroundColor Blue
flutter build windows --release
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
$releasePath = "build/windows/x64/runner/Release"
if (-not (Test-Path $releasePath)) {
throw "Windows release directory not found: $releasePath"
}
Compress-Archive `
-Path "$releasePath/*" `
-DestinationPath "dist/selene-$version-windows-x64-portable.zip" `
-Force
Write-Host "Windows build complete" -ForegroundColor Green
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}-release-artifacts
path: dist/*
if-no-files-found: error
create-release:
needs: build
runs-on: ubuntu-latest
name: Create Release
if: startsWith(github.ref, 'refs/tags/')
env:
TZ: Asia/Shanghai
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: all-artifacts
- name: Prepare release artifacts
run: |
mkdir -p release-files
find all-artifacts -type f -exec cp {} release-files/ \;
if [ -z "$(find release-files -type f -print -quit)" ]; then
echo "No release artifacts found"
exit 1
fi
ls -lh release-files/
- name: Get version from tag
id: tag_version
run: |
VERSION="${GITHUB_REF#refs/tags/}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Release version: $VERSION"
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.tag_version.outputs.version }}
name: Selene ${{ steps.tag_version.outputs.version }}
files: release-files/*
draft: false
prerelease: false
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get Release Notes
id: release_notes
run: |
RELEASE_INFO=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.tag_version.outputs.version }}")
RELEASE_BODY=$(echo "$RELEASE_INFO" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('body', '') if 'body' in data else '')")
{
echo 'notes<<EOF'
echo "$RELEASE_BODY"
echo EOF
} >> $GITHUB_OUTPUT
echo "Release notes length: ${#RELEASE_BODY}"
cleanup:
runs-on: ubuntu-latest
needs: build
if: always()
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
retain_days: 0
keep_minimum_runs: 2