-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.sh
executable file
·129 lines (115 loc) · 2.7 KB
/
scripts.sh
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
set -eu
install() {
echo "Installing dependencies..."
bundle install
echo "Dependencies installed."
}
# Function to build the package
build() {
echo "Building the package..."
gem build PCP-server-Ruby-SDK.gemspec
echo "Build complete."
}
lint() {
echo "Formatting the code..."
bundle exec rake -- rubocop
echo "Format complete."
}
# Function to run tests
test() {
echo "Running tests..."
bundle exec rake spec
echo "Tests complete."
}
version() {
# example: ./scripts.sh version 1.0.0
if [ -z "$2" ]; then
echo "Please provide the version."
exit 1
fi
echo "Running version..."
NEW_VERSION=$2
VERSION_FILE_PATH="./lib/PCP-server-Ruby-SDK/version.rb"
# Update the version in the version.rb file
if [ -f $VERSION_FILE_PATH ]; then
sed -i '' "s/VERSION = '.*'/VERSION = '$NEW_VERSION'/" "$VERSION_FILE_PATH"
if grep -q "VERSION = '$NEW_VERSION'" "$VERSION_FILE_PATH"; then
echo "Version updated successfully to $NEW_VERSION in $VERSION_FILE_PATH"
else
echo "Failed to update the version in $VERSION_FILE_PATH"
exit 1
fi
else
echo "Version file not found at $VERSION_FILE_PATH"
exit 1
fi
# Commit and tag the changes
git add $VERSION_FILE_PATH
npm install
npm run changelog
git add CHANGELOG.md
git tag -a v$NEW_VERSION -m "Version $NEW_VERSION"
git commit -m "chore: update version to $NEW_VERSION"
git push origin tag v$NEW_VERSION
git push -u origin HEAD
echo "Version complete."
}
clear() {
echo "Removing temp directories..."
rm -f PCP-server-Ruby-SDK-*.gem
rm -f Gemfile.lock
rm -rf node_modules/
echo "All temp directories have been removed."
}
publish() {
# example: ./scripts.sh publish <RubyGems token>
# check if the RubyGems token is passed
if [ -z "$2" ]; then
echo "Please provide the RubyGems token."
exit 1
fi
echo "Uploading the package..."
# Set the environment variable for RubyGems
export GEM_HOST_API_KEY=$2
VERSION=$(git describe --tags --abbrev=0 | sed 's/^v//')
GEM_NAME=pcp-server-ruby-sdk-$VERSION.gem
# Push the gem to RubyGems
gem push $GEM_NAME
echo "Upload complete."
}
run() {
echo "Running the package..."
ruby example-app/example.rb
}
# Check the first argument passed to the script
case "$1" in
install)
install
;;
build)
build
;;
test)
test
;;
lint)
lint
;;
clear)
clear
;;
version)
version $@
;;
publish)
publish $@
;;
run)
run
;;
*)
echo "Usage: $0 {install|build|test|lint|clear|version|publish|run}"
exit 1
;;
esac