Skip to content

Commit

Permalink
feat: Add Netlify output as action outputs
Browse files Browse the repository at this point in the history
* Add command output

* add to contrib and readme

* fix name in action
  • Loading branch information
wallies committed Nov 14, 2021
1 parent 20cf18b commit 9cc40dc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
23 changes: 23 additions & 0 deletions README.md
Expand Up @@ -43,6 +43,28 @@ The inputs this action uses are:
| `deploy_alias` | `false` | '' | (Optional) [Deployed site alias](https://cli.netlify.com/commands/deploy) |
| `node_version` | `false` | '' | (Optional) Node version or other arguments passed to [nvm install](https://github.com/nvm-sh/nvm#usage) |


### Outputs

The outputs for this action are:

`NETLIFY_OUTPUT`

Full output of the action

`NETLIFY_PREVIEW_URL`

The url of deployment preview.

`NETLIFY_LOGS_URL`

The url of the logs.

`NETLIFY_LIVE_URL`

The url of the live deployed site.


## Example

### Deploy to production on release
Expand Down Expand Up @@ -147,3 +169,4 @@ Alternatively, create an `.nvmrc` file with the desired version range in your re
## Contributors

- [tpluscode](https://github.com/tpluscode)
- [wallies](https://github.com/wallies)
10 changes: 10 additions & 0 deletions action.yml
Expand Up @@ -53,6 +53,16 @@ inputs:
required: false
default: ''

outputs:
NETLIFY_OUTPUT:
description: "netlify command output"
NETLIFY_PREVIEW_URL:
description: "deployment preview URL"
NETLIFY_LOGS_URL:
description: "deployment preview logs url"
NETLIFY_LIVE_URL:
description: "deployment URL"

runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
16 changes: 13 additions & 3 deletions entrypoint.sh
Expand Up @@ -36,8 +36,8 @@ fi
eval ${BUILD_COMMAND:-"npm run build"}

# Export token to use with netlify's cli
export NETLIFY_SITE_ID=$NETLIFY_SITE_ID
export NETLIFY_AUTH_TOKEN=$NETLIFY_AUTH_TOKEN
export NETLIFY_SITE_ID="$NETLIFY_SITE_ID"
export NETLIFY_AUTH_TOKEN="$NETLIFY_AUTH_TOKEN"

COMMAND="$NETLIFY_CLI deploy --dir=$BUILD_DIRECTORY --functions=$FUNCTIONS_DIRECTORY --message=\"$INPUT_NETLIFY_DEPLOY_MESSAGE\""

Expand All @@ -50,4 +50,14 @@ then
fi

# Deploy with netlify
eval $COMMAND
OUTPUT=$(sh -c "$COMMAND")

NETLIFY_OUTPUT=$(echo "$OUTPUT")
NETLIFY_PREVIEW_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*(--)[a-zA-Z0-9./?=_-]*') #Unique key: --
NETLIFY_LOGS_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://app.netlify.com/[a-zA-Z0-9./?=_-]*') #Unique key: app.netlify.com
NETLIFY_LIVE_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*' | grep -Eov "netlify.com") #Unique key: don't containr -- and app.netlify.com

echo "::set-output name=NETLIFY_OUTPUT::$NETLIFY_OUTPUT"
echo "::set-output name=NETLIFY_PREVIEW_URL::$NETLIFY_PREVIEW_URL"
echo "::set-output name=NETLIFY_LOGS_URL::$NETLIFY_LOGS_URL"
echo "::set-output name=NETLIFY_LIVE_URL::$NETLIFY_LIVE_URL"

0 comments on commit 9cc40dc

Please sign in to comment.