Giter VIP home page Giter VIP logo

gatsby-gh-pages-action's Introduction

Gatsby Publish

GitHub Action to build and deploy your Gatsby site to GitHub Pages โค๏ธ๐ŸŽฉ

Usage

This GitHub Action will run gatsby build at the root of your repository and deploy it to GitHub Pages for you! Here's a basic workflow example:

name: Gatsby Publish

on:
  push:
    branches:
      - dev

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: enriikke/gatsby-gh-pages-action@v2
        with:
          access-token: ${{ secrets.ACCESS_TOKEN }}

NOTE: In order to support npm and yarn, this Action relies on having a build script defined in your package.json file. Gatsby automatically defines this script whenever you start a new project via gatsby new, which in turn calls gatsby build.

Knobs & Handles

This Action is fairly simple but it does provide you with a couple of configuration options:

  • access-token: A GitHub Personal Access Token with the repo scope. This is required to push the site to your repo after Gatsby finish building it. You should store this as a secret in your repository. Provided as an input.

  • deploy-branch: The branch expected by GitHub to have the static files needed for your site. For org and user pages it should always be master. This is where the output of gatsby build will be pushed to. Provided as an input. Defaults to master.

  • gatsby-args: Additional arguments that get passed to gatsby build. See the Gatsby documentation for a list of allowed options. Provided as an input. Defaults to nothing.

Org or User Pages

Create a repository with the format <YOUR/ORG USERNAME>.github.io, push your Gatsby source code to a branch other than master and add this GitHub Action to your workflow! ๐Ÿš€๐Ÿ˜ƒ

Repository Pages

Repo pages give you the option to push your static site to either master or gh-pages branches. They also work a little different because the URL includes a trailing path with the repository name, like https://username.github.io/reponame/. You need to tell Gatsby what the path prefix is via gatsby-config.js:

module.exports = {
  pathPrefix: "/reponame",
}

Additionally, you need to tell the gatsby build command to use it by passing the --prefix-paths as an argument. Here's an example workflow for that:

name: Gatsby Publish

on:
  push:
    branches:
      - dev

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: enriikke/gatsby-gh-pages-action@v2
        with:
          access-token: ${{ secrets.ACCESS_TOKEN }}
          deploy-branch: gh-pages
          gatsby-args: --prefix-paths

CNAME

You have a custom domain you would like to use? Fancy! ๐Ÿ˜Ž This Action's got you covered! Assuming you have already set up your DNS provider as defined in the GitHub Pages docs, all we need next is a CNAME file at the root of your project with the domain you would like to use. For example:

imenrique.com

Notice that it's all capitals CNAME ๐Ÿ˜Š.

This is how GitHub keeps track of the domain you want to use. This action will copy the file to the public directory generated by Gatsby before pushing your site so that the domain is persisted between deploys.

Assumptions

This Action assumes that your Gatsby code sits at the root of your repository and gatsby build outputs to the public directory. As of this writing, Gatsby doesn't provide a way to customize the build directory so this should be a safe assumption.

Additionally, a build script on package.json is expected for this Action to to work (as mentioned at the beginning). Ultimately, this is what calls gatsby build.

That's It

Have fun building! โœจ

gatsby-gh-pages-action's People

Contributors

enriikke avatar antoncarlsson avatar garritfra avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.