diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18a6a3e..ab60b88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,13 +6,16 @@ name: CI on: # Triggers the workflow on push or pull request events but only for the "main" branch push: - branches: [ "main" ] + branches: [ "main", "v0.0.1" ] pull_request: - branches: [ "main" ] + branches: [ "main", "v0.0.1" ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +permissions: + contents: read + # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" @@ -24,13 +27,17 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 + + - uses: actions/setup-node@v4 + with: + node-version: 14.14.0 - # Runs a single command using the runners shell - - name: Run a one-line script - run: echo Hello, world! - - # Runs a set of commands using the runners shell - - name: Run a multi-line script - run: | - echo Add other actions to build, - echo test, and deploy your project. + # Runs my action + - name: Setup serverless-devs + id: setup-serverless-devs + uses: ./ + with: + account_id: MOCK_ACCOUNT_ID + access_key_id: MOCK_KEY_ID + access_key_secret: MOCK_KEY_SECRET + access: MOCK_ACCESS_ALIAS \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..67a79cb --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ + +## Usage + +To include the action in a workflow in another repository, you can use the +`uses` syntax with the `@` symbol to reference a specific branch, tag, or commit +hash. + +```yaml +steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Setup Node + id: setupnode + uses: actions/setup-node@v4 + with: + node-version: 14.14.0 + + - name: Setup Serverless-devs + uses: actions/setup-s-aliyun@v1 + with: + account_id: ${{ secrets.ACCOUNT_ID }} + access_key_id: ${{ secrets.ACCESS_KEYID }} + access_key_secret: ${{ secrets.ACCESS_KEYSECRET }} + access: default +``` diff --git a/action.yml b/action.yml index 4c933d2..fb01ab3 100644 --- a/action.yml +++ b/action.yml @@ -19,3 +19,9 @@ inputs: description: 'Access Alias Name' required: true default: 'default' + +runs: + using: "composite" + steps: + - 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/script.sh b/script.sh new file mode 100755 index 0000000..349c5c7 --- /dev/null +++ b/script.sh @@ -0,0 +1,28 @@ +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 # 本地版本小于要求版本 + 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 "Serverless-dev requires nodejs >= 14.14.0, please update your local nodejs's version." +fi \ No newline at end of file