Skip to content

Commit

Permalink
Install package/plugin functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlawson committed May 18, 2024
1 parent 033f524 commit 38d0cf3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 51 deletions.
55 changes: 10 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | `.` |

Expand All @@ -62,15 +61,15 @@ jobs:
### Minimal example
```yaml
- name: Deploy
uses: serverless/github-action@v3.2
uses: serverless/github-action@v4.0
with:
args: deploy
```
### 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
Expand All @@ -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/[email protected]
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
Expand All @@ -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/[email protected]
with:
args: -c "serverless plugin install --name <plugin-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/[email protected]
with:
args: -c "cd ./<your-dir> && 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

Expand Down
5 changes: 3 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 38d0cf3

Please sign in to comment.