├── LICENSE ├── README.md ├── build ├── Dockerfile ├── README.md └── entrypoint.sh ├── cli ├── Dockerfile ├── README.md └── entrypoint.sh └── diff-includes ├── Dockerfile ├── README.md └── entrypoint.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Netlify 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Actions for Netlify 2 | 3 | This repository contains GitHub Actions for Netlify, for performing common tasks such as triggering a site deploy, as well as a generic cli for doing arbitrary actions with the netlify commandline client. 4 | 5 | ## Usage 6 | Usage information for individual commands can be found in their respective directories. 7 | 8 | ```yml 9 | on: push 10 | name: Publish docs if changed 11 | jobs: 12 | checkChangesInDocs: 13 | name: Check changes in docs 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@master 17 | - name: Check changes in stories 18 | uses: netlify/actions/diff-includes@master 19 | with: 20 | args: docs 21 | ``` 22 | -------------------------------------------------------------------------------- /build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | LABEL version="1.0.0" 4 | LABEL repository="http://github.com/netlify/actions" 5 | LABEL homepage="http://github.com/netlify/actions/netlify" 6 | LABEL maintainer="Netlify" 7 | LABEL "com.github.actions.name"="Netlify Build" 8 | LABEL "com.github.actions.description"="Deploy a site to Netlify" 9 | LABEL "com.github.actions.icon"="cloud" 10 | LABEL "com.github.actions.color"="blue" 11 | 12 | RUN apk add --update curl jq && rm -rf /var/cache/apk/* 13 | 14 | COPY entrypoint.sh /entrypoint.sh 15 | ENTRYPOINT ["/entrypoint.sh"] 16 | -------------------------------------------------------------------------------- /build/README.md: -------------------------------------------------------------------------------- 1 | # GitHub action to trigger a build in Netlify 2 | 3 | Trigger a build on Netlify, if there's no site for this repo it can automagically set up one with the specified base directory, command, and publish directory. 4 | 5 | ## Secrets 6 | - `GITHUB_TOKEN` - *Required* GitHub token provided by actions to validate requests 7 | - `NETLIFY_SITE_ID` - *Optional* API site ID of the site you wanna work on 8 | [Obtain it from the UI](https://www.netlify.com/docs/cli/#link-with-an-environment-variable) 9 | 10 | ## Environment Variables 11 | - `NETLIFY_BASE` - *Optional* Directory to change to before starting build 12 | - `NETLIFY_CMD` - *Optional* Build command to build site 13 | - `NETLIFY_DIR` - *Optional* The directory to publish (relative to root of your repo) 14 | 15 | ## Example 16 | 17 | Trigger a build to a specific site in Netlify 18 | 19 | ```yml 20 | on: push 21 | name: Publish on Netlify 22 | 23 | jobs: 24 | publish: 25 | runs-on: ubuntu-latest 26 | 27 | steps: 28 | - uses: actions/checkout@master 29 | 30 | - name: Publish 31 | uses: netlify/actions/build@master 32 | env: 33 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 34 | NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} 35 | ``` 36 | 37 | Trigger a build on Netlify, if there's no site for this repo it will automagically set up one with the specified base, command, and publish directory. 38 | 39 | ```yml 40 | on: push 41 | name: Publish on Netlify 42 | 43 | jobs: 44 | publish: 45 | runs-on: ubuntu-latest 46 | 47 | steps: 48 | - uses: actions/checkout@master 49 | 50 | - name: Publish 51 | uses: netlify/actions/build@master 52 | env: 53 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 54 | NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} 55 | NETLIFY_BASE: site 56 | NETLIFY_CMD: npm build 57 | NETLIFY_DIR: site/_build 58 | ``` -------------------------------------------------------------------------------- /build/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -l 2 | 3 | if [ -f "$HOME/ignore" ] && grep "^ignore:$BUILD_DIR" "$HOME/ignore"; then 4 | echo "$BUILD_DIR didn't change" 5 | else 6 | echo "Deploying" 7 | jq \ 8 | --arg cmd "$NETLIFY_CMD" \ 9 | --arg base "$NETLIFY_BASE" \ 10 | --arg dir "$NETLIFY_DIR" \ 11 | --arg site_id "$NETLIFY_SITE_ID" \ 12 | '. + {cmd: $cmd, base: $base, dir: $dir, site_id: $site_id}' \ 13 | "$GITHUB_EVENT_PATH" > args.json 14 | 15 | code=$(curl \ 16 | --silent \ 17 | --show-error \ 18 | --output /dev/stderr \ 19 | --write-out "%{http_code}" \ 20 | -H "Authorization: $GITHUB_TOKEN" \ 21 | -H "X-GitHub-Event: $GITHUB_EVENT_NAME" \ 22 | -H 'Content-Type: application/json' \ 23 | --data-binary @args.json \ 24 | "https://api.netlify.com/api/v1/github/$GITHUB_REPOSITORY/build" 25 | ) 2>&1 26 | 27 | if [ ! 204 -eq "$code" ] && [ ! 200 -eq "$code" ]; then 28 | exit 1 29 | fi 30 | fi 31 | -------------------------------------------------------------------------------- /cli/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:22-alpine 2 | 3 | LABEL version="2.0.0" 4 | LABEL repository="http://github.com/netlify/actions" 5 | LABEL homepage="http://github.com/netlify/actions/netlify" 6 | LABEL maintainer="Netlify" 7 | LABEL "com.github.actions.name"="Netlify" 8 | LABEL "com.github.actions.description"="Wraps the Netlify CLI to enable common Netlify commands" 9 | LABEL "com.github.actions.icon"="cloud" 10 | LABEL "com.github.actions.color"="blue" 11 | 12 | RUN npm install -g netlify-cli 13 | 14 | COPY entrypoint.sh /entrypoint.sh 15 | ENTRYPOINT ["/entrypoint.sh"] 16 | -------------------------------------------------------------------------------- /cli/README.md: -------------------------------------------------------------------------------- 1 | # GitHub Actions for Netlify CLI 2 | 3 | This Action enables arbitrary actions with the [Netlify CLI](https://github.com/netlify/cli) 4 | 5 | ## Secrets 6 | - `NETLIFY_AUTH_TOKEN` - *Required* The token to use for authentication. 7 | [Obtain one with the UI](https://www.netlify.com/docs/cli/#obtain-a-token-in-the-netlify-ui) 8 | - `NETLIFY_SITE_ID` - *Optional* API site ID of the site you wanna work on 9 | [Obtain it from the UI](https://www.netlify.com/docs/cli/#link-with-an-environment-variable) 10 | 11 | ## Outputs 12 | 13 | The following outputs will be available from a step that uses this action: 14 | - `NETLIFY_OUTPUT`, the full stdout from the run of the `netlify` command 15 | - `NETLIFY_URL`, the URL of the draft site that Netlify provides 16 | - `NETLIFY_LOGS_URL`, the URL where the logs from the deploy can be found 17 | - `NETLIFY_LIVE_URL`, the URL of the "real" site, set only if `--prod` was passed 18 | 19 | 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. 20 | 21 | ## Example 22 | 23 | ```yml 24 | on: push 25 | name: Publish on Netlify 26 | jobs: 27 | publish: 28 | runs-on: ubuntu-latest 29 | 30 | steps: 31 | - uses: actions/checkout@master 32 | 33 | - name: Publish 34 | uses: netlify/actions/cli@master 35 | with: 36 | args: deploy --dir=site --functions=functions 37 | env: 38 | NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} 39 | NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} 40 | ``` 41 | -------------------------------------------------------------------------------- /cli/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -l 2 | 3 | read -d '' COMMAND <<- EOF 4 | if [ -f "$HOME/ignore" ] && grep "^ignore:$BUILD_DIR" "$HOME/ignore"; then 5 | echo "$BUILD_DIR didn't change" 6 | else 7 | ${BUILD_COMMAND:-echo} && netlify $* 8 | fi 9 | EOF 10 | 11 | OUTPUT=$(sh -c "$COMMAND") 12 | 13 | NETLIFY_OUTPUT=$(echo "$OUTPUT") 14 | NETLIFY_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*(--)[a-zA-Z0-9./?=_-]*') #Unique key: -- 15 | NETLIFY_LOGS_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://app.netlify.com/[a-zA-Z0-9./?=_-]*') #Unique key: app.netlify.com 16 | 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 17 | 18 | echo "::set-output name=NETLIFY_OUTPUT::$NETLIFY_OUTPUT" 19 | echo "::set-output name=NETLIFY_URL::$NETLIFY_URL" 20 | echo "::set-output name=NETLIFY_LOGS_URL::$NETLIFY_LOGS_URL" 21 | echo "::set-output name=NETLIFY_LIVE_URL::$NETLIFY_LIVE_URL" 22 | -------------------------------------------------------------------------------- /diff-includes/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | LABEL version="1.0.0" 4 | LABEL repository="http://github.com/netlify/actions" 5 | LABEL homepage="http://github.com/netlify/actions/diff-includes" 6 | LABEL maintainer="Netlify" 7 | LABEL "com.github.actions.name"="Diff includes" 8 | LABEL "com.github.actions.description"="Stop workflow unless changes were made in certain files/directories." 9 | LABEL "com.github.actions.icon"="git-commit" 10 | LABEL "com.github.actions.color"="gray-dark" 11 | 12 | RUN apk add --update git jq && rm -rf /var/cache/apk/* 13 | 14 | COPY entrypoint.sh /entrypoint.sh 15 | ENTRYPOINT ["/entrypoint.sh"] 16 | -------------------------------------------------------------------------------- /diff-includes/README.md: -------------------------------------------------------------------------------- 1 | # Diff Includes Filter for GitHub Actions 2 | 3 | This action includes a filter to stop workflows unless certain files or directories are changed in a range of commits. 4 | 5 | ## Examples 6 | 7 | ```yml 8 | on: push 9 | name: Publish docs if changed 10 | 11 | jobs: 12 | checkChangesInDocs: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@master 17 | 18 | - name: Check changes in docs 19 | uses: netlify/actions/diff-includes@master 20 | with: 21 | # this can be one or many files/directories 22 | args: docs 23 | 24 | build: 25 | runs-on: ubuntu-latest 26 | 27 | steps: 28 | - name: Build 29 | needs: checkChangesInDocs 30 | # See https://github.com/netlify/actions/tree/master/build for details 31 | uses: netlify/actions/build@master 32 | env: 33 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 34 | NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} 35 | # this should match previous action `args` until known issue is resolved 36 | BUILD_DIR: docs 37 | ``` -------------------------------------------------------------------------------- /diff-includes/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -l 2 | 3 | # shellcheck disable=SC2046 disable=SC2048 disable=SC2086 4 | if ! git diff-index --quiet HEAD~$(jq '.commits | length' "${GITHUB_EVENT_PATH}") $*; then 5 | echo "Changes in $*, proceeding" 6 | else 7 | echo "No changes in $*, stopping" && echo "ignore:$*" >> "$HOME/ignore" 8 | fi 9 | --------------------------------------------------------------------------------