Skip to content

Commit

Permalink
fix: PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cristopher-ozone authored and jsmrcaga committed Jan 17, 2023
1 parent 2339912 commit 10294b8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 86 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ The inputs this action uses are:
| `install_command` | `false` | Auto-detected | The (optional) command to install dependencies. Runs `yarn` when `yarn.lock` is found; `npm i` otherwise |
| `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) |
| `node_version` | `false` | '' | (Optional) Node version or other arguments passed to [nvm install](https://github.com/nvm-sh/nvm#usage) |
| `use_nvm` | `false` | 'true' | (Optional) Enables you to disable nvm altogether |


### Outputs
Expand Down Expand Up @@ -179,7 +177,6 @@ In case of already having the deployment ready data - we can easily skip the nvm
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_DEPLOY_MESSAGE: "Deployed from GitHub action"
NETLIFY_DEPLOY_TO_PROD: true
use_nvm: false
install_command: "echo Skipping installing the dependencies"
build_command: "echo Skipping building the web files"
```
Expand Down
96 changes: 13 additions & 83 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ inputs:
description: Deployment Subdomain name
required: false
default: ""
node_version:
description: Node version or arguments compatible with `nvm install`
required: false
default: ""
use_nvm:
description: Enables you to disable nvm altogether
required: false
default: true
outputs:
NETLIFY_OUTPUT:
description: netlify command output
Expand All @@ -59,82 +51,20 @@ outputs:
runs:
using: composite
steps:
- name: "Install node through NVM if needed"
shell: bash
run: |
if [[ "${{ inputs.use_nvm }}" == "true" ]] && ([[ -n "${{ inputs.node_version }}" ]] || [[ -e ".nvmrc" ]])
then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
[ -s "$HOME/.nvm/nvm.sh" ] && \. "$HOME/.nvm/nvm.sh"
if [[ -n "${{ inputs.node_version }}" ]]
then
nvm install "${{ inputs.node_version }}"
else
nvm install
fi
else
echo "Node installation has been omitted"
fi
- name: "Run install command"
shell: bash
run: |
if [[ -n "${{ inputs.install_command }}" ]]
then
${{ inputs.install_command }}
elif [[ -f yarn.lock ]]
then
yarn
else
npm i
fi
- name: "Run build command"
shell: bash
run: |
if [[ -n "${{ inputs.build_command }}" ]]
then
${{ inputs.build_command }}
else
npm run build
fi
- name: "Deploy to Netlify"
shell: bash
run: |
export NETLIFY_SITE_ID="${{ inputs.NETLIFY_SITE_ID }}"
export NETLIFY_AUTH_TOKEN="${{ inputs.NETLIFY_AUTH_TOKEN }}"
COMMAND="netlify deploy --dir=${{ inputs.build_directory }} --functions=${{ inputs.functions_directory }} --message=\"${{ inputs.NETLIFY_DEPLOY_MESSAGE }}\""
if [[ "${{ inputs.NETLIFY_DEPLOY_TO_PROD }}" == "true" ]]
then
COMMAND+=" --prod"
elif [[ -n "${{ inputs.deploy_alias }}" ]]
then
COMMAND+=" --alias ${{ inputs.deploy_alias }}"
fi
# Deploy with netlify
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 "NETLIFY_OUTPUT<<EOF" >> $GITHUB_ENV
echo "$NETLIFY_OUTPUT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "NETLIFY_PREVIEW_URL<<EOF" >> $GITHUB_ENV
echo "$NETLIFY_PREVIEW_URL" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "NETLIFY_LOGS_URL<<EOF" >> $GITHUB_ENV
echo "$NETLIFY_LOGS_URL" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: ${{ github.action_path }}/entrypoint.sh
shell: bash
env:
NETLIFY_AUTH_TOKEN: ${{ inputs.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ inputs.NETLIFY_SITE_ID }}
NETLIFY_DEPLOY_TO_PROD: ${{ inputs.NETLIFY_DEPLOY_TO_PROD }}
NETLIFY_DEPLOY_MESSAGE: ${{ inputs.NETLIFY_DEPLOY_MESSAGE }}
BUILD_DIRECTORY: ${{ inputs.build_directory }}
FUNCTIONS_DIRECTORY: ${{ inputs.functions_directory }}
INSTALL_COMMAND: ${{ inputs.install_command }}
BUILD_COMMAND: ${{ inputs.build_command }}
DEPLOY_ALIAS: ${{ inputs.deploy_alias }}

echo "NETLIFY_LIVE_URL<<EOF" >> $GITHUB_ENV
echo "$NETLIFY_LIVE_URL" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

branding:
icon: activity
color: blue
60 changes: 60 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -e

# Run install command
if [[ -n "${INSTALL_COMMAND}" ]]
then
${INSTALL_COMMAND}
elif [[ -f yarn.lock ]]
then
yarn
else
npm i
fi

# Run build command
if [[ -n "${BUILD_COMMAND}" ]]
then
${BUILD_COMMAND}
else
npm run build
fi

# Deploy to Netlify
export NETLIFY_SITE_ID="${NETLIFY_SITE_ID}"
export NETLIFY_AUTH_TOKEN="${NETLIFY_AUTH_TOKEN}"

COMMAND="netlify deploy --dir=${BUILD_DIRECTORY} --functions=${FUNCTIONS_DIRECTORY} --message=\"${NETLIFY_DEPLOY_MESSAGE}\""

if [[ "${NETLIFY_DEPLOY_TO_PROD}" == "true" ]]
then
COMMAND+=" --prod"
elif [[ -n "${DEPLOY_ALIAS}" ]]
then
COMMAND+=" --alias ${DEPLOY_ALIAS}"
fi

OUTPUT=$(sh -c "$COMMAND")

# Set outputs
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 "NETLIFY_OUTPUT<<EOF" >> $GITHUB_ENV
echo "$NETLIFY_OUTPUT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

echo "NETLIFY_PREVIEW_URL<<EOF" >> $GITHUB_ENV
echo "$NETLIFY_PREVIEW_URL" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

echo "NETLIFY_LOGS_URL<<EOF" >> $GITHUB_ENV
echo "$NETLIFY_LOGS_URL" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

echo "NETLIFY_LIVE_URL<<EOF" >> $GITHUB_ENV
echo "$NETLIFY_LIVE_URL" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

0 comments on commit 10294b8

Please sign in to comment.