|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Populate SHA256 placeholders in every distribution-channel manifest from the |
| 3 | +# artifacts attached to a published GitHub Release. |
| 4 | +# |
| 5 | +# Usage: |
| 6 | +# ./packaging/update-shas.sh # uses apps/desktop/package.json version |
| 7 | +# ./packaging/update-shas.sh 0.1.0 # override version |
| 8 | +# ./packaging/update-shas.sh 0.1.0 local/dir # hash local files in local/dir instead of downloading |
| 9 | +# |
| 10 | +# After a successful `gh release view vX.Y.Z` run this and commit the diffs. |
| 11 | + |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +VERSION="${1:-$(node -p "require('./apps/desktop/package.json').version" 2>/dev/null || echo '0.1.0')}" |
| 15 | +LOCAL_DIR="${2:-}" |
| 16 | + |
| 17 | +REPO="OpenCoworkAI/open-codesign" |
| 18 | +REL_URL_BASE="https://github.com/${REPO}/releases/download/v${VERSION}" |
| 19 | + |
| 20 | +# electron-builder's default artifact names for the three Windows targets |
| 21 | +# and two macOS architectures. Keep these in sync with electron-builder.yml. |
| 22 | +MAC_ARM64_DMG="open-codesign-${VERSION}-arm64.dmg" |
| 23 | +MAC_X64_DMG="open-codesign-${VERSION}.dmg" |
| 24 | +WIN_X64_EXE="open-codesign-${VERSION}-x64-setup.exe" |
| 25 | +WIN_ARM64_EXE="open-codesign-${VERSION}-arm64-setup.exe" |
| 26 | + |
| 27 | +tmpdir=$(mktemp -d) |
| 28 | +trap 'rm -rf "$tmpdir"' EXIT |
| 29 | + |
| 30 | +fetch_sha() { |
| 31 | + local file="$1" |
| 32 | + local out="$tmpdir/$file" |
| 33 | + if [[ -n "$LOCAL_DIR" && -f "$LOCAL_DIR/$file" ]]; then |
| 34 | + cp "$LOCAL_DIR/$file" "$out" |
| 35 | + else |
| 36 | + local url="${REL_URL_BASE}/${file}" |
| 37 | + echo " downloading $url" >&2 |
| 38 | + curl -fsSL -o "$out" "$url" |
| 39 | + fi |
| 40 | + shasum -a 256 "$out" | awk '{print $1}' |
| 41 | +} |
| 42 | + |
| 43 | +update_placeholder() { |
| 44 | + local file="$1" ; local placeholder="$2" ; local sha="$3" |
| 45 | + # Perl for portable in-place replace that works on both macOS and Linux. |
| 46 | + perl -pi -e "s/\\Q${placeholder}\\E/${sha}/g" "$file" |
| 47 | +} |
| 48 | + |
| 49 | +echo "Version: v${VERSION}" |
| 50 | +echo "" |
| 51 | +echo "Computing SHA256s…" |
| 52 | +mac_arm_sha=$(fetch_sha "$MAC_ARM64_DMG") |
| 53 | +mac_x64_sha=$(fetch_sha "$MAC_X64_DMG") |
| 54 | +win_x64_sha=$(fetch_sha "$WIN_X64_EXE") |
| 55 | +win_arm_sha=$(fetch_sha "$WIN_ARM64_EXE") |
| 56 | +echo " mac arm64 : $mac_arm_sha" |
| 57 | +echo " mac x64 : $mac_x64_sha" |
| 58 | +echo " win x64 : $win_x64_sha" |
| 59 | +echo " win arm64 : $win_arm_sha" |
| 60 | +echo "" |
| 61 | + |
| 62 | +echo "Homebrew cask…" |
| 63 | +cask="packaging/homebrew/Casks/open-codesign.rb" |
| 64 | +perl -pi -e "s/version \"[0-9.]+\"/version \"${VERSION}\"/" "$cask" |
| 65 | +update_placeholder "$cask" "REPLACE_WITH_ARM64_SHA256" "$mac_arm_sha" |
| 66 | +update_placeholder "$cask" "REPLACE_WITH_X64_SHA256" "$mac_x64_sha" |
| 67 | + |
| 68 | +echo "winget manifests…" |
| 69 | +winget_dir="packaging/winget/manifests/o/OpenCoworkAI/open-codesign/${VERSION}" |
| 70 | +# If the user bumped VERSION without renaming the directory, guide them. |
| 71 | +if [[ ! -d "$winget_dir" ]]; then |
| 72 | + echo " note: $winget_dir does not exist yet. Copy the previous version's" |
| 73 | + echo " directory and rerun — this script only updates SHAs, not tree." |
| 74 | +else |
| 75 | + for f in "$winget_dir"/*.yaml; do |
| 76 | + perl -pi -e "s/PackageVersion: [0-9.]+/PackageVersion: ${VERSION}/" "$f" |
| 77 | + done |
| 78 | + installer="$winget_dir/OpenCoworkAI.open-codesign.installer.yaml" |
| 79 | + update_placeholder "$installer" "REPLACE_WITH_X64_SHA256" "$win_x64_sha" |
| 80 | + update_placeholder "$installer" "REPLACE_WITH_ARM64_SHA256" "$win_arm_sha" |
| 81 | + # Keep InstallerUrl in sync with VERSION too. |
| 82 | + perl -pi -e "s/v[0-9.]+\/open-codesign-[0-9.]+-/v${VERSION}\/open-codesign-${VERSION}-/g" "$installer" |
| 83 | +fi |
| 84 | + |
| 85 | +echo "scoop manifest…" |
| 86 | +scoop="packaging/scoop/bucket/open-codesign.json" |
| 87 | +# Replace top-level "version": "...". |
| 88 | +perl -pi -e "s/\"version\": \"[0-9.]+\"/\"version\": \"${VERSION}\"/" "$scoop" |
| 89 | +perl -pi -e "s/v[0-9.]+\/open-codesign-[0-9.]+-/v${VERSION}\/open-codesign-${VERSION}-/g" "$scoop" |
| 90 | +update_placeholder "$scoop" "REPLACE_WITH_X64_SHA256" "$win_x64_sha" |
| 91 | +update_placeholder "$scoop" "REPLACE_WITH_ARM64_SHA256" "$win_arm_sha" |
| 92 | + |
| 93 | +echo "" |
| 94 | +echo "Done. Review with git diff packaging/, then commit + mirror to the" |
| 95 | +echo "downstream tap/bucket/winget-pkgs repos (see packaging/README.md)." |
0 commit comments