0327a55c74
Mozilla AMO rejetait le .xpi avec : Unsupported "/background/service_worker" manifest property used without "/background/scripts" property as Firefox-compatible fallback. build.sh ajoute maintenant 'scripts: [background.js]' à background.* dans le manifest Firefox uniquement (Chrome ignore 'scripts' quand 'service_worker' est présent ; Firefox ignore 'service_worker' et utilise 'scripts'). Les deux navigateurs chargent le même background.js. Sha256 du .xpi v2026.5.41 mis à jour dans firefox-updates.json.
99 lines
3.7 KiB
Bash
Executable File
99 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
###############################################################################
|
|
# build.sh — génère dist/chromium/, dist/firefox/, et les archives .zip / .xpi
|
|
# à partir du code source dans src/.
|
|
#
|
|
# Usage : ./build.sh
|
|
###############################################################################
|
|
set -e
|
|
# Le script est dans Autres/ — on remonte d'un cran pour se placer à la
|
|
# racine du projet, où se trouvent src/ et dist/.
|
|
cd "$(dirname "$0")"
|
|
|
|
VERSION=$(python3 -c "import json; print(json.load(open('src/manifest.json'))['version'])")
|
|
echo "==> Build Planification v$VERSION"
|
|
|
|
rm -rf dist
|
|
mkdir -p dist/chromium dist/firefox
|
|
|
|
# ---- Chromium : copie src/ tel quel (manifest sans gecko_settings) ----
|
|
cp -r src/* dist/chromium/
|
|
echo " ✓ dist/chromium/ ($(du -sh dist/chromium | cut -f1))"
|
|
|
|
# ---- Firefox : copie src/ + manifest avec browser_specific_settings ----
|
|
cp -r src/* dist/firefox/
|
|
python3 - <<EOF
|
|
import json
|
|
with open('src/manifest.json', 'r') as f: m = json.load(f)
|
|
m['browser_specific_settings'] = {
|
|
'gecko': {
|
|
'id': 'planification@netaplaid.ch',
|
|
'strict_min_version': '140.0',
|
|
'update_url': 'https://gitea.netaplaid.ch/FroSteel/Planification/raw/branch/main/firefox-updates.json',
|
|
'data_collection_permissions': {'required': ['none']}
|
|
}
|
|
}
|
|
# Firefox MV3 ne supporte pas (encore) 'service_worker' → AMO rejette.
|
|
# On ajoute 'scripts' (event page) comme fallback compatible Firefox.
|
|
# Chrome ignore 'scripts' quand 'service_worker' est présent ; Firefox
|
|
# ignore 'service_worker' et utilise 'scripts'. Les deux navigateurs
|
|
# chargent ainsi le même background.js.
|
|
bg = m.get('background', {})
|
|
if 'scripts' not in bg:
|
|
bg['scripts'] = ['background.js']
|
|
m['background'] = bg
|
|
with open('dist/firefox/manifest.json', 'w') as f:
|
|
json.dump(m, f, indent=2, ensure_ascii=False)
|
|
f.write('\n')
|
|
EOF
|
|
echo " ✓ dist/firefox/ ($(du -sh dist/firefox | cut -f1))"
|
|
|
|
# ---- Archives ZIP / XPI prêtes à distribuer ----
|
|
cd dist/chromium && zip -rq "../planification-v${VERSION}-chromium.zip" . && cd ../..
|
|
cd dist/firefox && zip -rq "../planification-v${VERSION}-firefox.xpi" . && cd ../..
|
|
|
|
echo ""
|
|
echo "==> Builds prêts dans dist/"
|
|
ls -la dist/*.zip dist/*.xpi 2>/dev/null
|
|
|
|
# ---- firefox-updates.json : ajout/mise à jour de l'entrée pour cette version
|
|
# (sha256 du .xpi NON SIGNÉ — sera remplacé par celui du .xpi signé après AMO).
|
|
python3 - <<EOF
|
|
import json, hashlib, os
|
|
xpi = f"dist/planification-v${VERSION}-firefox.xpi"
|
|
with open(xpi, 'rb') as f: sha = hashlib.sha256(f.read()).hexdigest()
|
|
|
|
JSON_PATH = "firefox-updates.json"
|
|
ADDON_ID = "planification@netaplaid.ch"
|
|
update_link = f"https://gitea.netaplaid.ch/FroSteel/Planification/releases/download/v${VERSION}/planification-v${VERSION}-firefox.xpi"
|
|
|
|
if os.path.exists(JSON_PATH):
|
|
with open(JSON_PATH) as f: data = json.load(f)
|
|
else:
|
|
data = {"addons": {ADDON_ID: {"updates": []}}}
|
|
|
|
addon = data.setdefault("addons", {}).setdefault(ADDON_ID, {"updates": []})
|
|
updates = addon.setdefault("updates", [])
|
|
|
|
# Retirer toute entrée existante pour cette version (idempotent)
|
|
updates = [u for u in updates if u.get("version") != "${VERSION}"]
|
|
# Ajouter en tête
|
|
updates.insert(0, {
|
|
"version": "${VERSION}",
|
|
"update_link": update_link,
|
|
"update_hash": "sha256:" + sha,
|
|
})
|
|
addon["updates"] = updates
|
|
|
|
with open(JSON_PATH, 'w') as f:
|
|
json.dump(data, f, indent=2, ensure_ascii=False)
|
|
f.write('\n')
|
|
|
|
print(f" ✓ firefox-updates.json mis à jour (sha256 NON SIGNÉ : {sha[:16]}…)")
|
|
EOF
|
|
|
|
echo ""
|
|
echo "Pour Chrome : charger dist/chromium/ en mode développeur"
|
|
echo "Pour Firefox : signer dist/planification-v${VERSION}-firefox.xpi sur AMO"
|
|
echo " Après signature, remplacer le sha256 dans firefox-updates.json par celui du .xpi signé."
|