Skip to content

Commit 0d7370f

Browse files
authored
Further improve release scripts (#185)
* Rework create-nym-vpn-desktop-release.sh * Rework create-nym-vpn-cli-release.sh * Fix error handling in bump script * Use common function * Add script for bumping desktop client to dev version * exec permission * Fix forgotten line
1 parent 691de62 commit 0d7370f

5 files changed

Lines changed: 196 additions & 123 deletions

scripts/bump-nym-vpn-cli-to-next-dev-version.sh

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,7 @@
55
# set -x
66
set -euo pipefail
77

8-
# Function to increment version and append -dev suffix
9-
increment_version() {
10-
local version=$1
11-
local IFS='.' # Internal Field Separator for splitting version parts
12-
read -r -a parts <<< "$version" # Read version into an array
13-
14-
# Validate version format (basic check)
15-
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
16-
echo "Error: Version format must be X.Y.Z (e.g., 0.0.7)" >&2
17-
exit 1
18-
fi
19-
20-
# Increment the patch version
21-
((parts[2]++))
22-
23-
# Reassemble the version and append -dev suffix
24-
local new_version="${parts[0]}.${parts[1]}.${parts[2]}-dev"
25-
26-
echo "$new_version"
27-
}
28-
29-
check_unstaged_changes() {
30-
# Confirm we don't have unstaged changes
31-
if ! git diff --exit-code > /dev/null; then
32-
echo "Error: There are unstaged changes. Please commit or stash them before running this script."
33-
exit 1
34-
fi
35-
}
8+
source "$(dirname "$0")/common.sh"
369

3710
get_current_version() {
3811
echo "$(cargo get package.version --entry="nym-vpn-cli")"
@@ -46,21 +19,20 @@ run_cargo_set_version() {
4619
echo "Running in dry-run mode: $command --dry-run"
4720
$command --dry-run
4821

49-
# Ask for user confirmation
50-
read -p "Was this the intended change? (Y/N): " answer
51-
if [[ $answer =~ ^[Yy]$ ]]; then
52-
echo "Running command without dry-run: $command"
53-
$command
54-
else
55-
echo "Exiting without making changes."
56-
exit 1
57-
fi
22+
ask_for_confirmation "$command"
5823
}
5924

6025
main() {
6126
check_unstaged_changes
27+
confirm_root_directory
6228
local version=$(get_current_version)
6329
local next_version=$(increment_version "$version")
30+
31+
if [[ -z "$next_version" ]]; then
32+
echo "Error: next_version is empty. Exiting."
33+
exit 1
34+
fi
35+
6436
run_cargo_set_version "$next_version"
6537
}
6638

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#! /usr/bin/env bash
2+
#
3+
# Bump the version of nym-vpn-desktop to the next dev version.
4+
5+
# set -x
6+
set -euo pipefail
7+
8+
source "$(dirname "$0")/common.sh"
9+
10+
NAME=nym-vpn-desktop
11+
DIRNAME=nym-vpn-desktop
12+
13+
get_current_cargo_version() {
14+
cd $DIRNAME
15+
echo "$(cargo get package.version --entry src-tauri)"
16+
cd ..
17+
}
18+
19+
run_cargo_set_version() {
20+
cd $DIRNAME/src-tauri
21+
local next_version=$1
22+
local command="cargo set-version $next_version"
23+
24+
# Run the command with --dry-run option first
25+
echo "Running in dry-run mode: $command --dry-run"
26+
$command --dry-run
27+
28+
ask_for_confirmation "$command"
29+
cd ../..
30+
}
31+
32+
run_npm_set_version() {
33+
cd $DIRNAME
34+
local next_version=$1
35+
local command="npm version $next_version"
36+
echo "Running: $command"
37+
$command
38+
cd ..
39+
}
40+
41+
main() {
42+
check_unstaged_changes
43+
confirm_root_directory
44+
local version=$(get_current_cargo_version)
45+
local next_version=$(increment_version "$version")
46+
47+
if [[ -z "$next_version" ]]; then
48+
echo "Error: next_version is empty. Exiting."
49+
exit 1
50+
fi
51+
52+
run_cargo_set_version "$next_version"
53+
run_npm_set_version "$next_version"
54+
}
55+
56+
main

scripts/common.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
check_unstaged_changes() {
2+
# Confirm we don't have unstaged changes
3+
if ! git diff --exit-code > /dev/null; then
4+
echo "Error: There are unstaged changes. Please commit or stash them before running this script."
5+
exit 1
6+
fi
7+
}
8+
9+
confirm_root_directory() {
10+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
11+
echo "Error: This script must be run from the root of a Git repository."
12+
exit 1
13+
fi
14+
15+
local git_root_dir=$(git rev-parse --show-toplevel)
16+
local current_dir=$(pwd)
17+
18+
if [[ "$git_root_dir" != "$current_dir" ]]; then
19+
echo "Error: This script must be run from the root of the Git repository. Current directory is not the root."
20+
exit 1
21+
fi
22+
}
23+
24+
ask_for_confirmation() {
25+
local command=$1
26+
read -p "Was this the intended change? (Y/N): " answer
27+
if [[ $answer =~ ^[Yy]$ ]]; then
28+
echo "Running command without dry-run: $command"
29+
$command
30+
else
31+
echo "Exiting without making changes."
32+
exit 1
33+
fi
34+
}
35+
36+
ask_and_tag_release() {
37+
local tag_name=$1
38+
local version=$2
39+
read -p "Do you want to tag this commit with: $tag_name ? (Y/N): " confirm_tag
40+
if [[ $confirm_tag =~ ^[Yy]$ ]]; then
41+
echo "Tagging the commit with tag: $tag_name"
42+
git commit -a -m "Bump $NAME to $version"
43+
git tag $tag_name
44+
# Optionally, push the tag to remote repository
45+
# git push origin $tag
46+
else
47+
echo "Not tagging."
48+
fi
49+
}
50+
51+
increment_version() {
52+
local version=$1
53+
local IFS='.' # Internal Field Separator for splitting version parts
54+
read -r -a parts <<< "$version" # Read version into an array
55+
56+
# Validate version format (basic check)
57+
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
58+
echo "Error: version=$version format must be X.Y.Z (e.g., 0.0.7)" >&2
59+
exit 1
60+
fi
61+
62+
# Increment the patch version
63+
((parts[2]++))
64+
65+
# Reassemble the version and append -dev suffix
66+
local new_version="${parts[0]}.${parts[1]}.${parts[2]}-dev"
67+
68+
echo "$new_version"
69+
}

scripts/create-nym-vpn-cli-release.sh

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,30 @@
1010
# set -x
1111
set -euo pipefail
1212

13-
# Confirm we don't have unstaged changes
14-
if ! git diff --exit-code > /dev/null; then
15-
echo "Error: There are unstaged changes. Please commit or stash them before running this script."
16-
exit 1
17-
fi
13+
source "$(dirname "$0")/common.sh"
1814

19-
# Bump the patch level version
20-
command="cargo set-version -p nym-vpn-cli --bump patch"
15+
NAME=nym-vpn-cli
16+
PACKAGE=nym-vpn-cli
2117

22-
# Run the command with --dry-run option first
23-
echo "Running in dry-run mode: $command --dry-run"
24-
$command --dry-run
18+
cargo_version_bump() {
19+
local command="cargo set-version -p $PACKAGE --bump patch"
20+
echo "Running in dry-run mode: $command --dry-run"
21+
$command --dry-run
22+
ask_for_confirmation "$command"
23+
}
2524

26-
# Ask for user confirmation
27-
read -p "Was this the intended change? (Y/N): " answer
28-
if [[ $answer =~ ^[Yy]$ ]]; then
29-
echo "Running command without dry-run: $command"
30-
$command
31-
else
32-
echo "Exiting without making changes."
33-
exit 1
34-
fi
25+
tag_release() {
26+
local version=$(cargo get package.version --entry="$PACKAGE")
27+
local tag_name="$NAME-v$version"
28+
echo "New version: $version, prepared tag: $tag_name"
29+
ask_and_tag_release "$tag_name" "$version"
30+
}
3531

36-
# Read the new version
37-
version=$(cargo get package.version --entry="nym-vpn-cli")
38-
tag_name=nym-vpn-cli-v$version
32+
main() {
33+
check_unstaged_changes
34+
confirm_root_directory
35+
cargo_version_bump
36+
tag_release
37+
}
3938

40-
# Tag the release
41-
read -p "Do you want to tag this commit with: $tag_name ? (Y/N): " confirm_tag
42-
if [[ $confirm_tag =~ ^[Yy]$ ]]; then
43-
echo "Tagging the commit with tag: $tag_name"
44-
git commit -a -m "Bump nym-vpn-cli to $version"
45-
git tag $tag_name
46-
# Optionally, push the tag to remote repository
47-
# git push origin $tag
48-
else
49-
echo "Not tagging."
50-
fi
39+
main

scripts/create-nym-vpn-desktop-release.sh

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,43 @@
1010
# set -x
1111
set -euo pipefail
1212

13-
# Confirm we don't have unstaged changes
14-
if ! git diff --exit-code > /dev/null; then
15-
echo "Error: There are unstaged changes. Please commit or stash them before running this script."
16-
exit 1
17-
fi
18-
19-
# Confirm we are in the root of the directory
20-
21-
pushd nym-vpn-desktop
22-
pushd src-tauri
23-
# Bump the patch level version
24-
command="cargo set-version --bump patch"
25-
# npm version patch
26-
# cargo set-version 0.0.6-dev
27-
# npm version 0.0.6-dev
28-
29-
# Run the command with --dry-run option first
30-
echo "Running in dry-run mode: $command --dry-run"
31-
$command --dry-run
32-
33-
# Ask for user confirmation
34-
read -p "Was this the intended change? (Y/N): " answer
35-
if [[ $answer =~ ^[Yy]$ ]]; then
36-
echo "Running command without dry-run: $command"
37-
$command
38-
else
39-
echo "Exiting without making changes."
40-
exit 1
41-
fi
42-
43-
popd
44-
45-
# We can't run this with --dry-run, so let's assume it will be fine
46-
command_npm="npm version patch"
47-
echo "Running: $command_npm"
48-
$command_npm
49-
50-
# Read the new version
51-
# version=$(cargo get package.version --entry="nym-vpn-desktop")
52-
version=$(cargo get package.version --entry src-tauri)
53-
tag_name=nym-vpn-desktop-v$version
54-
55-
# Tag the release
56-
read -p "Do you want to tag this commit with: $tag_name ? (Y/N): " confirm_tag
57-
if [[ $confirm_tag =~ ^[Yy]$ ]]; then
58-
echo "Tagging the commit with tag: $tag_name"
59-
git commit -a -m "Bump nym-vpn-desktop to $version"
60-
git tag $tag_name
61-
# Optionally, push the tag to remote repository
62-
# git push origin $tag
63-
else
64-
echo "Not tagging."
65-
fi
13+
source "$(dirname "$0")/common.sh"
14+
15+
NAME=nym-vpn-desktop
16+
DIRNAME=nym-vpn-desktop
17+
18+
cargo_version_bump() {
19+
cd $DIRNAME/src-tauri
20+
local command="cargo set-version --bump patch"
21+
echo "Running in dry-run mode: $command --dry-run"
22+
$command --dry-run
23+
ask_for_confirmation "$command"
24+
cd ../..
25+
}
26+
27+
npm_version_bump() {
28+
# We can't run this with --dry-run, so let's assume it will be fine
29+
cd $DIRNAME
30+
local command_npm="npm version patch"
31+
echo "Running: $command_npm"
32+
$command_npm
33+
cd ..
34+
}
35+
36+
tag_release() {
37+
cd $DIRNAME
38+
local version=$(cargo get package.version --entry src-tauri)
39+
local tag_name="$NAME-v$version"
40+
echo "New version: $version, Tag: $tag_name"
41+
ask_and_tag_release "$tag_name" "$version"
42+
}
43+
44+
main() {
45+
check_unstaged_changes
46+
confirm_root_directory
47+
cargo_version_bump
48+
npm_version_bump
49+
tag_release
50+
}
51+
52+
main

0 commit comments

Comments
 (0)