From 36f0d790bd45b2cd33a50e8ef189fe18067d1ebb Mon Sep 17 00:00:00 2001 From: "A. Ryan Lawson" Date: Sat, 18 May 2024 01:10:15 -0400 Subject: [PATCH] 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..d8bbf1e 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