Skip to content

Commit

Permalink
Feat/consistent versioning (#18)
Browse files Browse the repository at this point in the history
* ✨ Use explicit version

* ✨ Silent crate add

* ✨ Add versions check

* ♻️ Code Refactor
  • Loading branch information
GabrielePicco committed Feb 24, 2024
1 parent fc7301c commit b34d50d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/publish-bolt-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ jobs:
echo ${{ secrets.SYSTEM_FLY }} > target/deploy/system_fly-keypair.json
echo ${{ secrets.SYSTEM_SIMPLE_MOVEMENT }} > target/deploy/system_simple_movement-keypair.json
- name: Check versions are aligned
run: |
# Fails if versions are not aligned
./scripts/version-align.sh --check
- name: run build
run: |
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/publish-bolt-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ jobs:
echo ${{ secrets.SYSTEM_FLY }} > target/deploy/system_fly-keypair.json
echo ${{ secrets.SYSTEM_SIMPLE_MOVEMENT }} > target/deploy/system_simple_movement-keypair.json
- name: Check versions are aligned
run: |
# Fails if versions are not aligned
./scripts/version-align.sh --check
- name: run build
run: |
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ jobs:
command: build
args: --manifest-path=cli/Cargo.toml --no-default-features --release --locked --target ${{ matrix.build.TARGET }}

- name: Check versions are aligned
run: |
# Fails if versions are not aligned
./scripts/version-align.sh --check
- name: Build the NPM package
shell: bash
run: |
Expand Down
4 changes: 2 additions & 2 deletions cli/npm-package/package.json.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@magicblock-labs/${node_pkg}",
"description": "Bolt CLI tool (${node_pkg})",
"version": "${node_version}",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "git+https://github.com/magicblock-labs/bolt.git"
Expand All @@ -23,4 +23,4 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
4 changes: 2 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ fn init(
.arg(format!("programs-ecs/components/{}", component_name))
.arg("--features")
.arg("cpi")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.spawn()
.map_err(|e| {
anyhow::format_err!(
Expand Down
55 changes: 55 additions & 0 deletions version-align.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

set -e

# Step 1: Read the version from Cargo.toml
version=$(grep '^version = ' Cargo.toml | head -n 1 | sed 's/version = "\(.*\)"/\1/')

if [ -z "$version" ]; then
echo "Version not found in Cargo.toml"
exit 1
fi

echo "Aligning for version: $version"

# GNU/BSD compat
sedi=(-i'')
case "$(uname)" in
# For macOS, use two parameters
Darwin*) sedi=(-i '')
esac

# Update the version for all crates in the Cargo.toml workspace.dependencies section
sed "${sedi[@]}" "/\[workspace.dependencies\]/,/\## External crates/s/version = \"=.*\"/version = \"=$version\"/" Cargo.toml

# Update the version in clients/bolt-sdk/package.json
jq --arg version "$version" '.version = $version' clients/bolt-sdk/package.json > temp.json && mv temp.json clients/bolt-sdk/package.json

# Update the version in cli/npm-package/package.json.tmpl
jq --arg version "$version" '.version = $version' cli/npm-package/package.json.tmpl > temp.json && mv temp.json cli/npm-package/package.json.tmpl

# Update the main package version and all optionalDependencies versions in cli/npm-package/package.json
jq --arg version "$version" '(.version = $version) | (.optionalDependencies[] = $version)' cli/npm-package/package.json > temp.json && mv temp.json cli/npm-package/package.json

# Potential for collisions in Cargo.lock, use cargo update to update it
cargo update --workspace


# Check if the any changes have been made to the specified files, if running with --check
if [[ "$1" == "--check" ]]; then
files_to_check=(
"clients/bolt-sdk/package.json"
"cli/npm-package/package.json.tmpl"
"cli/npm-package/package.json"
"Cargo.toml"
)

for file in "${files_to_check[@]}"; do
# Check if the file has changed from the previous commit
if git diff --name-only | grep -q "$file"; then
echo "Error: version not aligned for $file. Align the version, commit and try again."
exit 1
fi
done
exit 0
fi

0 comments on commit b34d50d

Please sign in to comment.