upload-msi-release.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
  5. DIST_DIR="${DIST_DIR:-${REPO_ROOT}/dist}"
  6. ARCH="${ARCH:-amd64}"
  7. MSI_NAME="OliveTin-windows-${ARCH}.msi"
  8. MSI_PATH="${DIST_DIR}/${MSI_NAME}"
  9. TAG="${1:-}"
  10. if [[ -z "${TAG}" ]]; then
  11. echo "Usage: $(basename "$0") <release-tag>" >&2
  12. exit 1
  13. fi
  14. if [[ ! -f "${MSI_PATH}" ]]; then
  15. echo "MSI not found: ${MSI_PATH}" >&2
  16. exit 1
  17. fi
  18. if ! command -v gh >/dev/null; then
  19. echo "gh is required to upload the MSI to GitHub releases" >&2
  20. exit 1
  21. fi
  22. checksums_path="${DIST_DIR}/checksums.txt"
  23. new_checksum="$(cd "${DIST_DIR}" && sha256sum "${MSI_NAME}")"
  24. if [[ -f "${checksums_path}" ]] && grep -qF " ${MSI_NAME}" "${checksums_path}"; then
  25. tmp="$(mktemp)"
  26. grep -vF " ${MSI_NAME}" "${checksums_path}" > "${tmp}" || true
  27. printf '%s\n' "${new_checksum}" >> "${tmp}"
  28. mv "${tmp}" "${checksums_path}"
  29. elif [[ -f "${checksums_path}" ]]; then
  30. printf '%s\n' "${new_checksum}" >> "${checksums_path}"
  31. else
  32. printf '%s\n' "${new_checksum}" > "${checksums_path}"
  33. fi
  34. gh release upload "${TAG}" "${MSI_PATH}" --clobber
  35. if [[ -f "${checksums_path}" ]]; then
  36. gh release upload "${TAG}" "${checksums_path}" --clobber
  37. fi
  38. echo "Uploaded ${MSI_NAME} to release ${TAG}"