Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ LABEL "com.github.actions.color"="blue"
RUN npm install -g netlify-cli

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["sh", "/entrypoint.sh"]
6 changes: 4 additions & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ This Action enables arbitrary actions with the [Netlify CLI](https://github.com/
## Outputs

The following outputs will be available from a step that uses this action:
- `NETLIFY_OUTPUT`, the full stdout from the run of the `netlify` command
- `NETLIFY_URL`, the URL of the draft site that Netlify provides
- `NETLIFY_LOGS_URL`, the URL where the logs from the deploy can be found
- `NETLIFY_LIVE_URL`, the URL of the "real" site, set only if `--prod` was passed

> The full stdout from the run of the `netlify` command is printed in the GitHub Actions workflow logs.


See [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions) for info and examples of how to use outputs in later steps and jobs.

## Example
Expand All @@ -33,7 +35,7 @@ jobs:
- name: Publish
uses: netlify/actions/cli@master
with:
args: deploy --dir=site --functions=functions
args: deploy --prod --dir=./build --message="Deploy from Github Action"
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
Expand Down
20 changes: 11 additions & 9 deletions cli/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ read -d '' COMMAND <<- EOF
if [ -f "$HOME/ignore" ] && grep "^ignore:$BUILD_DIR" "$HOME/ignore"; then
echo "$BUILD_DIR didn't change"
else
${BUILD_COMMAND:-echo} && netlify $*
${BUILD_COMMAND:-echo} && netlify $@
fi
EOF

echo "running ${COMMAND}"
OUTPUT=$(sh -c "$COMMAND")
echo "$OUTPUT"

NETLIFY_OUTPUT=$(echo "$OUTPUT")
NETLIFY_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
NETLIFY_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*(--)[a-zA-Z0-9./?=_-]*' | head -n 1)
NETLIFY_LOGS_URL=$(echo "$OUTPUT" | grep "Build logs:" | grep -Eo '(http|https)://app.netlify.com/[a-zA-Z0-9./?=_-]*' | head -n 1)
NETLIFY_LIVE_URL=$(echo "$OUTPUT" | grep -i "production URL:" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*' | head -n 1)

echo "::set-output name=NETLIFY_OUTPUT::$NETLIFY_OUTPUT"
echo "::set-output name=NETLIFY_URL::$NETLIFY_URL"
echo "::set-output name=NETLIFY_LOGS_URL::$NETLIFY_LOGS_URL"
echo "::set-output name=NETLIFY_LIVE_URL::$NETLIFY_LIVE_URL"
{
echo "NETLIFY_URL=$NETLIFY_URL"
echo "NETLIFY_LOGS_URL=$NETLIFY_LOGS_URL"
echo "NETLIFY_LIVE_URL=$NETLIFY_LIVE_URL"
} >> "$GITHUB_OUTPUT"