Skip to content

Commit d9a54ca

Browse files
committed
First Commit
0 parents  commit d9a54ca

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:current-stretch-slim
2+
3+
ADD entrypoint.sh /entrypoint.sh
4+
ADD action.yml /action.yml
5+
6+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Netlify Deploy
2+
3+
This is a simple GitHub Action to deploy a static website to Netlify.
4+
5+
## Usage
6+
To use a GitHub action you can just reference it on your Workflow file
7+
(for more info check [this article by Github](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow))
8+
9+
> Important: this action will execute `npm i` and `npm run build`. Please open an issue if another command is needed
10+
11+
```yml
12+
name: 'My Workflow'
13+
14+
on:
15+
release:
16+
types: [published]
17+
18+
jobs:
19+
deploy:
20+
name: 'Deploy to Netlify'
21+
steps:
22+
- uses: jsmrcaga/action-netlify-deploy@v1
23+
with:
24+
NETLIFY_AUTH_TOKEN: ${{ secrets.MY_TOKEN_SECRET }}
25+
NETLIFY_DEPLOY_TO_PROD: true
26+
```
27+
28+
### Inputs
29+
30+
As most GitHub actions, this action requires and uses some inputs, that you define in
31+
your workflow file.
32+
33+
The inputs this action uses are:
34+
35+
| Name | Required | Default | Description |
36+
|:----:|:--------:|:-------:|:-----------:|
37+
| `NETLIFY_AUTH_TOKEN` | `true` | N/A | The token needed to deploy your site ([generate here](https://app.netlify.com/user/applications#personal-access-tokens))|
38+
| `NETLIFY_SITE_ID` | `true` | N/A | The site to where deploy your site (get it from the API ID on your Site Settings) |
39+
| `NETLIFY_DEPLOY_MESSAGE` | `false` | '' | An optional deploy message |
40+
| `build_directory` | `false` | `'build'` | The directory where your files are built |
41+
| `functions_directory` | `false` | N/A | The (optional) directory where your Netlify functions are stored |
42+
43+
## Example
44+
### Deploy to production on release
45+
46+
> You can setup repo secrets to use in your workflows
47+
48+
```yml
49+
name: 'Netlify Deploy'
50+
51+
on:
52+
release:
53+
types: ['published']
54+
55+
jobs:
56+
deploy:
57+
name: 'Deploy'
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- uses: actions/checkout@v1
62+
- uses: jsmrcaga/action-netlify-deploy@master
63+
with:
64+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
65+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
66+
NETLIFY_DEPLOY_MESSAGE: "Prod deploy v${{ github.ref }}"
67+
NETLIFY_DEPLOY_TO_PROD: true
68+
```
69+
70+
### Preview Deploy on pull request
71+
```yml
72+
name: 'Netlify Preview Deploy'
73+
74+
on:
75+
pull_request:
76+
types: ['opened', 'edited', 'synchronize']
77+
78+
jobs:
79+
deploy:
80+
name: 'Deploy'
81+
runs-on: ubuntu-latest
82+
83+
steps:
84+
- uses: actions/checkout@v1
85+
- uses: jsmrcaga/action-netlify-deploy@master
86+
with:
87+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
88+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
89+
90+
```

action.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Netlify Deploy'
2+
author: 'Jo Colina'
3+
description: 'Netlify Deploy'
4+
5+
inputs:
6+
NETLIFY_AUTH_TOKEN:
7+
description: 'Auth token to use with netlify'
8+
required: true
9+
default: ''
10+
11+
NETLIFY_SITE_ID:
12+
description: 'Your Netlify site id'
13+
required: true
14+
default: ''
15+
16+
NETLIFY_DEPLOY_MESSAGE:
17+
description: 'A deploy message'
18+
required: false
19+
default: ''
20+
21+
build_directory:
22+
description: 'Directory where built files are stored'
23+
required: true
24+
default: 'build'
25+
26+
functions_directory:
27+
description: 'Directory where built files are stored'
28+
required: false
29+
default: ''
30+
31+
runs:
32+
using: 'docker'
33+
image: 'Dockerfile'
34+
args:
35+
- ${{ inputs.NETLIFY_AUTH_TOKEN }}
36+
- ${{ inputs.NETLIFY_SITE_ID }}
37+
- ${{ inputs.NETLIFY_DEPLOY_TO_PROD }}
38+
- ${{ inputs.build_directory }}
39+
- ${{ inputs.functions_directory }}
40+
41+
branding:
42+
icon: activity
43+
color: blue

entrypoint.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
npm i -g netlify-cli
4+
5+
NETLIFY_AUTH_TOKEN=$1
6+
NETLIFY_SITE_ID=$2
7+
NETLIFY_DEPLOY_TO_PROD=$3
8+
BUILD_DIRECTORY=$4
9+
FUNCTIONS_DIRECTORY=$5
10+
11+
# Install dependencies
12+
npm i
13+
14+
# Build project
15+
npm run build
16+
17+
# Export token to use with netlify's cli
18+
export NETLIFY_SITE_ID=$NETLIFY_SITE_ID
19+
export NETLIFY_AUTH_TOKEN=$NETLIFY_AUTH_TOKEN
20+
21+
# Deploy with netlify
22+
if [ -z $NETLIFY_DEPLOY_TO_PROD ]
23+
then
24+
netlify deploy --dir=$BUILD_DIRECTORY --functions=$FUNCTIONS_DIRECTORY --message="$INPUT_NETLIFY_DEPLOY_MESSAGE"
25+
else
26+
netlify deploy --dir=$BUILD_DIRECTORY --functions=$FUNCTIONS_DIRECTORY --prod --message="$INPUT_NETLIFY_DEPLOY_MESSAGE"
27+
fi

0 commit comments

Comments
 (0)