Skip to content

Commit f1717b4

Browse files
authored
Add experimental macOS publishing #770 (#771)
1 parent c68b37a commit f1717b4

File tree

3 files changed

+168
-6
lines changed

3 files changed

+168
-6
lines changed

.github/workflows/build-electron.yml

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ on:
4545
- true
4646
- false
4747
default: 'false'
48+
macosonly:
49+
description: Do you wish to build only for macOS (primarily for testing)?
50+
type: choice
51+
required: false
52+
options:
53+
- true
54+
- false
55+
default: 'false'
4856
env:
4957
INPUT_VERSION: ${{ github.event.inputs.version }}
5058
INPUT_TARGET: ${{ github.event.inputs.target }}
@@ -63,7 +71,7 @@ env:
6371
jobs:
6472

6573
Release_Linux:
66-
if: github.event.inputs.win11only != 'true'
74+
if: github.event.inputs.win11only != 'true' && github.event.inputs.macosonly != 'true'
6775
runs-on: ubuntu-latest
6876
steps:
6977
- uses: actions/checkout@v4
@@ -141,7 +149,7 @@ jobs:
141149
npx electron-builder --linux AppImage:ia32 --projectDir dist
142150
fi
143151
- name: Upload packages to Kiwix
144-
if: github.ref_name == 'main' && github.event.inputs.target != 'artefacts'
152+
if: github.event.inputs.target != 'artefacts'
145153
run: |
146154
echo "$SSH_KEY" > ./scripts/ssh_key
147155
chmod 600 ./scripts/ssh_key
@@ -157,7 +165,85 @@ jobs:
157165
dist/bld/Electron/*.deb
158166
dist/bld/Electron/*.rpm
159167
168+
Release_macOS:
169+
if: github.event.inputs.win11only != 'true'
170+
runs-on: macos-latest
171+
steps:
172+
- uses: actions/checkout@v4
173+
- uses: actions/setup-node@v4
174+
- name: Install dependencies
175+
run: npm install
176+
- name: Rewrite app version number and file name
177+
run: |
178+
chmod +x ./scripts/rewrite_app_version_number.sh
179+
./scripts/rewrite_app_version_number.sh
180+
# Replace -app in archive name for Electron apps (BSD sed syntax for macOS)
181+
sed -i '' -E 's/(mdwiki[^-]+)-app_/\1_/g' ./www/js/init.js
182+
- name: Build production code
183+
run: npm run build-min
184+
- name: Download archive if needed
185+
run: |
186+
echo "Changing to the dist directory"
187+
cd dist && pwd
188+
# Get archive name
189+
packagedFile=$(grep -m1 'params\[.packagedFile' www/js/init.js | sed -E "s/^.+'([^']+\.zim)'.+/\1/")
190+
# If packagedFile doesn't match a zim file, we don't need to download anything, so exit
191+
if [[ ! $packagedFile =~ \.zim$ ]]; then
192+
echo -e "\nNo zim file to download.\n"
193+
exit 0
194+
fi
195+
# If file doesn't exist in FS, download it
196+
if [ ! -f "archives/$packagedFile" ]; then
197+
# Generalize the name if cron_launched and download it
198+
if [[ $CRON_LAUNCHED = true ]]; then
199+
packagedFileGeneric=$(sed -E 's/_[0-9-]+(\.zim)/\1/' <<<"$packagedFile")
200+
echo -e "\nDownloading https://download.kiwix.org/zim/$packagedFileGeneric"
201+
wget -nv "https://download.kiwix.org/zim/$packagedFileGeneric" -O "archives/$packagedFile"
202+
else
203+
flavour=$(sed -E 's/^([^_]+)_.+$/\1/' <<<"$packagedFile")
204+
if [[ $flavour = "mdwiki" ]]; then
205+
flavour='other'
206+
fi
207+
echo -e "\nDownloading https://mirror.download.kiwix.org/zim/$flavour/$packagedFile"
208+
wget -nv "https://mirror.download.kiwix.org/zim/$flavour/$packagedFile" -O "archives/$packagedFile"
209+
fi
210+
fi
211+
ls archives
212+
if [ -f "archives/$packagedFile" ]; then
213+
echo -e "\nFile $packagedFile now available in 'archives'.\n"
214+
else
215+
echo -e "\nError! We could not obtain the requested archive $packagedFile!\n"
216+
exit 1
217+
fi
218+
- name: Build macOS packages
219+
env:
220+
USE_HARD_LINKS: false
221+
run: |
222+
echo "Installing dependencies in dist"
223+
cd dist && npm install && cd ..
224+
echo "Building macOS packages for ref_name=$REF_NAME..."
225+
if [[ $REF_NAME = "main" ]]; then
226+
npx electron-builder --mac zip:x64 zip:arm64 --projectDir dist
227+
else
228+
npx electron-builder --mac zip:x64 zip:arm64 --projectDir dist
229+
fi
230+
- name: Upload packages to Kiwix
231+
if: github.event.inputs.target != 'artefacts'
232+
run: |
233+
echo "$SSH_KEY" > ./scripts/ssh_key
234+
chmod 600 ./scripts/ssh_key
235+
chmod +x ./scripts/publish_macos_packages_to_kiwix.sh
236+
./scripts/publish_macos_packages_to_kiwix.sh
237+
- name: Archive build artefacts
238+
if: github.event.inputs.target == 'artefacts'
239+
uses: actions/upload-artifact@v4
240+
with:
241+
name: kiwix-js-electron_macos
242+
path: |
243+
dist/bld/Electron/*.zip
244+
160245
Release_Windows:
246+
if: github.event.inputs.macosonly != 'true'
161247
runs-on: windows-latest
162248
env:
163249
SIGNTOOL_PATH: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.22621.0/x86/signtool.exe"
@@ -358,8 +444,8 @@ jobs:
358444
if ($Env:REF_NAME -eq "main") {
359445
./scripts/Publish-ElectronPackages.ps1 -portableonly
360446
} else {
361-
echo "DEV: Note that only nightly builds launched from main will be published to the Kiwix server..."
362-
./scripts/Publish-ElectronPackages.ps1 -portableonly -githubonly
447+
echo "DEV: Note that this is a manual test build from branch $Env:REF_NAME"
448+
./scripts/Publish-ElectronPackages.ps1 -portableonly
363449
}
364450
- name: Archive build artefacts
365451
if: github.event.inputs.target == 'artefacts'
@@ -374,7 +460,7 @@ jobs:
374460
dist/bld/Electron/nsis-web/*.nsis.7z
375461
376462
Release_NWJS:
377-
if: github.ref_name == 'main' && github.event.inputs.win11only != 'true'
463+
if: github.ref_name == 'main' && github.event.inputs.win11only != 'true' && github.event.inputs.macosonly != 'true'
378464
runs-on: windows-latest
379465
steps:
380466
- uses: actions/checkout@v4
@@ -437,7 +523,12 @@ jobs:
437523
$INPUT_VERSION = $Env:INPUT_VERSION
438524
$INPUT_TARGET = $Env:INPUT_TARGET
439525
$CRON_LAUNCHED = $Env:CRON_LAUNCHED
440-
./scripts/Publish-ElectronPackages.ps1
526+
if ($Env:REF_NAME -eq "main") {
527+
./scripts/Publish-ElectronPackages.ps1
528+
} else {
529+
echo "DEV: Note that this is a manual test build from branch $Env:REF_NAME"
530+
./scripts/Publish-ElectronPackages.ps1
531+
}
441532
- name: Archive build artefacts
442533
if: github.event.inputs.target == 'artefacts'
443534
uses: actions/upload-artifact@v4

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@
5454
}
5555
]
5656
},
57+
"mac": {
58+
"asar": "true",
59+
"extraResources": {
60+
"from": "archives",
61+
"to": "archives"
62+
},
63+
"publish": [
64+
"github"
65+
],
66+
"target": [
67+
{
68+
"target": "zip",
69+
"arch": [
70+
"x64",
71+
"arm64"
72+
]
73+
}
74+
],
75+
"category": "public.app-category.education"
76+
},
5777
"linux": {
5878
"asar": "true",
5979
"extraResources": {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Script to upload macOS packages to download.kiwix.org
3+
target="/data/download/release/kiwix-js-electron"
4+
if [[ ${INPUT_TARGET} = "nightly" ]]; then
5+
CRON_LAUNCHED="1"
6+
fi
7+
if [[ "qq${CRON_LAUNCHED}" != "qq" ]]; then
8+
echo "This script was launched by the GitHub Cron process"
9+
CURRENT_DATE=$(date +'%Y-%m-%d')
10+
target="/data/download/nightly/$CURRENT_DATE"
11+
fi
12+
echo "Uploading macOS packages to https://download.kiwix.org$target/"
13+
echo "mkdir ${target}" | sftp -P 30022 -o StrictHostKeyChecking=no -i ./scripts/ssh_key [email protected]
14+
for file in ./dist/bld/Electron/* ; do
15+
if [[ "$file" =~ \.zip$ ]]; then
16+
directory=$(sed -E 's/[^\/]+$//' <<<"$file")
17+
filename=$(sed -E 's/[^/]+\///g' <<<"$file")
18+
# Convert spaces to underscores and standardize naming
19+
filename=$(sed 's/[[:space:]]/_/g' <<<"$filename")
20+
# Remove unneeded elements and standardize format
21+
filename=$(sed -E 's/_E([_.])/\1/' <<<"$filename")
22+
# Convert to all lowercase (compatible with older bash)
23+
filename=$(echo "$filename" | tr '[:upper:]' '[:lower:]')
24+
# Restore hyphens in app name
25+
filename=$(sed 's/kiwix_js_electron/kiwix-js-electron/' <<<"$filename")
26+
# Handle architecture naming for macOS
27+
filename=$(sed 's/-darwin-x64/-macos-x64/' <<<"$filename")
28+
filename=$(sed 's/-darwin-arm64/-macos-arm64/' <<<"$filename")
29+
filename=$(sed 's/-mac\.zip/-macos.zip/' <<<"$filename")
30+
if [[ "qq${CRON_LAUNCHED}" != "qq" ]]; then
31+
# For nightly builds, create a standardized filename with date
32+
# Extract architecture if present (arm64 or x64)
33+
arch=""
34+
if [[ "$filename" =~ arm64 ]]; then
35+
arch="_arm64"
36+
elif [[ "$filename" =~ x64 ]]; then
37+
arch="_x64"
38+
fi
39+
# Create nightly filename format: kiwix-js-electron_macos[_arch]_YYYY-MM-DD.zip
40+
filename="kiwix-js-electron_macos${arch}_${CURRENT_DATE}.zip"
41+
fi
42+
echo "Renaming $file to $filename"
43+
# Put it all together
44+
renamed_file="$directory$filename"
45+
if [[ "$file" != "$renamed_file" ]]; then
46+
mv "$file" "$renamed_file"
47+
fi
48+
echo "Copying $renamed_file to $target"
49+
scp -P 30022 -o StrictHostKeyChecking=no -i ./scripts/ssh_key "$renamed_file" [email protected]:$target
50+
fi
51+
done

0 commit comments

Comments
 (0)