Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Mar 1, 2023
0 parents commit 5a8e07b
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Netlify Deploy Github Action v1.0.0

* Initial release
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Data Intuitive

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
Netlify Deploy Github Action
================

A wrapper for the “netlify deploy” command, used for deploying
pre-rendered site to Netlify. See the [Netlify reference
documentation](https://cli.netlify.com/commands/deploy/#nodejs-function-entry-points)
for more information.

Note: This action does not perform a build of the static website and
assumes the directory is ready to be deployed as is.

## Usage

``` yaml
- name: Deploy to Netlify 🚀
uses: data-intuitive/[email protected]
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
site: 'my-netlify-site'
dir: '_site'
prod: true
message: 'Deploy production ${{ github.ref }}'
```
## Inputs
- `auth` (*required*): Netlify auth token to deploy with. Generate the
auth token
[here](https://app.netlify.com/user/applications#personal-access-tokens).

- `alias` (*optional*): Specifies the alias for deployment, the string
at the beginning of the deploy subdomain (string). Useful for creating
predictable deployment URLs. Maximum 37 characters.

- `dir` (*required*): Specify a folder to deploy (string).

- `prod` (*optional*): Whether the site should be deployed to production
(boolean).

- `message` (*optional*): A short message to include in the deploy log
(string).

- `site` (*required*): A site name or ID to deploy to (string). You can
retrieve the API ID on your Site Settings.

- `timeout` (*optional*): Timeout to wait for deployment to finish
(string).

- `debug` (*optional*): Print debugging information (boolean).

## Outputs

- `site-name`: The name of the Netlify site associated with the
deployment.
- `deploy-id`: A unique identifier assigned by Netlify to the
deployment. It is used to track and manage the deployment, and can be
used to retrieve additional information about the deployment from the
Netlify API.
- `deploy-url`: The URL of the deployed site. It indicates the URL where
the deployed application can be accessed by end-users.
- `logs`: The URL of the deployment logs. It provides detailed
information about the deployment process, including any errors or
warnings that occurred during the deployment.

## Example with Quarto

This example action will run `quarto render` on a project and then
publish the site on Netlify. Remove the part about Quarto if not
relevant or using a different builder.

``` yaml
on:
push:
branches: [ main, master ]
pull_request:
name: Render project
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Quarto
uses: quarto-dev/quarto-actions/setup@v2
- name: Render Quarto Project
uses: quarto-dev/quarto-actions/render@v2
- name: Deploy to Netlify 🚀
if: github.event_name != 'pull_request'
uses: data-intuitive/[email protected]
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: '_site'
site: 'my-netlify-site'
prod: true
message: 'Deploy production ${{ github.ref }}'
- name: Deploy preview
id: deploy_preview
if: github.event_name == 'pull_request'
uses: data-intuitive/[email protected]
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: '_site'
site: 'my-netlify-site'
alias: "${{ env.BRANCH_NAME }}"
message: 'Deploy prooduction ${{ github.ref }}'
- uses: thollander/actions-comment-pull-request@v2
if: github.event_name == 'pull_request'
with:
message: |
[![Deploy: success](https://img.shields.io/badge/Deploy-success-success)](${{ steps.deploy_preview.outputs.deploy-url }})
comment_tag: deploy_status
- uses: thollander/actions-comment-pull-request@v2
if: github.event_name == 'pull_request' && failure()
with:
message: |
[![Deploy: failure](https://img.shields.io/badge/Deploy-failure-critical)]${{ steps.deploy_preview.outputs.logs }})
comment_tag: deploy_status
```
109 changes: 109 additions & 0 deletions README.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
title: Netlify Deploy Github Action
format: gfm
---

```{r}
#| include: false
library(tidyverse)
action <- yaml::read_yaml("action.yml")
```

`r action$description`

## Usage

```yaml
- name: Deploy to Netlify 🚀
uses: data-intuitive/[email protected]
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
site: 'my-netlify-site'
dir: '_site'
prod: true
message: 'Deploy production ${{ github.ref }}'
```
## Inputs
```{r}
#| echo: false
lines <- map_chr(names(action$inputs), function(name) {
input <- action$inputs[[name]]
required <- ifelse (input$required %||% FALSE, "required", "optional")
glue::glue("* `{name}` (_{required}_): {input$description}")
})
knitr::asis_output(paste0(lines, collapse = "\n"))
```

## Outputs

```{r}
#| echo: false
lines <- map_chr(names(action$outputs), function(name) {
output <- action$outputs[[name]]
glue::glue("* `{name}`: {output$description}")
})
knitr::asis_output(paste0(lines, collapse = "\n"))
```

## Example with Quarto

This example action will run `quarto render` on a project and then publish the site on Netlify. Remove the part about Quarto if not relevant or using a different builder.

```yaml
on:
push:
branches: [ main, master ]
pull_request:

name: Render project

jobs:
build-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Quarto
uses: quarto-dev/quarto-actions/setup@v2

- name: Render Quarto Project
uses: quarto-dev/quarto-actions/render@v2

- name: Deploy to Netlify 🚀
if: github.event_name != 'pull_request'
uses: data-intuitive/[email protected]
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: '_site'
site: 'my-netlify-site'
prod: true
message: 'Deploy production ${{ github.ref }}'

- name: Deploy preview
id: deploy_preview
if: github.event_name == 'pull_request'
uses: data-intuitive/[email protected]
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: '_site'
site: 'my-netlify-site'
alias: "${{ env.BRANCH_NAME }}"
message: 'Deploy prooduction ${{ github.ref }}'

- uses: thollander/actions-comment-pull-request@v2
if: github.event_name == 'pull_request'
with:
message: |
[![Deploy: success](https://img.shields.io/badge/Deploy-success-success)](${{ steps.deploy_preview.outputs.deploy-url }})
comment_tag: deploy_status

- uses: thollander/actions-comment-pull-request@v2
if: github.event_name == 'pull_request' && failure()
with:
message: |
[![Deploy: failure](https://img.shields.io/badge/Deploy-failure-critical)]${{ steps.deploy_preview.outputs.logs }})
comment_tag: deploy_status
```
105 changes: 105 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
name: Netlify Deploy
author: Data Intuitive
description: |
A wrapper for the "netlify deploy" command, used for deploying pre-rendered site to Netlify.
See the [Netlify reference documentation](https://cli.netlify.com/commands/deploy/#nodejs-function-entry-points) for more information.
Note: This action does not perform a build of the static website and assumes the directory is ready to be deployed as is.
inputs:
auth:
description: Netlify auth token to deploy with. Generate the auth token [here](https://app.netlify.com/user/applications#personal-access-tokens).
required: true
alias:
description: |
Specifies the alias for deployment, the string at the beginning of the deploy subdomain (string).
Useful for creating predictable deployment URLs. Maximum 37 characters.
required: false
dir:
description: Specify a folder to deploy (string).
required: true
prod:
description: Whether the site should be deployed to production (boolean).
required: false
default: "false"
message:
description: A short message to include in the deploy log (string).
required: false
site:
description: A site name or ID to deploy to (string). You can retrieve the API ID on your Site Settings.
required: true
timeout:
description: Timeout to wait for deployment to finish (string).
required: false
debug:
description: Print debugging information (boolean).
required: false
default: "false"
outputs:
site-name:
description: The name of the Netlify site associated with the deployment.
value: ${{ steps.netlify-deploy.outputs.site-name }}
deploy-id:
description: A unique identifier assigned by Netlify to the deployment. It is used to track and manage the deployment, and can be used to retrieve additional information about the deployment from the Netlify API.
value: ${{ steps.netlify-deploy.outputs.deploy-id }}
deploy-url:
description: The URL of the deployed site. It indicates the URL where the deployed application can be accessed by end-users.
value: ${{ steps.netlify-deploy.outputs.deploy-url }}
logs:
description: The URL of the deployment logs. It provides detailed information about the deployment process, including any errors or warnings that occurred during the deployment.
value: ${{ steps.netlify-deploy.outputs.logs }}
runs:
using: composite
steps:
- shell: bash
id: netlify-deploy
env:
NETLIFY_AUTH_TOKEN: ${{ inputs.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ inputs.NETLIFY_SITE_ID }}
run: |
ARGS=()
# process auth
if [[ -n "${{ inputs.auth }}" ]]; then
ARGS+=("--auth=${{ inputs.auth }}")
fi
# process prod and alias
if [[ "${{ inputs.prod }}" == "true" ]]; then
ARGS+=("--prod")
elif [[ -n "${{ inputs.alias }}" ]]; then
ARGS+=("--alias=${{ inputs.alias }}")
fi
# process dir
if [[ -n "${{ inputs.dir }}" ]]; then
ARGS+=("--dir=${{ inputs.dir }}")
fi
# process message
if [[ -n "${{ inputs.message }}" ]]; then
ARGS+=("--message=${{ inputs.message }}")
fi
# process site
if [[ -n "${{ inputs.site }}" ]]; then
ARGS+=("--site=${{ inputs.site }}")
fi
# process timeout
if [[ -n "${{ inputs.timeout }}" ]]; then
ARGS+=("--timeout=${{ inputs.timeout }}")
fi
# process debug
if [[ "${{ inputs.debug }}" == "true" ]]; then
ARGS+=("--debug")
fi
TEMP_JSON="${{runner.temp}}/output.json"
netlify deploy --json "${ARGS[@]}" | tee "$TEMP_JSON"
jq -r '"site-name=" + .site_name' "$TEMP_JSON" >> $GITHUB_OUTPUT
jq -r '"deploy-id=" + .deploy_id' "$TEMP_JSON" >> $GITHUB_OUTPUT
jq -r '"deploy-url=" + .deploy_url' "$TEMP_JSON" >> $GITHUB_OUTPUT
jq -r '"logs=" + .logs' "$TEMP_JSON" >> $GITHUB_OUTPUT

0 comments on commit 5a8e07b

Please sign in to comment.