Skip to content

Commit c0caa48

Browse files
committed
Add npm binary deploy helper
1 parent 05a630f commit c0caa48

4 files changed

Lines changed: 157 additions & 1 deletion

File tree

codex-cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"codex-infinity": "bin/codex-infinity.js"
88
},
99
"scripts": {
10+
"deploy": "bash scripts/deploy_new_binary.sh",
11+
"deploy:dry-run": "bash scripts/deploy_new_binary.sh --dry-run",
1012
"prepack": "node -e \"process.env.CODEX_INFINITY_REQUIRED_GROUPS='any';require('child_process').execFileSync(process.execPath,['scripts/verify_vendor.js'],{stdio:'inherit'})\""
1113
},
1214
"type": "module",

codex-cli/scripts/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# npm releases
22

3+
## Codex Infinity local publish
4+
5+
To publish a new `@codex-infinity/codex-infinity` package with the current Rust
6+
binary:
7+
8+
```bash
9+
cd codex-cli
10+
npm run deploy
11+
```
12+
13+
This builds `codex-rs`, copies `target/release/codex` into
14+
`codex-cli/vendor/x86_64-unknown-linux-gnu/codex/codex`, bumps the package patch
15+
version, verifies the Linux x64 vendor payload, and runs `npm publish --access
16+
public`.
17+
18+
Preview the package without publishing:
19+
20+
```bash
21+
cd codex-cli
22+
npm run deploy:dry-run
23+
```
24+
25+
Use `scripts/deploy_new_binary.sh --no-bump` only when `package.json` already
26+
contains an unpublished version.
27+
28+
## OpenAI release staging
29+
330
Use the staging helper in the repo root to generate npm tarballs for a release. For
431
example, to stage the CLI, responses proxy, and SDK packages for version `0.6.0`:
532

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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

codex-cli/scripts/verify_vendor.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const platformGroups = {
1717

1818
const requiredGroups = process.env.CODEX_INFINITY_REQUIRED_GROUPS || 'any';
1919
let foundAny = false;
20+
const foundGroups = new Set();
2021

2122
for (const [group, triples] of Object.entries(platformGroups)) {
2223
for (const triple of triples) {
@@ -25,12 +26,31 @@ for (const [group, triples] of Object.entries(platformGroups)) {
2526
if (existsSync(binaryPath)) {
2627
console.log(`Found binary for ${triple}`);
2728
foundAny = true;
29+
foundGroups.add(group);
2830
break;
2931
}
3032
}
3133
}
3234

33-
if (!foundAny && requiredGroups !== 'any') {
35+
if (requiredGroups === 'any') {
36+
if (!foundAny) {
37+
console.error('No vendor binaries found');
38+
process.exit(1);
39+
}
40+
} else {
41+
const missingGroups = requiredGroups
42+
.split(',')
43+
.map((group) => group.trim())
44+
.filter(Boolean)
45+
.filter((group) => !foundGroups.has(group));
46+
47+
if (missingGroups.length > 0) {
48+
console.error(`Missing vendor binaries for: ${missingGroups.join(', ')}`);
49+
process.exit(1);
50+
}
51+
}
52+
53+
if (!foundAny) {
3454
console.error('No vendor binaries found');
3555
process.exit(1);
3656
}

0 commit comments

Comments
 (0)