| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | repo_root="$(cd "${script_dir}/../.." && pwd)" |
| 6 | # shellcheck source=scripts/release/crates.sh |
| 7 | source "${script_dir}/crates.sh" |
| 8 | |
| 9 | usage() { |
| 10 | cat <<'EOF' |
| 11 | usage: scripts/release/check-published.sh [--allow-npm-binary-mismatch] [VERSION] |
| 12 | |
| 13 | Verifies that a release version is visible on both npm and crates.io. |
| 14 | Defaults VERSION to the workspace version in Cargo.toml. |
| 15 | |
| 16 | Use --allow-npm-binary-mismatch only for npm packaging-only releases where |
| 17 | the npm package intentionally points at an older GitHub binary release. |
| 18 | EOF |
| 19 | } |
| 20 | |
| 21 | allow_npm_binary_mismatch=0 |
| 22 | version="" |
| 23 | |
| 24 | while (($# > 0)); do |
| 25 | case "$1" in |
| 26 | --allow-npm-binary-mismatch) |
| 27 | allow_npm_binary_mismatch=1 |
| 28 | ;; |
| 29 | -h|--help) |
| 30 | usage |
| 31 | exit 0 |
| 32 | ;; |
| 33 | *) |
| 34 | if [[ -n "${version}" ]]; then |
| 35 | usage >&2 |
| 36 | exit 2 |
| 37 | fi |
| 38 | version="$1" |
| 39 | ;; |
| 40 | esac |
| 41 | shift |
| 42 | done |
| 43 | |
| 44 | cd "${repo_root}" |
| 45 | |
| 46 | if [[ -z "${version}" ]]; then |
| 47 | version="$(grep -E '^version = "' Cargo.toml | head -n1 | sed -E 's/^version = "([^"]+)".*/\1/')" |
| 48 | fi |
| 49 | |
| 50 | if [[ -z "${version}" ]]; then |
| 51 | echo "Could not determine release version." >&2 |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | fail=0 |
| 56 | |
| 57 | echo "Checking published release ${version}..." |
| 58 | |
| 59 | # Canonical post-rebrand npm package. |
| 60 | if npm_version="$(npm view "codewhale@${version}" version 2>/dev/null)"; then |
| 61 | echo "npm codewhale@${npm_version} is published." |
| 62 | else |
| 63 | echo "npm codewhale@${version} is not published." >&2 |
| 64 | fail=1 |
| 65 | fi |
| 66 | |
| 67 | # `codewhaleBinaryVersion` is the new internal version-pin field. Fall back |
| 68 | # to the legacy `deepseekBinaryVersion` field for old/transition packages. |
| 69 | binary_field="" |
| 70 | npm_binary_version="" |
| 71 | if value="$(npm view "codewhale@${version}" codewhaleBinaryVersion 2>/dev/null)" && [[ -n "${value}" ]]; then |
| 72 | binary_field="codewhaleBinaryVersion" |
| 73 | npm_binary_version="${value}" |
| 74 | elif value="$(npm view "codewhale@${version}" deepseekBinaryVersion 2>/dev/null)" && [[ -n "${value}" ]]; then |
| 75 | binary_field="deepseekBinaryVersion" |
| 76 | npm_binary_version="${value}" |
| 77 | fi |
| 78 | |
| 79 | if [[ -n "${binary_field}" ]]; then |
| 80 | if [[ "${npm_binary_version}" == "${version}" ]]; then |
| 81 | echo "npm ${binary_field}=${npm_binary_version}." |
| 82 | elif [[ "${allow_npm_binary_mismatch}" == "1" ]]; then |
| 83 | echo "npm ${binary_field}=${npm_binary_version} (allowed packaging-only mismatch)." |
| 84 | else |
| 85 | echo "npm ${binary_field}=${npm_binary_version}, expected ${version}." >&2 |
| 86 | fail=1 |
| 87 | fi |
| 88 | elif [[ "${allow_npm_binary_mismatch}" == "1" ]]; then |
| 89 | echo "npm codewhaleBinaryVersion is absent (allowed packaging-only mismatch)." |
| 90 | else |
| 91 | echo "npm codewhaleBinaryVersion is absent for codewhale@${version}." >&2 |
| 92 | fail=1 |
| 93 | fi |
| 94 | |
| 95 | # Legacy `deepseek-tui` npm package. It is deprecated and must not be |
| 96 | # republished under the release version. |
| 97 | if legacy_version="$(npm view "deepseek-tui@${version}" version 2>/dev/null)"; then |
| 98 | echo "npm deepseek-tui@${legacy_version} exists, but the legacy npm package must not be republished." >&2 |
| 99 | fail=1 |
| 100 | fi |
| 101 | if legacy_deprecated="$(npm view deepseek-tui deprecated 2>/dev/null)" && [[ -n "${legacy_deprecated}" ]]; then |
| 102 | echo "npm deepseek-tui is deprecated: ${legacy_deprecated}" |
| 103 | else |
| 104 | echo "npm deepseek-tui is not marked deprecated." >&2 |
| 105 | fail=1 |
| 106 | fi |
| 107 | |
| 108 | crates_user_agent="CodeWhale release check (https://github.com/Hmbown/CodeWhale)" |
| 109 | for crate in "${release_crates[@]}"; do |
| 110 | if curl -fsSL -A "${crates_user_agent}" "https://crates.io/api/v1/crates/${crate}/${version}" >/dev/null 2>&1; then |
| 111 | echo "crates.io ${crate}@${version} is published." |
| 112 | else |
| 113 | echo "crates.io ${crate}@${version} is not published." >&2 |
| 114 | fail=1 |
| 115 | fi |
| 116 | done |
| 117 | |
| 118 | if [[ "${fail}" == "0" ]]; then |
| 119 | echo "Published release OK: npm codewhale@${version} and ${#release_crates[@]} crates are visible." |
| 120 | fi |
| 121 | |
| 122 | exit "${fail}" |
| 123 |