deploy #639
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI-CD | |
on: | |
push: | |
pull_request: | |
repository_dispatch: | |
types: [deploy] | |
jobs: | |
build_and_deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2-beta | |
with: | |
node-version: 14 | |
- name: NPM cache | |
uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: npm-packages-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
npm-packages- | |
# In order to make gatsby incremental build works, it's necessary .cache | |
# and public folder. | |
- name: Gatsby cache folder | |
uses: actions/cache@v2 | |
with: | |
path: .cache | |
key: gatsby-cache | |
- name: Gatsby public folder | |
uses: actions/cache@v2 | |
with: | |
path: public | |
key: gatsby-public | |
- name: Install dependencies | |
run: npm ci --prefer-offline --no-audit --no-progress | |
env: | |
HUSKY_SKIP_INSTALL: 1 | |
- name: Lint | |
if: | | |
!(github.event_name == 'repository_dispatch' && | |
github.event.action == 'deploy') | |
run: npm run lint | |
- name: Build Gatsby | |
run: npm run build -- --log-pages | |
env: | |
# incremental builds | |
# https://www.gatsbyjs.org/docs/page-build-optimizations-for-incremental-data-changes/ | |
GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES: true | |
GATSBY_TELEMETRY_DISABLED: 1 | |
NODE_ENV: production | |
DIRECTUS_API_TOKEN: ${{ secrets.DIRECTUS_API_TOKEN }} | |
GATSBY_ACTIVE_ENV: ${{ contains(github.ref, 'master') && 'production' || 'staging'}} | |
GATSBY_GMAPS_API_KEY: ${{ secrets.GMAPS_API_KEY }} | |
GATSBY_CONCURRENT_DOWNLOAD: 1 | |
- name: Deploy preview site | |
if: github.ref != 'refs/heads/master' | |
run: | | |
npm run deploy:draft | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
- name: Deploy production site | |
if: github.ref == 'refs/heads/master' | |
run: | | |
npm run deploy:prod | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |