#!/usr/bin/env bash # release-firefox.sh — Package + optionally sign the quickSnote extension. # # Usage: # ./release-firefox.sh # Package .zip only # ./release-firefox.sh --sign # Package + sign via web-ext (auto-bumps patch version) # ./release-firefox.sh --sign --no-bump # Sign without bumping version # ./release-firefox.sh --bump # Bump version only, no signing # ./release-firefox.sh --channel=beta # Sign on beta channel # # Prerequisites for --sign: # - npm install -g web-ext # - AMO API keys set in environment: # export AMO_JWT_ISSUER="user:12345678" # export AMO_JWT_SECRET="..." # # The signed .xpi is copied to static/snotes-capture-firefox.xpi so the snotes # helper page can serve it for one-click install. set -euo pipefail SRC="$(cd "$(dirname "$0")" && pwd)" REPO="$(cd "$SRC"/.. && pwd)" DIST="$REPO/dist" STATIC="$REPO/static" OUT_ZIP="$DIST/snotes-capture-firefox.zip" OUT_XPI="$STATIC/snotes-capture-firefox.xpi" MANIFEST="$SRC/manifest.json" SIGN=false CHANNEL="unlisted" BUMP="" for arg in "$@"; do case "$arg" in --sign) SIGN=true ;; --channel=*) CHANNEL="${arg#*=}" ;; --bump) BUMP=true ;; --no-bump) BUMP=false ;; esac done # Auto-bump patch version when signing (AMO rejects duplicate versions) if [ "$SIGN" = true ] && [ "$BUMP" != false ]; then BUMP=true fi if [ "$BUMP" = true ]; then CURRENT_VERSION="$(python3 -c "import json,sys; print(json.load(open('$MANIFEST'))['version'])")" NEW_VERSION="$(python3 -c " v = '$CURRENT_VERSION'.split('.') v[-1] = str(int(v[-1]) + 1) print('.'.join(v)) ")" python3 -c " import json with open('$MANIFEST') as f: m = json.load(f) m['version'] = '$NEW_VERSION' with open('$MANIFEST', 'w') as f: json.dump(m, f, indent=2) f.write('\n') " echo "==> Bumped version: $CURRENT_VERSION -> $NEW_VERSION" fi rm -f "$OUT_ZIP" mkdir -p "$DIST" echo "==> Packaging Firefox extension..." cd "$SRC" zip -q -r "$OUT_ZIP" \ manifest.json \ background.js \ content.js \ popup.html \ popup.js \ popup.css \ options.html \ options.js \ icons/icon-48.png \ icons/icon-96.png echo " Created: $OUT_ZIP" echo " Size: $(du -h "$OUT_ZIP" | cut -f1)" if [ "$SIGN" = true ]; then if ! command -v web-ext &>/dev/null; then echo "!! web-ext not found. Install with: npm install -g web-ext" exit 1 fi if [ -z "${AMO_JWT_ISSUER:-}" ] || [ -z "${AMO_JWT_SECRET:-}" ]; then echo "!! AMO_JWT_ISSUER and AMO_JWT_SECRET must be set for signing." echo " Get keys at: https://addons.mozilla.org/en-US/developers/addon/api/key/" exit 1 fi echo "==> Signing via addons.mozilla.org (channel: $CHANNEL)..." web-ext sign \ --source-dir "$SRC" \ --artifacts-dir "$DIST" \ --api-key "$AMO_JWT_ISSUER" \ --api-secret "$AMO_JWT_SECRET" \ --channel "$CHANNEL" \ --ignore-files "*.sh" echo " Signed .xpi in: $DIST/" SIGNED_XPI="$(ls -t "$DIST"/*.xpi 2>/dev/null | head -1)" if [ -n "$SIGNED_XPI" ]; then cp "$SIGNED_XPI" "$OUT_XPI" echo " Copied to: $OUT_XPI" fi fi echo "==> Done."