#!/usr/bin/env bash # Writes /latest.json, the update feed the app reads, from the signed # release artifacts in : # windows-x86_64 -> *__x64-setup.exe (+ .sig) # linux-x86_64 -> *__amd64.AppImage (+ .sig) # The download URLs point at ${RELEASE_BASE_URL}/releases/download/v/ # (scripts/release.env). # # Usage: scripts/make-latest-json.sh set -euo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)" die() { echo "make-latest-json: $*" >&2 exit 1 } [ "$#" -eq 2 ] || die "usage: scripts/make-latest-json.sh " VERSION="$1" DIR="$2" [ -d "${DIR}" ] || die "no such directory: ${DIR}" command -v jq >/dev/null 2>&1 || die "jq not found on PATH" # shellcheck source=release.env source "${SCRIPT_DIR}/release.env" # The one file in DIR matching the glob $1, with its .sig next to it. signed_file() { local matches=() local file for file in "${DIR}"/$1; do [ -f "${file}" ] && matches+=("${file}") done [ "${#matches[@]}" -eq 1 ] || die "expected exactly one $1 in ${DIR}, found ${#matches[@]}" [ -s "${matches[0]}.sig" ] || die "missing signature ${matches[0]}.sig" echo "${matches[0]}" } WINDOWS="$(signed_file "*_${VERSION}_x64-setup.exe")" LINUX="$(signed_file "*_${VERSION}_amd64.AppImage")" jq -n \ --arg version "${VERSION}" \ --arg pub_date "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ --arg base "${RELEASE_BASE_URL}/releases/download/v${VERSION}" \ --arg windows_file "$(basename "${WINDOWS}")" \ --rawfile windows_sig "${WINDOWS}.sig" \ --arg linux_file "$(basename "${LINUX}")" \ --rawfile linux_sig "${LINUX}.sig" \ '{ version: $version, pub_date: $pub_date, platforms: { "windows-x86_64": { signature: ($windows_sig | gsub("\\s"; "")), url: "\($base)/\($windows_file | @uri)" }, "linux-x86_64": { signature: ($linux_sig | gsub("\\s"; "")), url: "\($base)/\($linux_file | @uri)" } } }' >"${DIR}/latest.json" echo "Wrote ${DIR}/latest.json"