Skip to content

Commit 2339912

Browse files
cristopher-ozonejsmrcaga
authored andcommitted
feat: Switching the action from docker into composite
1 parent 4fcfeb8 commit 2339912

File tree

4 files changed

+124
-148
lines changed

4 files changed

+124
-148
lines changed

Dockerfile

Lines changed: 0 additions & 6 deletions
This file was deleted.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The inputs this action uses are:
4242
| `build_command` | `false` | `npm run build` | The (optional) command to build static website |
4343
| `deploy_alias` | `false` | '' | (Optional) [Deployed site alias](https://cli.netlify.com/commands/deploy) |
4444
| `node_version` | `false` | '' | (Optional) Node version or other arguments passed to [nvm install](https://github.com/nvm-sh/nvm#usage) |
45+
| `use_nvm` | `false` | 'true' | (Optional) Enables you to disable nvm altogether |
4546

4647

4748
### Outputs
@@ -166,7 +167,25 @@ Use the `node_version` input to change the desired version. It will be passed to
166167

167168
Alternatively, create an `.nvmrc` file with the desired version range in your repository.
168169

170+
### Deploy to Netlify only
171+
172+
In case of already having the deployment ready data - we can easily skip the nvm, install and build part via passing:
173+
174+
```
175+
- name: Deploy to Netlify
176+
uses: jsmrcaga/action-netlify-deploy@master
177+
with:
178+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
179+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
180+
NETLIFY_DEPLOY_MESSAGE: "Deployed from GitHub action"
181+
NETLIFY_DEPLOY_TO_PROD: true
182+
use_nvm: false
183+
install_command: "echo Skipping installing the dependencies"
184+
build_command: "echo Skipping building the web files"
185+
```
186+
169187
## Contributors
170188

171189
- [tpluscode](https://github.com/tpluscode)
172190
- [wallies](https://github.com/wallies)
191+
- [crisperit](https://github.com/crisperit)

action.yml

Lines changed: 105 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,140 @@
1-
name: 'Netlify Deploy'
2-
author: 'Jo Colina'
3-
description: 'Netlify Deploy'
4-
1+
---
2+
name: Netlify Deploy
3+
author: Jo Colina
4+
description: Netlify Deploy
55
inputs:
66
NETLIFY_AUTH_TOKEN:
7-
description: 'Auth token to use with netlify'
7+
description: Auth token to use with netlify
88
required: true
9-
default: ''
10-
9+
default: ""
1110
NETLIFY_SITE_ID:
12-
description: 'Your Netlify site id'
11+
description: Your Netlify site id
1312
required: true
14-
default: ''
15-
13+
default: ""
1614
NETLIFY_DEPLOY_TO_PROD:
17-
description: 'Should the site be deployed to production?'
15+
description: Should the site be deployed to production?
1816
required: false
1917
default: false
20-
2118
NETLIFY_DEPLOY_MESSAGE:
22-
description: 'A deploy message'
19+
description: A deploy message
2320
required: false
24-
default: ''
25-
21+
default: ""
2622
build_directory:
27-
description: 'Directory where built files are stored'
23+
description: Directory where built files are stored
2824
required: true
29-
default: 'build'
30-
25+
default: build
3126
functions_directory:
32-
description: 'Directory where built files are stored'
27+
description: Directory where built files are stored
3328
required: false
34-
default: ''
35-
29+
default: ""
3630
install_command:
37-
description: 'Command to install dependencies'
31+
description: Command to install dependencies
3832
required: false
39-
default: ''
40-
33+
default: ""
4134
build_command:
42-
description: 'Command to build static website'
35+
description: Command to build static website
4336
required: false
44-
default: 'npm run build'
45-
37+
default: npm run build
4638
deploy_alias:
47-
description: 'Deployment Subdomain name'
39+
description: Deployment Subdomain name
4840
required: false
49-
default: ''
50-
41+
default: ""
5142
node_version:
52-
description: 'Node version or arguments compatible with `nvm install`'
43+
description: Node version or arguments compatible with `nvm install`
5344
required: false
54-
default: ''
55-
45+
default: ""
5646
use_nvm:
57-
description: 'Enables you to disable nvm altogether'
47+
description: Enables you to disable nvm altogether
5848
required: false
5949
default: true
60-
6150
outputs:
6251
NETLIFY_OUTPUT:
63-
description: "netlify command output"
52+
description: netlify command output
6453
NETLIFY_PREVIEW_URL:
65-
description: "deployment preview URL"
54+
description: deployment preview URL
6655
NETLIFY_LOGS_URL:
67-
description: "deployment preview logs url"
56+
description: deployment preview logs url
6857
NETLIFY_LIVE_URL:
69-
description: "deployment URL"
70-
58+
description: deployment URL
7159
runs:
72-
using: 'docker'
73-
image: 'Dockerfile'
74-
args:
75-
- ${{ inputs.NETLIFY_AUTH_TOKEN }}
76-
- ${{ inputs.NETLIFY_SITE_ID }}
77-
- ${{ inputs.NETLIFY_DEPLOY_TO_PROD }}
78-
- ${{ inputs.build_directory }}
79-
- ${{ inputs.functions_directory }}
80-
- ${{ inputs.install_command }}
81-
- ${{ inputs.build_command }}
82-
- ${{ inputs.deploy_alias }}
83-
- ${{ inputs.node_version }}
60+
using: composite
61+
steps:
62+
- name: "Install node through NVM if needed"
63+
shell: bash
64+
run: |
65+
if [[ "${{ inputs.use_nvm }}" == "true" ]] && ([[ -n "${{ inputs.node_version }}" ]] || [[ -e ".nvmrc" ]])
66+
then
67+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
68+
[ -s "$HOME/.nvm/nvm.sh" ] && \. "$HOME/.nvm/nvm.sh"
69+
if [[ -n "${{ inputs.node_version }}" ]]
70+
then
71+
nvm install "${{ inputs.node_version }}"
72+
else
73+
nvm install
74+
fi
75+
else
76+
echo "Node installation has been omitted"
77+
fi
78+
- name: "Run install command"
79+
shell: bash
80+
run: |
81+
if [[ -n "${{ inputs.install_command }}" ]]
82+
then
83+
${{ inputs.install_command }}
84+
elif [[ -f yarn.lock ]]
85+
then
86+
yarn
87+
else
88+
npm i
89+
fi
90+
- name: "Run build command"
91+
shell: bash
92+
run: |
93+
if [[ -n "${{ inputs.build_command }}" ]]
94+
then
95+
${{ inputs.build_command }}
96+
else
97+
npm run build
98+
fi
99+
- name: "Deploy to Netlify"
100+
shell: bash
101+
run: |
102+
export NETLIFY_SITE_ID="${{ inputs.NETLIFY_SITE_ID }}"
103+
export NETLIFY_AUTH_TOKEN="${{ inputs.NETLIFY_AUTH_TOKEN }}"
104+
105+
COMMAND="netlify deploy --dir=${{ inputs.build_directory }} --functions=${{ inputs.functions_directory }} --message=\"${{ inputs.NETLIFY_DEPLOY_MESSAGE }}\""
106+
107+
if [[ "${{ inputs.NETLIFY_DEPLOY_TO_PROD }}" == "true" ]]
108+
then
109+
COMMAND+=" --prod"
110+
elif [[ -n "${{ inputs.deploy_alias }}" ]]
111+
then
112+
COMMAND+=" --alias ${{ inputs.deploy_alias }}"
113+
fi
114+
115+
# Deploy with netlify
116+
OUTPUT=$(sh -c "$COMMAND")
117+
118+
NETLIFY_OUTPUT=$(echo "$OUTPUT")
119+
NETLIFY_PREVIEW_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*(--)[a-zA-Z0-9./?=_-]*') #Unique key: --
120+
NETLIFY_LOGS_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://app.netlify.com/[a-zA-Z0-9./?=_-]*') #Unique key: app.netlify.com
121+
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
122+
123+
echo "NETLIFY_OUTPUT<<EOF" >> $GITHUB_ENV
124+
echo "$NETLIFY_OUTPUT" >> $GITHUB_ENV
125+
echo "EOF" >> $GITHUB_ENV
126+
127+
echo "NETLIFY_PREVIEW_URL<<EOF" >> $GITHUB_ENV
128+
echo "$NETLIFY_PREVIEW_URL" >> $GITHUB_ENV
129+
echo "EOF" >> $GITHUB_ENV
130+
131+
echo "NETLIFY_LOGS_URL<<EOF" >> $GITHUB_ENV
132+
echo "$NETLIFY_LOGS_URL" >> $GITHUB_ENV
133+
echo "EOF" >> $GITHUB_ENV
84134
135+
echo "NETLIFY_LIVE_URL<<EOF" >> $GITHUB_ENV
136+
echo "$NETLIFY_LIVE_URL" >> $GITHUB_ENV
137+
echo "EOF" >> $GITHUB_ENV
85138
branding:
86139
icon: activity
87140
color: blue

entrypoint.sh

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)