-
-
Notifications
You must be signed in to change notification settings - Fork 7
308 lines (277 loc) · 11.2 KB
/
Copy pathtesting-release.yml
File metadata and controls
308 lines (277 loc) · 11.2 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
name: Testing Release Build
on:
push:
# branches: [ testing ]
tags: [ 'testing-*' ]
# pull_request:
# branches: [ testing ]
jobs:
build:
strategy:
matrix:
include:
# - os: macos-14
# python-version: '3.12'
- os: windows-latest
python-version: '3.12' # Use Python 3.11 for Windows
runs-on: ${{ matrix.os }}
# Add permissions block here for the job
permissions:
contents: write
packages: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.ref }} # Checkout the specific tag that triggered the workflow
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Create virtual environment
shell: bash
run: |
python -m venv venv
if [ "${{ runner.os }}" == "Windows" ]; then
source venv/Scripts/activate
else
source venv/bin/activate
fi
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
- name: Verify Python version
shell: bash
run: |
if [ "${{ runner.os }}" == "Windows" ]; then
source venv/Scripts/activate
venv/Scripts/python.exe --version
else
source venv/bin/activate
python --version # Verify correct Python version
fi
- name: Install dependencies
shell: bash
run: |
if [ "${{ runner.os }}" == "Windows" ]; then
source venv/scripts/activate
venv/Scripts/python.exe -m pip install --upgrade pip
venv/Scripts/python.exe -m pip install -r requirements.txt
else
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
fi
- name: Install project in editable mode
shell: bash
run: |
if [ "${{ runner.os }}" == "Windows" ]; then
source venv/scripts/activate
venv/Scripts/python.exe -m pip install -e .
else
source venv/bin/activate
pip install -e .
fi
- name: Show location and files
shell: bash
run: |
pwd
ls
- name: Run build script
shell: bash
run: |
if [ "${{ runner.os }}" == "Windows" ]; then
source venv/scripts/activate
else
source venv/bin/activate
fi
chmod +x scripts/build
scripts/build --skip-npm-build --skip-git-tag
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16' # Matches Electron and other dependencies version requirements
- name: Install npm dependencies
shell: bash
run: |
npm install
- name: Build frontend for ${{ matrix.os }}
shell: bash
run: |
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
npm run build:linux
elif [ "${{ matrix.os }}" == "macos-14" ]; then
npm run build:mac:arm64
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
npm run build:mac:x64
else
npm run build:win
fi
- name: Determine Archive Name
id: archive_name
shell: bash
run: |
# Extract tag name (e.g., testing-v1.0.0)
TAG_NAME="${{ github.ref_name }}"
# Extract branch part (e.g., testing)
BRANCH_PART="${TAG_NAME%-v*}"
# Extract version part (e.g., v1.0.0)
VERSION_PART="${TAG_NAME#*-}"
# Clean the OS name (e.g., macos-latest -> macos, macos-14 -> macos)
OS_NAME="$(echo "${{ matrix.os }}" | sed 's/-latest$//' | sed 's/-[0-9]*$//')"
# Add architecture detection
if [[ "${{ matrix.os }}" == "macos-14" ]]; then
ARCH="arm64"
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
ARCH="x64"
else
ARCH=""
fi
# Construct the desired filename, use .exe for Windows
if [ "${{ runner.os }}" == "Windows" ]; then
echo "ARCHIVE_FILENAME=ainara-polaris-${BRANCH_PART}-${VERSION_PART}-${OS_NAME}.exe" >> $GITHUB_ENV
echo "VERSION_PART=${VERSION_PART}" >> $GITHUB_ENV
echo "Generated filename: ainara-polaris-${BRANCH_PART}-${VERSION_PART}-${OS_NAME}.exe"
elif [[ "${{ runner.os }}" == "macOS" ]]; then
echo "ARCHIVE_FILENAME=ainara-polaris-${BRANCH_PART}-${VERSION_PART}-${OS_NAME}-${ARCH}.dmg" >> $GITHUB_ENV
echo "VERSION_PART=${VERSION_PART}" >> $GITHUB_ENV
echo "Generated filename: ainara-polaris-${BRANCH_PART}-${VERSION_PART}-${OS_NAME}-${ARCH}.dmg"
else
# Assuming Linux still uses zip for now
echo "ARCHIVE_FILENAME=ainara-polaris-${BRANCH_PART}-${VERSION_PART}-${OS_NAME}.zip" >> $GITHUB_ENV
echo "VERSION_PART=${VERSION_PART}" >> $GITHUB_ENV
echo "Generated filename: ainara-polaris-${BRANCH_PART}-${VERSION_PART}-${OS_NAME}.zip"
fi
# Output version part for use in other steps
echo "version-part=${VERSION_PART}" >> $GITHUB_OUTPUT
- name: Debug VERSION_PART
shell: bash
run: |
echo "VERSION_PART is: ${{ steps.archive_name.outputs.version-part }}"
echo "All env vars:"
env | grep VERSION
- name: Create Archive (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Do not remove dist/servers as it's needed for the NSIS installer
# Copy latest.yml to dist if it exists
if (Test-Path "latest.yml") {
Copy-Item "latest.yml" -Destination dist\
}
# Find the NSIS installer generated by electron-builder
$installerPath = Get-ChildItem -Path "dist" -Filter "Ainara Polaris Setup *.exe" | Select-Object -First 1
if ($installerPath) {
Move-Item -Path $installerPath.FullName -Destination ${{ env.ARCHIVE_FILENAME }}
Write-Host "Renamed installer to ${{ env.ARCHIVE_FILENAME }}"
} else {
Write-Error "NSIS installer not found in dist directory"
exit 1
}
- name: Create YAML Metadata for installer (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$exePath = "${{ env.ARCHIVE_FILENAME }}"
$exeSize = (Get-Item $exePath).Length
$sha512 = (Get-FileHash -Path $exePath -Algorithm SHA512).Hash.ToLower()
$yamlContent = "version: ${{ steps.archive_name.outputs.version-part }}`nfiles:`n - url: ${{ env.ARCHIVE_FILENAME }}`n sha512: $sha512`n size: $exeSize`npath: ${{ env.ARCHIVE_FILENAME }}`nsha512: $sha512`nreleaseDate: $(Get-Date -Format 'yyyy-MM-ddTHH:mm:ss.fffZ')"
Set-Content -Path "latest.yml" -Value $yamlContent
Copy-Item "latest.yml" -Destination "${{ env.ARCHIVE_FILENAME }}.yml"
- name: Create Archive (macOS/Linux)
if: runner.os != 'Windows'
shell: bash
run: |
if [[ "${{ matrix.os }}" == "macos-latest" ]] || [[ "${{ matrix.os }}" == "macos-14" ]]; then
# Find the generated DMG file (electron-builder names it like 'ProductName-Version.dmg')
# For electron-builder, artifactName is "${productName}-${version}-${arch}.${ext}"
# Example: "Ainara Polaris-0.5.2-arm64.dmg" or "Ainara Polaris-0.5.2-x64.dmg"
# The version part comes from steps.archive_name.outputs.version-part
# The arch part comes from the build command or can be inferred.
BUILT_ARCH="x64" # Default for macos-latest
if [[ "${{ matrix.os }}" == "macos-14" ]]; then
BUILT_ARCH="arm64"
fi
# Construct the expected DMG name from electron-builder
# Note: package.json version is used by electron-builder, not necessarily the tag version part.
# We need to get the version from package.json or rely on a pattern.
# A simpler find might be better if the version in the tag doesn't match package.json exactly.
DMG_PATTERN="dist/Ainara Polaris-*${BUILT_ARCH}.dmg"
DMG_PATH=$(find dist -maxdepth 1 -name "Ainara Polaris*${BUILT_ARCH}.dmg" -print -quit)
if [ -z "$DMG_PATH" ]; then
echo "Error: DMG file matching pattern '${DMG_PATTERN}' not found in dist directory."
ls -R dist # List contents for debugging
exit 1
fi
echo "Found DMG: $DMG_PATH"
# Rename the DMG to the desired archive filename
mv "$DMG_PATH" "${{ env.ARCHIVE_FILENAME }}"
echo "Renamed DMG to ${{ env.ARCHIVE_FILENAME }}"
else
# Keep existing Linux logic (assuming zip for now)
rm -rf dist/servers
[ -f "latest-linux.yml" ] && cp latest-linux.yml dist/
zip -r ${{ env.ARCHIVE_FILENAME }} dist/
fi
- name: Create YAML Metadata for DMG (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
dmg_path="${{ env.ARCHIVE_FILENAME }}"
dmg_size=$(stat -f %z "$dmg_path")
sha512=$(shasum -a 512 "$dmg_path" | awk '{print tolower($1)}')
ARCHIVE_FILENAME="${{ env.ARCHIVE_FILENAME }}"
RELEASE_DATE=$(date -u +'%Y-%m-%dT%H:%M:%S.%3NZ')
echo "version: ${{ steps.archive_name.outputs.version-part }}" > "latest-mac.yml"
echo "files:" >> "latest-mac.yml"
echo " - url: $ARCHIVE_FILENAME" >> "latest-mac.yml"
echo " sha512: $sha512" >> "latest-mac.yml"
echo " size: $dmg_size" >> "latest-mac.yml"
echo "path: $ARCHIVE_FILENAME" >> "latest-mac.yml"
echo "sha512: $sha512" >> "latest-mac.yml"
echo "releaseDate: $RELEASE_DATE" >> "latest-mac.yml"
cp "latest-mac.yml" "${{ env.ARCHIVE_FILENAME }}.yml"
- name: Package testing artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_FILENAME }}
path: ${{ env.ARCHIVE_FILENAME }}
if-no-files-found: error
# Prepare platform-specific update YAML file name
- name: Set update YAML filename
id: set_yaml_filename
shell: bash
run: |
if [ "${{ runner.os }}" == "Windows" ]; then
echo "UPDATE_YAML=latest.yml" >> $GITHUB_ENV
elif [ "${{ runner.os }}" == "macOS" ]; then
echo "UPDATE_YAML=latest-mac.yml" >> $GITHUB_ENV
elif [ "${{ runner.os }}" == "Linux" ]; then
echo "UPDATE_YAML=latest-linux.yml" >> $GITHUB_ENV
fi
# Rename the YAML file to the platform-specific name
- name: Prepare update YAML file
shell: bash
run: |
if [ -f "${{ env.ARCHIVE_FILENAME }}.yml" ]; then
cp "${{ env.ARCHIVE_FILENAME }}.yml" "${{ env.UPDATE_YAML }}"
fi
- name: Create testing release
# Only run this step if the workflow was triggered by a tag push
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Testing Release
body: |
Automated testing release from testing branch
OS: ${{ matrix.os }}
Python: ${{ matrix.python-version }}
SHA: ${{ github.sha }}
draft: false
prerelease: true
files: |
${{ env.ARCHIVE_FILENAME }}
${{ env.ARCHIVE_FILENAME }}.yml
${{ env.UPDATE_YAML }}