Skip to content

Commit b34d50d

Browse files
Feat/consistent versioning (#18)
* ✨ Use explicit version * ✨ Silent crate add * ✨ Add versions check * ♻️ Code Refactor
1 parent fc7301c commit b34d50d

File tree

6 files changed

+74
-4
lines changed

6 files changed

+74
-4
lines changed

.github/workflows/publish-bolt-crates.yml

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ jobs:
148148
echo ${{ secrets.SYSTEM_FLY }} > target/deploy/system_fly-keypair.json
149149
echo ${{ secrets.SYSTEM_SIMPLE_MOVEMENT }} > target/deploy/system_simple_movement-keypair.json
150150
151+
- name: Check versions are aligned
152+
run: |
153+
# Fails if versions are not aligned
154+
./scripts/version-align.sh --check
155+
151156
- name: run build
152157
run: |
153158
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"

.github/workflows/publish-bolt-sdk.yml

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ jobs:
148148
echo ${{ secrets.SYSTEM_FLY }} > target/deploy/system_fly-keypair.json
149149
echo ${{ secrets.SYSTEM_SIMPLE_MOVEMENT }} > target/deploy/system_simple_movement-keypair.json
150150
151+
- name: Check versions are aligned
152+
run: |
153+
# Fails if versions are not aligned
154+
./scripts/version-align.sh --check
155+
151156
- name: run build
152157
run: |
153158
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"

.github/workflows/publish-packages.yml

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ jobs:
8989
command: build
9090
args: --manifest-path=cli/Cargo.toml --no-default-features --release --locked --target ${{ matrix.build.TARGET }}
9191

92+
- name: Check versions are aligned
93+
run: |
94+
# Fails if versions are not aligned
95+
./scripts/version-align.sh --check
96+
9297
- name: Build the NPM package
9398
shell: bash
9499
run: |

cli/npm-package/package.json.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@magicblock-labs/${node_pkg}",
33
"description": "Bolt CLI tool (${node_pkg})",
4-
"version": "${node_version}",
4+
"version": "0.0.1",
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/magicblock-labs/bolt.git"
@@ -23,4 +23,4 @@
2323
"access": "public",
2424
"registry": "https://registry.npmjs.org/"
2525
}
26-
}
26+
}

cli/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ fn init(
297297
.arg(format!("programs-ecs/components/{}", component_name))
298298
.arg("--features")
299299
.arg("cpi")
300-
.stdout(Stdio::inherit())
301-
.stderr(Stdio::inherit())
300+
.stdout(std::process::Stdio::null())
301+
.stderr(std::process::Stdio::null())
302302
.spawn()
303303
.map_err(|e| {
304304
anyhow::format_err!(

version-align.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Step 1: Read the version from Cargo.toml
6+
version=$(grep '^version = ' Cargo.toml | head -n 1 | sed 's/version = "\(.*\)"/\1/')
7+
8+
if [ -z "$version" ]; then
9+
echo "Version not found in Cargo.toml"
10+
exit 1
11+
fi
12+
13+
echo "Aligning for version: $version"
14+
15+
# GNU/BSD compat
16+
sedi=(-i'')
17+
case "$(uname)" in
18+
# For macOS, use two parameters
19+
Darwin*) sedi=(-i '')
20+
esac
21+
22+
# Update the version for all crates in the Cargo.toml workspace.dependencies section
23+
sed "${sedi[@]}" "/\[workspace.dependencies\]/,/\## External crates/s/version = \"=.*\"/version = \"=$version\"/" Cargo.toml
24+
25+
# Update the version in clients/bolt-sdk/package.json
26+
jq --arg version "$version" '.version = $version' clients/bolt-sdk/package.json > temp.json && mv temp.json clients/bolt-sdk/package.json
27+
28+
# Update the version in cli/npm-package/package.json.tmpl
29+
jq --arg version "$version" '.version = $version' cli/npm-package/package.json.tmpl > temp.json && mv temp.json cli/npm-package/package.json.tmpl
30+
31+
# Update the main package version and all optionalDependencies versions in cli/npm-package/package.json
32+
jq --arg version "$version" '(.version = $version) | (.optionalDependencies[] = $version)' cli/npm-package/package.json > temp.json && mv temp.json cli/npm-package/package.json
33+
34+
# Potential for collisions in Cargo.lock, use cargo update to update it
35+
cargo update --workspace
36+
37+
38+
# Check if the any changes have been made to the specified files, if running with --check
39+
if [[ "$1" == "--check" ]]; then
40+
files_to_check=(
41+
"clients/bolt-sdk/package.json"
42+
"cli/npm-package/package.json.tmpl"
43+
"cli/npm-package/package.json"
44+
"Cargo.toml"
45+
)
46+
47+
for file in "${files_to_check[@]}"; do
48+
# Check if the file has changed from the previous commit
49+
if git diff --name-only | grep -q "$file"; then
50+
echo "Error: version not aligned for $file. Align the version, commit and try again."
51+
exit 1
52+
fi
53+
done
54+
exit 0
55+
fi

0 commit comments

Comments
 (0)