From ffad183114d4456a2e61414025c1fed6615f77b5 Mon Sep 17 00:00:00 2001 From: "huyikun.hyk" Date: Wed, 17 Jan 2024 10:04:06 +0800 Subject: [PATCH 1/4] feat: check nodejs. --- script.sh | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/script.sh b/script.sh index 349c5c7..00c1282 100755 --- a/script.sh +++ b/script.sh @@ -1,28 +1,33 @@ set -e # 报错后不继续执行 -LOCAL_VERSION=$(node -v) -REQUIRED_VERSION='v14.14.0' -echo 'Checking nodejs version, serverless-dev requires nodejs >= 14.14.0.' -echo "Local nodejs's version is" $LOCAL_VERSION. -function version_compare() { - if [[ "$1" == "$2" ]]; then - echo 0 # 本地版本等于要求版本 - return - fi - if [[ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" == "$1" ]]; then - echo 1 # 本地版本小于要求版本 +if ! which node > /dev/null; then + echo "Node is not installed, serverless-dev requires nodejs >= 14.14.0." + echo "You can install it manually or add actions/setup-node@v4 before actions/setup-s-aliyun in your .yaml/.yml file." +else + LOCAL_VERSION=$(node -v) + REQUIRED_VERSION='v14.14.0' + echo 'Checking nodejs version, serverless-dev requires nodejs >= 14.14.0.' + echo "Local nodejs's version is" $LOCAL_VERSION. + function version_compare() { + if [[ "$1" == "$2" ]]; then + echo 0 # 本地版本等于要求版本 + return + fi + if [[ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" == "$1" ]]; then + echo 1 # 本地版本小于要求版本 + else + echo 0 # 本地版本大于要求版本 + fi + } + result=$(version_compare "$LOCAL_VERSION" "$REQUIRED_VERSION") + if [ "$result" == 0 ]; then + echo 'Nodejs checked, serverless-devs installing.' + npm i @serverless-devs/s -g --registry=https://registry.npmmirror.com + s config add --AccountID $1 --AccessKeyID $2 --AccessKeySecret $3 -a $4 -f + echo '################################################' + echo 'Serverless-devs has been installed successfully.' + echo 'The access has been configured automatically, use "s config get" to check.' + echo '################################################' else - echo 0 # 本地版本大于要求版本 + echo "Serverless-dev requires nodejs >= 14.14.0, please update your local nodejs's version." fi -} -result=$(version_compare "$LOCAL_VERSION" "$REQUIRED_VERSION") -if [ "$result" == 0 ]; then - echo 'Nodejs checked, serverless-devs installing.' - npm i @serverless-devs/s -g --registry=https://registry.npmmirror.com - s config add --AccountID $1 --AccessKeyID $2 --AccessKeySecret $3 -a $4 -f - echo '################################################' - echo 'Serverless-devs has been installed successfully.' - echo 'The access has been configured automatically, use "s config get" to check.' - echo '################################################' -else - echo "Serverless-dev requires nodejs >= 14.14.0, please update your local nodejs's version." -fi \ No newline at end of file +fi From 02040013b347f567415986c1be9b8fbb49e34f52 Mon Sep 17 00:00:00 2001 From: "huyikun.hyk" Date: Wed, 17 Jan 2024 14:18:28 +0800 Subject: [PATCH 2/4] feat: use binary-file to execute. --- action.yml | 2 +- binary.sh | 9 +++++++++ script.sh | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 binary.sh mode change 100755 => 100644 script.sh diff --git a/action.yml b/action.yml index fb01ab3..7ca11f9 100644 --- a/action.yml +++ b/action.yml @@ -23,5 +23,5 @@ inputs: runs: using: "composite" steps: - - run: ./script.sh ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} + - run: ./binary.sh ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} shell: bash \ No newline at end of file diff --git a/binary.sh b/binary.sh new file mode 100644 index 0000000..15e452a --- /dev/null +++ b/binary.sh @@ -0,0 +1,9 @@ +set -e # 报错后不继续执行 +echo 'Serverless-devs installing.' +curl https://images.devsapp.cn/bin/s/v3.0.0 --output /usr/local/bin/s +chmod 777 /usr/local/bin/s +echo '################################################' +s config add --AccountID $1 --AccessKeyID $2 --AccessKeySecret $3 -a $4 -f +echo '################################################' +echo 'Serverless-devs has been installed successfully.' +echo 'The access has been configured automatically, use "s config get" to check.' \ No newline at end of file diff --git a/script.sh b/script.sh old mode 100755 new mode 100644 index 00c1282..c9c7c4b --- a/script.sh +++ b/script.sh @@ -1,3 +1,5 @@ +# unused + set -e # 报错后不继续执行 if ! which node > /dev/null; then echo "Node is not installed, serverless-dev requires nodejs >= 14.14.0." @@ -22,11 +24,11 @@ else if [ "$result" == 0 ]; then echo 'Nodejs checked, serverless-devs installing.' npm i @serverless-devs/s -g --registry=https://registry.npmmirror.com + echo '################################################' s config add --AccountID $1 --AccessKeyID $2 --AccessKeySecret $3 -a $4 -f echo '################################################' echo 'Serverless-devs has been installed successfully.' echo 'The access has been configured automatically, use "s config get" to check.' - echo '################################################' else echo "Serverless-dev requires nodejs >= 14.14.0, please update your local nodejs's version." fi From 2d0872126ae6cf99a23cac818860a24005787dce Mon Sep 17 00:00:00 2001 From: "huyikun.hyk" Date: Wed, 17 Jan 2024 14:21:00 +0800 Subject: [PATCH 3/4] change: clean --- action.yml | 2 +- binary.sh | 9 --------- script.sh | 42 ++++++++---------------------------------- 3 files changed, 9 insertions(+), 44 deletions(-) delete mode 100644 binary.sh diff --git a/action.yml b/action.yml index 7ca11f9..fb01ab3 100644 --- a/action.yml +++ b/action.yml @@ -23,5 +23,5 @@ inputs: runs: using: "composite" steps: - - run: ./binary.sh ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} + - run: ./script.sh ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} shell: bash \ No newline at end of file diff --git a/binary.sh b/binary.sh deleted file mode 100644 index 15e452a..0000000 --- a/binary.sh +++ /dev/null @@ -1,9 +0,0 @@ -set -e # 报错后不继续执行 -echo 'Serverless-devs installing.' -curl https://images.devsapp.cn/bin/s/v3.0.0 --output /usr/local/bin/s -chmod 777 /usr/local/bin/s -echo '################################################' -s config add --AccountID $1 --AccessKeyID $2 --AccessKeySecret $3 -a $4 -f -echo '################################################' -echo 'Serverless-devs has been installed successfully.' -echo 'The access has been configured automatically, use "s config get" to check.' \ No newline at end of file diff --git a/script.sh b/script.sh index c9c7c4b..15e452a 100644 --- a/script.sh +++ b/script.sh @@ -1,35 +1,9 @@ -# unused - set -e # 报错后不继续执行 -if ! which node > /dev/null; then - echo "Node is not installed, serverless-dev requires nodejs >= 14.14.0." - echo "You can install it manually or add actions/setup-node@v4 before actions/setup-s-aliyun in your .yaml/.yml file." -else - LOCAL_VERSION=$(node -v) - REQUIRED_VERSION='v14.14.0' - echo 'Checking nodejs version, serverless-dev requires nodejs >= 14.14.0.' - echo "Local nodejs's version is" $LOCAL_VERSION. - function version_compare() { - if [[ "$1" == "$2" ]]; then - echo 0 # 本地版本等于要求版本 - return - fi - if [[ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" == "$1" ]]; then - echo 1 # 本地版本小于要求版本 - else - echo 0 # 本地版本大于要求版本 - fi - } - result=$(version_compare "$LOCAL_VERSION" "$REQUIRED_VERSION") - if [ "$result" == 0 ]; then - echo 'Nodejs checked, serverless-devs installing.' - npm i @serverless-devs/s -g --registry=https://registry.npmmirror.com - echo '################################################' - s config add --AccountID $1 --AccessKeyID $2 --AccessKeySecret $3 -a $4 -f - echo '################################################' - echo 'Serverless-devs has been installed successfully.' - echo 'The access has been configured automatically, use "s config get" to check.' - else - echo "Serverless-dev requires nodejs >= 14.14.0, please update your local nodejs's version." - fi -fi +echo 'Serverless-devs installing.' +curl https://images.devsapp.cn/bin/s/v3.0.0 --output /usr/local/bin/s +chmod 777 /usr/local/bin/s +echo '################################################' +s config add --AccountID $1 --AccessKeyID $2 --AccessKeySecret $3 -a $4 -f +echo '################################################' +echo 'Serverless-devs has been installed successfully.' +echo 'The access has been configured automatically, use "s config get" to check.' \ No newline at end of file From 5b9b601ed85505c11f41698d6329c9b2085ac944 Mon Sep 17 00:00:00 2001 From: "huyikun.hyk" Date: Wed, 17 Jan 2024 14:23:49 +0800 Subject: [PATCH 4/4] change: add execute permission. --- script.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 script.sh diff --git a/script.sh b/script.sh old mode 100644 new mode 100755