From 75c00d84fa23f2dfc5eed2d8a7b3f865c94ddbd2 Mon Sep 17 00:00:00 2001 From: "A. Ryan Lawson" Date: Fri, 17 May 2024 19:26:30 -0400 Subject: [PATCH 1/8] Allow a particular Serverless version to be set --- Dockerfile | 5 +++-- README.md | 8 ++++++++ action.yml | 17 +++++++++++++++++ entrypoint.sh | 3 +++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 action.yml create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 2505df4..083c493 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,5 +10,6 @@ LABEL "com.github.actions.description"="Wraps the Serverless Framework to enable LABEL "com.github.actions.icon"="zap" LABEL "com.github.actions.color"="red" -RUN npm i -g serverless@3.x -ENTRYPOINT ["serverless"] +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 37a74fa..033b393 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,14 @@ jobs: # AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} ``` +## Specify a particular version +```yaml + - name: Deploy with a particular version + uses: serverless/github-action@v3.2 + with: + serverless-version: 3 +``` + ## Usage with serverless plugins Change your action in this way, according to [this issue](https://github.com/serverless/github-action/issues/28), thanks to @matthewpoer: ```yaml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..dc03f02 --- /dev/null +++ b/action.yml @@ -0,0 +1,17 @@ +name: 'Serverless Github Action' +description: 'Github Action for the Serverless Framework' +inputs: + args: + description: 'Arguments passed to `serverless`' + required: false + default: help + serverless-version: + description: 'Version of the Serverless Framework to use (default: latest)' + required: false + default: latest +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.serverless-version }} + - ${{ inputs.args }} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..df9b4ac --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh -l +npm i -g serverless@${1/v/} +serverless $2 From f0a5b900407c445fd09a3dfed6dceeae50dc6aa9 Mon Sep 17 00:00:00 2001 From: "A. Ryan Lawson" Date: Fri, 17 May 2024 20:25:34 -0400 Subject: [PATCH 2/8] Allow user to change working directory --- README.md | 10 ++++++++++ action.yml | 5 +++++ entrypoint.sh | 5 +++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 033b393..57f80ab 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,16 @@ jobs: uses: serverless/github-action@v3.2 with: serverless-version: 3 + args: deploy +``` + +## Change your working directory +```yaml + - name: Deploy from a particular working directory + uses: serverless/github-action@v3.2 + with: + working-directory: ./foo + args: deploy ``` ## Usage with serverless plugins diff --git a/action.yml b/action.yml index dc03f02..7c76ec3 100644 --- a/action.yml +++ b/action.yml @@ -9,9 +9,14 @@ inputs: description: 'Version of the Serverless Framework to use (default: latest)' required: false default: latest + working-directory: + description: 'Folder where your configuration is located' + required: false + default: . runs: using: 'docker' image: 'Dockerfile' args: + - ${{ inputs.working-directory }} - ${{ inputs.serverless-version }} - ${{ inputs.args }} diff --git a/entrypoint.sh b/entrypoint.sh index df9b4ac..1fd2b18 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,3 +1,4 @@ #!/bin/sh -l -npm i -g serverless@${1/v/} -serverless $2 +cd $1 +npm i -g serverless@${2/v/} +serverless $3 From 033f5243bc13ebb95049cf8c16585f4692455f19 Mon Sep 17 00:00:00 2001 From: "A. Ryan Lawson" Date: Sat, 18 May 2024 01:10:15 -0400 Subject: [PATCH 3/8] Add versioning and local credentials --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++---- action.yml | 13 ++++++++---- entrypoint.sh | 15 +++++++++++-- 3 files changed, 77 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 57f80ab..5395464 100644 --- a/README.md +++ b/README.md @@ -46,16 +46,67 @@ jobs: # AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} ``` -## Specify a particular version +## Configuration + +| `with:` | Description | Required | Default | +| --- | --- | --- | --- | +| `args` | Arguments passed to `serverless` | `true` | +| `aws-credentials` | Whether to use credentials stored in the local environment (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`) | `false` | | +| `entrypoint` | Serverless entrypoint. For example: `/bin/sh` | `false` | `/entrypoint.sh` | +| `install-packages` | Comma-separated list of packages to install prior to running `serverless {args}` | `false` | | +| `serverless-version` | Version of the Serverless Framework to use | `false` | `latest` | +| `working-directory` | Folder where your configuration is located | `false` | `.` | + +## Examples + +### Minimal example +```yaml + - name: Deploy + uses: serverless/github-action@v3.2 + with: + args: deploy +``` + +### Use local credentials +```yaml + - name: Deploy with local credentials + uses: serverless/github-action@v3.2 + with: + aws-credentials: true # or yes + args: deploy + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +``` + +### Use a different entrypoint +```yaml + - name: Deploy with a different entrypoint + uses: serverless/github-action@v3.2 + with: + entrypoint: /bin/sh + args: -c "serverless deploy" +``` + +### Install packages and deploy +```yaml + - name: Install packages and deploy + uses: serverless/github-action@v3.2 + with: + install-packages: serverless-offline,serverless-prune-plugin + args: deploy +``` + +### Use a particular Serverless Framework CLI version ```yaml - - name: Deploy with a particular version + - name: Deploy using a particular version of serverless uses: serverless/github-action@v3.2 with: - serverless-version: 3 + serverless-version: 2 args: deploy ``` -## Change your working directory +### Change your working directory ```yaml - name: Deploy from a particular working directory uses: serverless/github-action@v3.2 diff --git a/action.yml b/action.yml index a7aef13..dcb38ff 100644 --- a/action.yml +++ b/action.yml @@ -7,11 +7,15 @@ branding: inputs: args: description: 'Arguments passed to `serverless`' + required: true + aws-credentials: + description: 'Whether to use credentials stored in the local environment (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)' required: false - default: help - entrypoint: - description: 'Serverless entrypoint. For example: `/bin/sh`' + default: 'false' + install-packages: + description: 'Comma-separated list of packages to install prior to running `serverless {args}`' required: false + default: none serverless-version: description: 'Version of the Serverless Framework to use (default: latest)' required: false @@ -26,8 +30,9 @@ runs: args: - ${{ inputs.working-directory }} - ${{ inputs.serverless-version }} + - ${{ inputs.install-packages }} + - ${{ inputs.aws-credentials }} - ${{ inputs.args }} - entrypoint: ${{ inputs.entrypoint }} outputs: version: diff --git a/entrypoint.sh b/entrypoint.sh index 1fd2b18..e4eafd8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,15 @@ #!/bin/sh -l cd $1 -npm i -g serverless@${2/v/} -serverless $3 +npm i -g serverless@$2 + +PACKAGES_TO_INSTALL=$3 +if [ $3 != "none" ]; then + npm i -g ${PACKAGES_TO_INSTALL//,/\ } +fi + +WITH_LOCAL_CREDENTIALS="" +if [ $4 = "true" ] || [ $4 = "yes" ]; then + WITH_LOCAL_CREDENTIALS="--use-local-credentials" +fi + +serverless $5 $WITH_LOCAL_CREDENTIALS From 7d4c51ed966226df117782e11d7f1e83ecd388ff Mon Sep 17 00:00:00 2001 From: "A. Ryan Lawson" Date: Sat, 18 May 2024 03:02:16 -0400 Subject: [PATCH 4/8] Install package/plugin functionality --- README.md | 55 ++++++++++----------------------------------------- action.yml | 5 +++-- entrypoint.sh | 13 ++++++++---- 3 files changed, 22 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 5395464..b84330c 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,7 @@ jobs: | --- | --- | --- | --- | | `args` | Arguments passed to `serverless` | `true` | | `aws-credentials` | Whether to use credentials stored in the local environment (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`) | `false` | | -| `entrypoint` | Serverless entrypoint. For example: `/bin/sh` | `false` | `/entrypoint.sh` | -| `install-packages` | Comma-separated list of packages to install prior to running `serverless {args}` | `false` | | +| `install-packages` | Space-separated list of packages to install prior to running `serverless {args}` | `false` | | | `serverless-version` | Version of the Serverless Framework to use | `false` | `latest` | | `working-directory` | Folder where your configuration is located | `false` | `.` | @@ -62,7 +61,7 @@ jobs: ### Minimal example ```yaml - name: Deploy - uses: serverless/github-action@v3.2 + uses: serverless/github-action@v4.0 with: args: deploy ``` @@ -70,7 +69,7 @@ jobs: ### Use local credentials ```yaml - name: Deploy with local credentials - uses: serverless/github-action@v3.2 + uses: serverless/github-action@v4.0 with: aws-credentials: true # or yes args: deploy @@ -79,28 +78,19 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} ``` -### Use a different entrypoint -```yaml - - name: Deploy with a different entrypoint - uses: serverless/github-action@v3.2 - with: - entrypoint: /bin/sh - args: -c "serverless deploy" -``` - ### Install packages and deploy ```yaml - name: Install packages and deploy - uses: serverless/github-action@v3.2 + uses: serverless/github-action@v4.0 with: - install-packages: serverless-offline,serverless-prune-plugin + install-packages: serverless-offline serverless-prune-plugin args: deploy ``` ### Use a particular Serverless Framework CLI version ```yaml - name: Deploy using a particular version of serverless - uses: serverless/github-action@v3.2 + uses: serverless/github-action@v4.0 with: serverless-version: 2 args: deploy @@ -109,42 +99,17 @@ jobs: ### Change your working directory ```yaml - name: Deploy from a particular working directory - uses: serverless/github-action@v3.2 + uses: serverless/github-action@v4.0 with: working-directory: ./foo args: deploy ``` -## Usage with serverless plugins -Change your action in this way, according to [this issue](https://github.com/serverless/github-action/issues/28), thanks to @matthewpoer: -```yaml - - name: Install Plugin and Deploy - uses: serverless/github-action@v3.2 - with: - args: -c "serverless plugin install --name && serverless deploy" - entrypoint: /bin/sh -``` - -## Fix "This command can only be run in a Serverless service directory" error -Change your action in this way, according to [this issue](https://github.com/serverless/github-action/issues/53#issuecomment-1059839383), thanks to @nikhuber: -```yaml - - name: Enter dir and deploy - uses: serverless/github-action@v3.2 - with: - args: -c "cd ./ && serverless deploy" - entrypoint: /bin/sh -``` - - -## Use serverless v1 or v2 -Change the action with one of the following: +## Use a previous version +Change the action with `@{version}`, for example: ```yaml -uses: serverless/github-action@v1 +uses: serverless/github-action@v3.2 ``` -```yaml -uses: serverless/github-action@v2 -``` - ## License diff --git a/action.yml b/action.yml index dcb38ff..c166ecc 100644 --- a/action.yml +++ b/action.yml @@ -7,13 +7,14 @@ branding: inputs: args: description: 'Arguments passed to `serverless`' - required: true + required: false + default: none aws-credentials: description: 'Whether to use credentials stored in the local environment (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)' required: false default: 'false' install-packages: - description: 'Comma-separated list of packages to install prior to running `serverless {args}`' + description: 'Space-separated list of packages to install prior to running `serverless {args}`' required: false default: none serverless-version: diff --git a/entrypoint.sh b/entrypoint.sh index e4eafd8..ce29910 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,14 +1,19 @@ #!/bin/sh -l +if [ "$5" = "none" ]; then + echo "You need to specify at least one argument, like deploy" + exit 1 +fi + cd $1 + npm i -g serverless@$2 -PACKAGES_TO_INSTALL=$3 -if [ $3 != "none" ]; then - npm i -g ${PACKAGES_TO_INSTALL//,/\ } +if [ "$3" != "none" ]; then + npm i -g $3 fi WITH_LOCAL_CREDENTIALS="" -if [ $4 = "true" ] || [ $4 = "yes" ]; then +if [ "$4" = "true" ] || [ "$4" = "yes" ]; then WITH_LOCAL_CREDENTIALS="--use-local-credentials" fi From e2bf220b34ec9aac5d069aa7b46d5dc646bff36a Mon Sep 17 00:00:00 2001 From: "A. Ryan Lawson" Date: Sat, 18 May 2024 17:07:56 -0400 Subject: [PATCH 5/8] Add error checks --- action.yml | 2 +- entrypoint.sh | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index c166ecc..249ce3e 100644 --- a/action.yml +++ b/action.yml @@ -29,10 +29,10 @@ runs: using: 'docker' image: 'Dockerfile' args: + - ${{ inputs.aws-credentials }} - ${{ inputs.working-directory }} - ${{ inputs.serverless-version }} - ${{ inputs.install-packages }} - - ${{ inputs.aws-credentials }} - ${{ inputs.args }} outputs: diff --git a/entrypoint.sh b/entrypoint.sh index ce29910..f87fca8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,20 +1,36 @@ #!/bin/sh -l if [ "$5" = "none" ]; then echo "You need to specify at least one argument, like deploy" - exit 1 + exit 5 fi -cd $1 +WITH_LOCAL_CREDENTIALS="" +if [ "$1" = "true" ] || [ "$1" = "yes" ]; then + if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY"]; then + echo "You have aws-credentials set without AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY" + exit 1 + fi + WITH_LOCAL_CREDENTIALS="--use-local-credentials" +fi -npm i -g serverless@$2 +cd $2 +if [ "$?" != 0 ]; then + echo "Unable to cd into $2" + exit 2 +fi -if [ "$3" != "none" ]; then - npm i -g $3 +npm i -g serverless@$3 +if [ "$?" != 0 ]; then + echo "Unable to install serverless@$3" + exit 3 fi -WITH_LOCAL_CREDENTIALS="" -if [ "$4" = "true" ] || [ "$4" = "yes" ]; then - WITH_LOCAL_CREDENTIALS="--use-local-credentials" +if [ "$4" != "none" ]; then + npm i -g $4 + if [ "$?" != 0 ]; then + echo "Unable to install packages: $4" + exit 4 + fi fi serverless $5 $WITH_LOCAL_CREDENTIALS From 15b5dadddfdb0b931a53cc1c1c6898e43e9e40a5 Mon Sep 17 00:00:00 2001 From: "A. Ryan Lawson" Date: Sat, 18 May 2024 17:42:37 -0400 Subject: [PATCH 6/8] Add log for serverless command --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index f87fca8..729bd1d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,7 +6,7 @@ fi WITH_LOCAL_CREDENTIALS="" if [ "$1" = "true" ] || [ "$1" = "yes" ]; then - if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY"]; then + if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then echo "You have aws-credentials set without AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY" exit 1 fi @@ -33,4 +33,5 @@ if [ "$4" != "none" ]; then fi fi +echo serverless $5 $WITH_LOCAL_CREDENTIALS serverless $5 $WITH_LOCAL_CREDENTIALS From f3ac03f6a141e025f59136616e4777ef80df60a4 Mon Sep 17 00:00:00 2001 From: Austin Ryan Lawson Date: Thu, 23 May 2024 00:42:50 -0400 Subject: [PATCH 7/8] Update README.md --- README.md | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b84330c..1ebf06c 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,9 @@ This Action wraps the [Serverless Framework](https://serverless.com) to enable common Serverless commands. -## This project is looking for maintainers! - -If you would like to be a maintainer of this project, please reach out to one of the active [Serverless organization](https://github.com/serverless) members to express your interest. - -Welcome, and thanks in advance for your help! - ## Usage -An example workflow to deploy a project with serverless v3: +An example workflow to deploy a project with the Serverless Framework: ```yaml @@ -61,7 +55,7 @@ jobs: ### Minimal example ```yaml - name: Deploy - uses: serverless/github-action@v4.0 + uses: ryanlawson/serverless-github-action@v1.0 with: args: deploy ``` @@ -69,7 +63,7 @@ jobs: ### Use local credentials ```yaml - name: Deploy with local credentials - uses: serverless/github-action@v4.0 + uses: ryanlawson/serverless-github-action@v1.0 with: aws-credentials: true # or yes args: deploy @@ -81,7 +75,7 @@ jobs: ### Install packages and deploy ```yaml - name: Install packages and deploy - uses: serverless/github-action@v4.0 + uses: ryanlawson/serverless-github-action@v1.0 with: install-packages: serverless-offline serverless-prune-plugin args: deploy @@ -90,7 +84,7 @@ jobs: ### Use a particular Serverless Framework CLI version ```yaml - name: Deploy using a particular version of serverless - uses: serverless/github-action@v4.0 + uses: ryanlawson/serverless-github-action@v1.0 with: serverless-version: 2 args: deploy @@ -99,18 +93,12 @@ jobs: ### Change your working directory ```yaml - name: Deploy from a particular working directory - uses: serverless/github-action@v4.0 + uses: ryanlawson/serverless-github-action@v1.0 with: working-directory: ./foo args: deploy ``` -## Use a previous version -Change the action with `@{version}`, for example: -```yaml -uses: serverless/github-action@v3.2 -``` - ## License The Dockerfile and associated scripts and documentation in this project are released under the Apache-2 license. From 393abd5b0b529d55aa8a7000b7272440dcdbda34 Mon Sep 17 00:00:00 2001 From: "A. Ryan Lawson" Date: Tue, 28 May 2024 09:23:55 -0400 Subject: [PATCH 8/8] Update README --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1ebf06c..fd46e62 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ This Action wraps the [Serverless Framework](https://serverless.com) to enable c An example workflow to deploy a project with the Serverless Framework: - ```yaml name: Deploy master branch @@ -30,7 +29,7 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm ci - name: serverless deploy - uses: serverless/github-action@v3.2 + uses: ryanlawson/serverless-github-action@v1.0 with: args: deploy env: @@ -53,6 +52,7 @@ jobs: ## Examples ### Minimal example +Basic deployment with no customization ```yaml - name: Deploy uses: ryanlawson/serverless-github-action@v1.0 @@ -61,6 +61,7 @@ jobs: ``` ### Use local credentials +Ensures `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are present and uses them to authenticate ```yaml - name: Deploy with local credentials uses: ryanlawson/serverless-github-action@v1.0 @@ -73,6 +74,7 @@ jobs: ``` ### Install packages and deploy +Installs any additional packages (usually [Serverless plugins](https://www.serverless.com/plugins)) prior to deploying ```yaml - name: Install packages and deploy uses: ryanlawson/serverless-github-action@v1.0 @@ -82,6 +84,7 @@ jobs: ``` ### Use a particular Serverless Framework CLI version +Installs a specific version of the Serverless Framework ```yaml - name: Deploy using a particular version of serverless uses: ryanlawson/serverless-github-action@v1.0 @@ -91,6 +94,7 @@ jobs: ``` ### Change your working directory +Sets a specific working directory (usually the root of the repository) for your Serverless configuration ```yaml - name: Deploy from a particular working directory uses: ryanlawson/serverless-github-action@v1.0