-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion-sync.sh
More file actions
executable file
·93 lines (81 loc) · 3.95 KB
/
Copy pathversion-sync.sh
File metadata and controls
executable file
·93 lines (81 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
# Stamps the release version into every packaging artifact that carries one:
# - Cargo.toml (workspace version + socket-patch-core exact pin)
# - npm/socket-patch/package.json (+ optionalDependencies, package-lock.json)
# - npm/socket-patch-*/package.json (per-platform packages)
# - pypi/socket-patch/pyproject.toml + pypi/socket-patch-hook/pyproject.toml
# - gem/socket-patch-bundler/socket-patch-bundler.gemspec
# - gem/socket-patch/socket-patch.gemspec + lib/socket_patch/launcher.rb
set -euo pipefail
VERSION="${1:?Usage: version-sync.sh <version>}"
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
# Update workspace Cargo.toml version
sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" "$REPO_ROOT/Cargo.toml"
rm -f "$REPO_ROOT/Cargo.toml.bak"
# Update socket-patch-core workspace dependency version (needed for cargo publish).
# The version spec is exact-pinned with a leading "=" per the repo's pinning policy.
sed -i.bak "s/socket-patch-core = { path = \"crates\/socket-patch-core\", version = \".*\" }/socket-patch-core = { path = \"crates\/socket-patch-core\", version = \"=$VERSION\" }/" "$REPO_ROOT/Cargo.toml"
rm -f "$REPO_ROOT/Cargo.toml.bak"
# Update npm main package version and optionalDependencies versions
pkg_json="$REPO_ROOT/npm/socket-patch/package.json"
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('$pkg_json', 'utf8'));
pkg.version = '$VERSION';
if (pkg.optionalDependencies) {
for (const dep of Object.keys(pkg.optionalDependencies)) {
pkg.optionalDependencies[dep] = '$VERSION';
}
}
fs.writeFileSync('$pkg_json', JSON.stringify(pkg, null, 2) + '\n');
"
# Refresh the npm wrapper lockfile so package-lock.json stays in sync with the
# bumped package.json (own version, optionalDependencies). Uses --package-lock-only
# so node_modules is untouched.
(
cd "$REPO_ROOT/npm/socket-patch"
npm install --package-lock-only --ignore-scripts >/dev/null
)
# Update all per-platform npm package versions
for platform_dir in "$REPO_ROOT"/npm/socket-patch-*/; do
platform_pkg="$platform_dir/package.json"
if [ -f "$platform_pkg" ]; then
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('$platform_pkg', 'utf8'));
pkg.version = '$VERSION';
fs.writeFileSync('$platform_pkg', JSON.stringify(pkg, null, 2) + '\n');
"
fi
done
# Update PyPI package version
pyproject="$REPO_ROOT/pypi/socket-patch/pyproject.toml"
sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" "$pyproject"
rm -f "$pyproject.bak"
# Update the PyPI hook package version. The release build (build-pypi-wheels.py)
# injects --version at wheel-build time, so this keeps the source-of-truth
# pyproject.toml in sync for local builds and avoids a stale version field.
hook_pyproject="$REPO_ROOT/pypi/socket-patch-hook/pyproject.toml"
sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" "$hook_pyproject"
rm -f "$hook_pyproject.bak"
# Update the Ruby Bundler-plugin gem version (Phase 2 scaffolding). The in-tree
# plugin is the active mechanism today; keep the published gem's version in sync
# so a release publishes a version matching the CLI.
gemspec="$REPO_ROOT/gem/socket-patch-bundler/socket-patch-bundler.gemspec"
if [ -f "$gemspec" ]; then
sed -i.bak "s/s\.version *= *\".*\"/s.version = \"$VERSION\"/" "$gemspec"
rm -f "$gemspec.bak"
fi
# Update the RubyGems CLI launcher gem (gemspec version + the VERSION constant
# the launcher uses to pick the matching GitHub release binary).
ruby_cli_gemspec="$REPO_ROOT/gem/socket-patch/socket-patch.gemspec"
if [ -f "$ruby_cli_gemspec" ]; then
sed -i.bak "s/s\.version *= *\".*\"/s.version = \"$VERSION\"/" "$ruby_cli_gemspec"
rm -f "$ruby_cli_gemspec.bak"
fi
ruby_cli_launcher="$REPO_ROOT/gem/socket-patch/lib/socket_patch/launcher.rb"
if [ -f "$ruby_cli_launcher" ]; then
sed -i.bak "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" "$ruby_cli_launcher"
rm -f "$ruby_cli_launcher.bak"
fi
echo "Synced version to $VERSION"