|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +usage() { |
| 5 | + cat <<'EOF' |
| 6 | +Usage: scripts/deploy_new_binary.sh [--dry-run] [--bump] [--no-bump] [--tag <tag>] |
| 7 | +
|
| 8 | +Builds the Rust CLI, installs the new Linux x64 binary into vendor/, verifies |
| 9 | +the npm package payload, and publishes @codex-infinity/codex-infinity. |
| 10 | +
|
| 11 | +By default the script bumps the package patch version before publishing because |
| 12 | +npm package versions are immutable. Dry-runs restore package.json after the |
| 13 | +publish preview. Use --no-bump only when package.json already contains an |
| 14 | +unpublished version. |
| 15 | +EOF |
| 16 | +} |
| 17 | + |
| 18 | +dry_run=0 |
| 19 | +bump="" |
| 20 | +npm_tag="latest" |
| 21 | + |
| 22 | +while (($# > 0)); do |
| 23 | + case "$1" in |
| 24 | + --dry-run) |
| 25 | + dry_run=1 |
| 26 | + shift |
| 27 | + ;; |
| 28 | + --bump) |
| 29 | + bump=1 |
| 30 | + shift |
| 31 | + ;; |
| 32 | + --no-bump) |
| 33 | + bump=0 |
| 34 | + shift |
| 35 | + ;; |
| 36 | + --tag) |
| 37 | + if (($# < 2)); then |
| 38 | + echo "error: --tag requires a value" >&2 |
| 39 | + exit 2 |
| 40 | + fi |
| 41 | + npm_tag="$2" |
| 42 | + shift 2 |
| 43 | + ;; |
| 44 | + -h|--help) |
| 45 | + usage |
| 46 | + exit 0 |
| 47 | + ;; |
| 48 | + *) |
| 49 | + echo "error: unknown argument: $1" >&2 |
| 50 | + usage >&2 |
| 51 | + exit 2 |
| 52 | + ;; |
| 53 | + esac |
| 54 | +done |
| 55 | + |
| 56 | +if [[ -z "$bump" ]]; then |
| 57 | + bump=1 |
| 58 | +fi |
| 59 | + |
| 60 | +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 61 | +codex_cli_root="$(cd "$script_dir/.." && pwd)" |
| 62 | +repo_root="$(cd "$codex_cli_root/.." && pwd)" |
| 63 | +codex_rs_root="$repo_root/codex-rs" |
| 64 | +binary_src="$codex_rs_root/target/release/codex" |
| 65 | +binary_dest="$codex_cli_root/vendor/x86_64-unknown-linux-gnu/codex/codex" |
| 66 | + |
| 67 | +if ((!dry_run)); then |
| 68 | + if ! (cd "$codex_cli_root" && npm whoami >/dev/null); then |
| 69 | + echo "error: npm is not authenticated; run npm login before deploying." >&2 |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | +fi |
| 73 | + |
| 74 | +cd "$codex_rs_root" |
| 75 | +cargo build --release -p codex-cli |
| 76 | + |
| 77 | +mkdir -p "$(dirname "$binary_dest")" |
| 78 | +install -m 755 "$binary_src" "$binary_dest" |
| 79 | + |
| 80 | +cd "$codex_cli_root" |
| 81 | + |
| 82 | +package_json_backup="" |
| 83 | +restore_package_json() { |
| 84 | + if [[ -n "$package_json_backup" && -f "$package_json_backup" ]]; then |
| 85 | + cp "$package_json_backup" package.json |
| 86 | + rm -f "$package_json_backup" |
| 87 | + fi |
| 88 | +} |
| 89 | + |
| 90 | +if ((dry_run && bump)); then |
| 91 | + package_json_backup="$(mktemp)" |
| 92 | + cp package.json "$package_json_backup" |
| 93 | + trap restore_package_json EXIT |
| 94 | +fi |
| 95 | + |
| 96 | +if ((bump)); then |
| 97 | + npm version patch --no-git-tag-version |
| 98 | +fi |
| 99 | + |
| 100 | +CODEX_INFINITY_REQUIRED_GROUPS=linux-x64 node scripts/verify_vendor.js |
| 101 | +node bin/codex-infinity.js --version |
| 102 | + |
| 103 | +if ((dry_run)); then |
| 104 | + npm publish --access public --tag "$npm_tag" --dry-run |
| 105 | +else |
| 106 | + npm publish --access public --tag "$npm_tag" |
| 107 | +fi |
0 commit comments