Skip to content

Commit 47c430c

Browse files
authored
improve scripts (#1083)
- use `bash` instead of `sh` more info or reason see Shell Style Guide of google: https://google.github.io/styleguide/shellguide.html#which-shell-to-use - fix shellcheck warning - use -z instead of `! -n` - SC2086 Double quote to prevent globbing and word splitting - check_format.sh - call `git status` one time
1 parent 5f3dd7e commit 47c430c

File tree

6 files changed

+58
-52
lines changed

6 files changed

+58
-52
lines changed

.github/workflows/maven.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
with:
2121
java-version: 1.8
2222
- name: Build with Maven
23-
run: ./mvnw clean install -Pci-install -B -U -e && sh ./tools/check_format.sh
23+
run: ./mvnw clean install -Pci-install -B -U -e && bash ./tools/check_format.sh
2424
- name: Test with Maven
2525
run: ./mvnw package -Pci-test
2626
- name: Codecov

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cache:
1212

1313
install:
1414
- ./mvnw clean install -Pci-install -B -U -e
15-
- sh ./tools/check_format.sh
15+
- bash ./tools/check_format.sh
1616

1717
script:
1818
- ./mvnw package -Pci-test

registry/registry-nacos/src/test/scripts/start-nacos-server.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ echo "Downloading Nacos 0.6.0"
44
wget https://github.com/alibaba/nacos/releases/download/0.6.0/nacos-server-0.6.0.zip -O nacos-server-0.6.0.zip
55
unzip -qo nacos-server-0.6.0.zip
66

7-
nohup bash $PWD/nacos/bin/startup.sh -m standalone >> $PWD/nacos/start.out 2>&1 &
8-
sleep 10
7+
nohup bash "$PWD"/nacos/bin/startup.sh -m standalone >> "$PWD"/nacos/start.out 2>&1 &
8+
sleep 10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

3-
if [ -f "$PWD/nacos/bin/shutdown.sh" ]
4-
then
5-
bash $PWD/nacos/bin/shutdown.sh
3+
readonly shutdown_script="$PWD/nacos/bin/shutdown.sh"
4+
5+
if [ -f "$shutdown_script" ]; then
6+
bash "$shutdown_script"
67
fi

tools/change_version.sh

+40-37
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,61 @@
11
#!/bin/bash
2-
shellDir=$(cd "$(dirname "$0")"; pwd)
2+
3+
shellDir=$(
4+
cd "$(dirname "$0")"
5+
pwd
6+
)
37

48
shopt -s expand_aliases
5-
if [ ! -n "$1" ] ;then
6-
echo "Please enter a version"
7-
exit 1
9+
if [ -z "$1" ]; then
10+
echo "Please enter a version"
11+
exit 1
812
else
9-
echo "The version is $1 !"
13+
echo "The version is $1 !"
1014
fi
1115

12-
if [ `uname` == "Darwin" ] ;then
13-
echo "This is OS X"
14-
alias sed='sed -i ""'
16+
if [ "$(uname)" == "Darwin" ]; then
17+
echo "This is OS X"
18+
alias sed='sed -i ""'
1519
else
16-
echo "This is Linux"
17-
alias sed='sed -i'
20+
echo "This is Linux"
21+
alias sed='sed -i'
1822
fi
1923

2024
echo "Change version in root pom.xml ===>"
21-
sed "s/<revision>.*<\/revision>/<revision>$1<\/revision>/" $shellDir/../pom.xml
25+
sed "s/<revision>.*<\/revision>/<revision>$1<\/revision>/" "$shellDir"/../pom.xml
2226

2327
echo "Change version in sofa-rpc-all ===>"
24-
sed "/<project /,/<name/ s/<version>[^\$].*<\/version>/<version>$1<\/version>/" $shellDir/../all/pom.xml
28+
sed "/<project /,/<name/ s/<version>[^\$].*<\/version>/<version>$1<\/version>/" "$shellDir"/../all/pom.xml
2529

2630
echo "Change version in sofa-rpc-bom ===>"
27-
sed "s/<revision>.*<\/revision>/<revision>$1<\/revision>/" $shellDir/../bom/pom.xml
28-
31+
sed "s/<revision>.*<\/revision>/<revision>$1<\/revision>/" "$shellDir"/../bom/pom.xml
2932

3033
# echo "Change version in MANIFEST.MF"
3134
# echo "Deal with MANIFEST.MF"
3235
# sed "s/Plugin-Version.*/Plugin-Version: $1.common/g" $shellDir/../sofa-rpc-plugin/src/main/resources/META-INF/MANIFEST.MF
3336

3437
version_java_file="$shellDir/../core/api/src/main/java/com/alipay/sofa/rpc/common/Version.java"
35-
if [ -f $version_java_file ]; then
36-
37-
echo "=================="
38-
echo " WARN: You need to modify \"core/api/src/main/java/com/alipay/sofa/rpc/common/Version.java\" "
39-
echo "=================="
40-
41-
version_str=$(echo $1 | \sed -e "s/[^0-9\.]//g")
42-
echo "VERSION is ${version_str}"
43-
sed "s/\(VERSION[ ]*=[ ]*\"\).*$/\1${version_str}\";/g" $version_java_file
44-
45-
# number and dot -> padding bugfix version -> padding minor version -> padding major version -> only leave number
46-
rpc_version=$(echo $1 | \sed -e "s/[^0-9\.]//g" \
47-
-e "s/\.\([0-9]\)$/\.0\1/" \
48-
-e "s/\.\([0-9]\)\./\.0\1\./g" \
49-
-e "s/^\([0-9]\)\./\1\./g" \
50-
-e "s/[^0-9]//g")
51-
echo "RPC_VERSION is ${rpc_version}"
52-
sed "s/\(RPC_VERSION[ ]*=[ ]*\).*$/\1${rpc_version};/g" $version_java_file
53-
54-
date_format=$(date +"%Y%m%d%H%M%S")
55-
build_version=${version_str}_${date_format}
56-
echo "BUILD_VERSION is ${build_version}"
57-
sed "s/\(BUILD_VERSION[ ]*=[ ]*\"\).*$/\1${build_version}\";/g" $version_java_file
38+
if [ -f "$version_java_file" ]; then
39+
40+
echo "=================="
41+
echo " WARN: You need to modify \"core/api/src/main/java/com/alipay/sofa/rpc/common/Version.java\" "
42+
echo "=================="
43+
44+
version_str=$(echo "$1" | \sed -e "s/[^0-9\.]//g")
45+
echo "VERSION is ${version_str}"
46+
sed "s/\(VERSION[ ]*=[ ]*\"\).*$/\1${version_str}\";/g" "$version_java_file"
47+
48+
# number and dot -> padding bugfix version -> padding minor version -> padding major version -> only leave number
49+
rpc_version=$(echo "$1" | \sed -e "s/[^0-9\.]//g" \
50+
-e "s/\.\([0-9]\)$/\.0\1/" \
51+
-e "s/\.\([0-9]\)\./\.0\1\./g" \
52+
-e "s/^\([0-9]\)\./\1\./g" \
53+
-e "s/[^0-9]//g")
54+
echo "RPC_VERSION is ${rpc_version}"
55+
sed "s/\(RPC_VERSION[ ]*=[ ]*\).*$/\1${rpc_version};/g" "$version_java_file"
56+
57+
date_format=$(date +"%Y%m%d%H%M%S")
58+
build_version=${version_str}_${date_format}
59+
echo "BUILD_VERSION is ${build_version}"
60+
sed "s/\(BUILD_VERSION[ ]*=[ ]*\"\).*$/\1${build_version}\";/g" "$version_java_file"
5861
fi

tools/check_format.sh

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
set -eEuo pipefail
23

3-
BASEDIR=$(dirname $0)
4+
BASEDIR=$(dirname "$0")
5+
cd "${BASEDIR}"
46

5-
cd ${BASEDIR}
7+
git_status="$(git status --untracked-files=no --porcelain)"
68

79
# make sure git has no un commit files
8-
if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
9-
echo "Please commit your change before run this shell, un commit files:"
10-
git status --untracked-files=no --porcelain
11-
exit 1
12-
fi
10+
if [ -n "$git_status" ]; then
11+
echo "Please commit your change before run this shell, un commit files:"
12+
echo "$git_status"
13+
exit 1
14+
fi

0 commit comments

Comments
 (0)