Skip to content

Instantly share code, notes, and snippets.

@2018kguo
Last active March 15, 2021 12:19
Show Gist options
  • Save 2018kguo/31db080e27e2d90fd50f71086d264e0b to your computer and use it in GitHub Desktop.
Save 2018kguo/31db080e27e2d90fd50f71086d264e0b to your computer and use it in GitHub Desktop.
Workflow to deploy Gatsby site to GitHub Pages w/ Google Analytics
# This workflow to automatically build and deploy to GitHub Pages (master branch)
# when code is pushed to the dev branch
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push events but only for the dev branch
push:
branches: [ dev ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
#Create environment variable for Node
- name: Create .env file
uses: SpicyPizza/create-envfile@v1
with:
envkey_GOOGLE_ANALYTICS_ID: ${{ secrets.GOOGLE_ANALYTICS_ID }}
#This is required if public is in .gitignore, which it likely is
- name: Create public folder for build output
run: mkdir -p public
# Install packages
- name: Run npm install
run: npm install
# Gatsby build
- name: Run npm build
run: npm run build
# Deploy to master
- name: Deploy 🚀
uses: JamesIves/[email protected]
with:
branch: master # The branch the action should deploy to.
folder: public # The folder the action should deploy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment