Skip to content

Commit

Permalink
Merge pull request #1 from Serverless-Devs/v0.0.1
Browse files Browse the repository at this point in the history
feat: V0.0.1
  • Loading branch information
huyikun authored Jan 16, 2024
2 parents 989c271 + cabadd6 commit d5edb34
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
29 changes: 18 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions script.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d5edb34

Please sign in to comment.