From 4509b926fc8a546f256f5388552b0b2d04fc73d9 Mon Sep 17 00:00:00 2001 From: "huyikun.hyk" Date: Mon, 26 Feb 2024 15:56:51 +0800 Subject: [PATCH] feat: setup-s Signed-off-by: huyikun.hyk --- .github/workflows/ci.yml | 17 +++++++++++++--- action.yml | 43 ++++++++++++++++++++++++++++------------ script.sh | 13 +++++++++--- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab60b88..ed1bae9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,9 +6,9 @@ name: CI on: # Triggers the workflow on push or pull request events but only for the "main" branch push: - branches: [ "main", "v0.0.1" ] + branches: [ "main", "setup-s" ] pull_request: - branches: [ "main", "v0.0.1" ] + branches: [ "main", "setup-s" ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -34,9 +34,20 @@ jobs: # Runs my action - name: Setup serverless-devs - id: setup-serverless-devs + id: setup-s-aliyun uses: ./ with: + provider: aliyun + account_id: MOCK_ACCOUNT_ID + access_key_id: MOCK_KEY_ID + access_key_secret: MOCK_KEY_SECRET + access: MOCK_ACCESS_ALIAS + + - name: Setup serverless-devs + id: setup-s-tencent + uses: ./ + with: + provider: tencent account_id: MOCK_ACCOUNT_ID access_key_id: MOCK_KEY_ID access_key_secret: MOCK_KEY_SECRET diff --git a/action.yml b/action.yml index ccb7be8..9ddeb34 100644 --- a/action.yml +++ b/action.yml @@ -1,24 +1,28 @@ -name: 'Setup Aliyun Serverless-Devs' -description: 'An Action for Setup Aliyun Serverless-Devs' +name: 'Setup for Serverless-Devs' +description: 'An Action for Setup Serverless-Devs and Different Provider's Authorization Config' author: 'heimanba' branding: icon: 'heart' color: 'red' inputs: - account_id: - description: 'Aliyun Main Account ID' - required: true - access_key_id: - description: 'Aliyun Access Key ID' - required: true - access_key_secret: - description: 'Aliyun Access Key Secret' + provider: + description: 'Provider Name (aliyun/aws/tencent/huawei)' required: true + default: 'aliyun' access: description: 'Access Alias Name' required: true - default: 'default' + default: ${{ inputs.provider }}_access + account_id: + description: 'Main Account ID' + required: false + access_key_id: + description: 'Access Key ID' + required: false + access_key_secret: + description: 'Access Key Secret' + required: false version: description: 'Serverless-devs Version, 3.0.0 as default.' required: false @@ -27,5 +31,18 @@ inputs: runs: using: "composite" steps: - - run: ./script.sh ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} ${{ inputs.version }} - shell: bash \ No newline at end of file + - run: ./script.sh ${{inputs.provider}} ${{ inputs.version }} ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} + shell: bash + if: ${{ inputs.provider === 'aliyun' }} + + - run: ./script.sh ${{inputs.provider}} ${{ inputs.version }} ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} + shell: bash + if: ${{ inputs.provider === 'aws' }} + + - run: ./script.sh ${{inputs.provider}} ${{ inputs.version }} ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} + shell: bash + if: ${{ inputs.provider === 'tencent' }} + + - run: ./script.sh ${{inputs.provider}} ${{ inputs.version }} ${{ inputs.account_id }} ${{ inputs.access_key_id }} ${{ inputs.access_key_secret }} ${{ inputs.access }} + shell: bash + if: ${{ inputs.provider === 'huawei' }} diff --git a/script.sh b/script.sh index 20f2062..87adfa4 100755 --- a/script.sh +++ b/script.sh @@ -2,7 +2,7 @@ # 执行命令并捕获输出 VERSION_OUTPUT=$(s -v) -version=$5 +version=$2 set -e # 报错后不继续执行 # 检查输出是否包含版本号的格式 @@ -11,13 +11,20 @@ if [[ $VERSION_OUTPUT ]]; then echo "Version output is valid: $EXTRACTED_CONTENT" else echo 'Serverless-devs installing.' - curl "https://images.devsapp.cn/bin/s/${version}" --output /usr/local/bin/s + curl "https://images.devsapp.cn/bin/s/v${version}" --output /usr/local/bin/s chmod 777 /usr/local/bin/s echo 'Serverless-devs has been installed successfully.' fi echo '################################################' -s config add --AccountID $1 --AccessKeyID $2 --AccessKeySecret $3 -a $4 -f +if [[ $1 == "aliyun" ]]; then + s config add --AccountID $3 --AccessKeyID $4 --AccessKeySecret $5 -a $6 -f +elif [[ $1 == "aws" ]]; then + s config add --AccessKeyID $3 --SecretAccessKey $4 -a $5 -f +elif [[ $1 == "huawei" ]]; then + s config add --AccessKeyID $3 --SecretAccessKey $4 -a $5 -f +elif [[ $1 == "tencent" ]]; then + s config add --AccountID $3 --SecretID $4 --SecretKey $5 -a $6 -f echo '################################################' echo 'The access has been configured automatically, use "s config get" to check.'