Skip to content

Commit

Permalink
feat: alias
Browse files Browse the repository at this point in the history
* add alias parameter

* add alias to netlify command

* docs: mention new arg in readme

* Update README.md

* Update README.md
  • Loading branch information
tpluscode authored and jsmrcaga committed Jan 28, 2021
1 parent e654201 commit 87af643
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The inputs this action uses are:
| `functions_directory` | `false` | N/A | The (optional) directory where your Netlify functions are stored |
| `install_command` | `false` | `npm i` | The (optional) command to install dependencies |
| `build_command` | `false` | `npm run build` | The (optional) command to build static website |
| `deploy_alias` | `false` | '' | (Optional) [Deployed site alias](https://cli.netlify.com/commands/deploy) |

## Example

Expand Down Expand Up @@ -91,3 +92,29 @@ jobs:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}

```

### Use branch name to deploy

Will deploy under `https://${branchName}.${siteName}.netlify.app`

```yml
name: 'Netlify Deploy'

on:
push:
branches:
- '*'

jobs:
deploy:
name: 'Deploy'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: jsmrcaga/action-netlify-deploy@master
with:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
deploy_alias: ${{ GITHUB_REF##*/ }}
```
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ inputs:
description: 'Command to build static website'
required: false
default: 'npm run build'

deploy_alias:
description: 'Deployment Subdomain name'
required: false
default: ''

runs:
using: 'docker'
Expand All @@ -54,6 +59,7 @@ runs:
- ${{ inputs.functions_directory }}
- ${{ inputs.install_command }}
- ${{ inputs.build_command }}
- ${{ inputs.deploy_alias }}

branding:
icon: activity
Expand Down
16 changes: 12 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BUILD_DIRECTORY=$4
FUNCTIONS_DIRECTORY=$5
INSTALL_COMMAND=$6
BUILD_COMMAND=$7
DEPLOY_ALIAS=$8

# Install dependencies
eval ${INSTALL_COMMAND:-"npm i"}
Expand All @@ -20,10 +21,17 @@ eval ${BUILD_COMMAND:-"npm run build"}
export NETLIFY_SITE_ID=$NETLIFY_SITE_ID
export NETLIFY_AUTH_TOKEN=$NETLIFY_AUTH_TOKEN

# Deploy with netlify
COMMAND="netlify deploy --dir=$BUILD_DIRECTORY --functions=$FUNCTIONS_DIRECTORY --message=\"$INPUT_NETLIFY_DEPLOY_MESSAGE\""

if [[ $NETLIFY_DEPLOY_TO_PROD == "true" ]]
then
netlify deploy --dir=$BUILD_DIRECTORY --functions=$FUNCTIONS_DIRECTORY --prod --message="$INPUT_NETLIFY_DEPLOY_MESSAGE"
else
netlify deploy --dir=$BUILD_DIRECTORY --functions=$FUNCTIONS_DIRECTORY --message="$INPUT_NETLIFY_DEPLOY_MESSAGE"
COMMAND+=" --prod"
fi

if [[ -n $DEPLOY_ALIAS ]]
then
COMMAND+=" --alias $COMMAND"
fi

# Deploy with netlify
eval $COMMAND

0 comments on commit 87af643

Please sign in to comment.