Skip to content

Deploy

Deploy #40

Workflow file for this run

name: Deploy
on:
workflow_dispatch:
inputs:
env:
description: 'Deploy to (dev|prod|dev prod)'
required: true
default: 'dev'
clean:
description: 'Clean cache (yes|no)'
required: true
default: 'no'
jobs:
set-state:
runs-on: ubuntu-latest
outputs:
deploy_prod: ${{ contains(github.event.inputs.env, 'prod') }}
deploy_dev: ${{ contains(github.event.inputs.env, 'dev') }}
clean_cache: ${{ contains(github.event.inputs.clean, 'yes') }}
path_prefix: ${{ steps.extract_path_prefix.outputs.path_prefix }}
branch_short_ref: ${{ steps.extract_branch.outputs.branch }}
steps:
- name: Checkout
uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
- name: Extract path prefix
uses: actions/github-script@v3
id: extract_path_prefix
with:
script: |
const {pathPrefix} = require(`${process.env.GITHUB_WORKSPACE}/gatsby-config.js`)
if (!pathPrefix) {
core.setFailed('Missing path prefix')
}
else if (pathPrefix === '/') {
core.setFailed('Path prefix "/" is not allowed')
}
else if (!pathPrefix.startsWith('/') || !pathPrefix.endsWith('/')) {
core.setFailed('Path prefix should start and end with "/"')
}
core.setOutput('path_prefix', pathPrefix)
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
echo-state:
needs: [set-state]
runs-on: ubuntu-latest
steps:
- run: echo "Deploy to dev - ${{ needs.set-state.outputs.deploy_dev }}"
- run: echo "Deploy to prod - ${{ needs.set-state.outputs.deploy_prod }}"
- run: echo "Clean cache - ${{ needs.set-state.outputs.clean_cache }}"
- run: echo "Repository org - ${{ github.event.repository.owner.login }}"
- run: echo "Repository name - ${{ github.event.repository.name }}"
- run: echo "Repository branch - ${{ needs.set-state.outputs.branch_short_ref }}"
- run: echo "Path prefix - ${{ needs.set-state.outputs.path_prefix }}"
pre-build-dev:
needs: [set-state]
runs-on: ubuntu-latest
if: needs.set-state.outputs.deploy_dev == 'true'
steps:
- name: check dev azure connection string
if: env.AIO_AZURE_DEV_CONNECTION_STRING == null
run: |
echo "::error::Please set the Azure Blob Storage connection string as AIO_AZURE_DEV_CONNECTION_STRING in Github Secrets"
exit 1
env:
AIO_AZURE_DEV_CONNECTION_STRING: ${{ secrets.AIO_AZURE_DEV_CONNECTION_STRING }}
build-dev:
defaults:
run:
shell: bash
needs: [set-state, pre-build-dev]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
- name: NPM Install
uses: bahmutov/npm-install@v1
- name: Gatsby Cache
uses: actions/cache@v2
with:
path: |
public
.cache
key: ${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{ github.run_id }}
restore-keys: |
${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-
- name: Clean Cache
if: needs.set-state.outputs.clean_cache == 'true'
run: |
npm run clean
- name: Build
run: |
npm run build
env:
PREFIX_PATHS: true # equivalent to --prefix-paths flag for 'gatsby build'
PATH_PREFIX: ${{ needs.set-state.outputs.path_prefix }}
GATSBY_ADOBE_LAUNCH_SRC: ${{ secrets.AIO_ADOBE_LAUNCH_DEV_SRC }}
REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_OWNER: ${{ github.event.repository.owner.login }}
REPO_NAME: ${{ github.event.repository.name }}
REPO_BRANCH: ${{ needs.set-state.outputs.branch_short_ref }}
GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.GOOGLE_OAUTH_CLIENT_ID }}
GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }}
GOOGLE_DOCS_TOKEN: ${{ secrets.GOOGLE_DOCS_TOKEN }}
GOOGLE_DOCS_FOLDER_ID: ${{ secrets.GOOGLE_DOCS_FOLDER_ID }}
GATSBY_IMS_SRC: ${{ secrets.AIO_IMS_DEV_SRC }}
GATSBY_IMS_CONFIG: ${{ secrets.AIO_IMS_DEV_CONFIG }}
GATSBY_ALGOLIA_APP_ID: ${{ secrets.AIO_ALGOLIA_APP_ID }}
GATSBY_ALGOLIA_API_KEY: ${{ secrets.AIO_ALGOLIA_API_KEY }}
GATSBY_ALGOLIA_INDEX_ALL_SRC: ${{ secrets.AIO_ALGOLIA_INDEX_ALL_SRC }}
GATSBY_ALGOLIA_SEARCH_INDEX: ${{ secrets.AIO_ALGOLIA_SEARCH_INDEX }}
- name: Deploy
uses: icaraps/static-website-deploy@master
with:
enabled-static-website: 'true'
source: 'public'
target: ${{ needs.set-state.outputs.path_prefix }}
connection-string: ${{ secrets.AIO_AZURE_DEV_CONNECTION_STRING }}
remove-existing-files: 'true'
- name: Purge Fastly Cache
uses: icaraps/gatsby-fastly-purge-action@master
with:
fastly-token: ${{ secrets.AIO_FASTLY_TOKEN }}
fastly-url: '${{ secrets.AIO_FASTLY_DEV_URL}}${{ needs.set-state.outputs.path_prefix }}'
pre-build-production:
needs: [set-state]
runs-on: ubuntu-latest
if: needs.set-state.outputs.deploy_prod == 'true'
steps:
- name: check prod azure connection string
if: env.AIO_AZURE_PROD_CONNECTION_STRING == null
run: |
echo "::error::Please set the Azure Blob Storage connection string as AIO_AZURE_PROD_CONNECTION_STRING in Github Secrets"
exit 1
env:
AIO_AZURE_PROD_CONNECTION_STRING: ${{ secrets.AIO_AZURE_PROD_CONNECTION_STRING }}
build-production:
defaults:
run:
shell: bash
needs: [set-state, pre-build-production]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
- name: NPM Install
uses: bahmutov/npm-install@v1
- name: Gatsby Cache
uses: actions/cache@v2
with:
path: |
public
.cache
key: ${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-${{ github.run_id }}
restore-keys: |
${{ needs.set-state.outputs.branch_short_ref }}-gatsby-cache-
- name: Clean Cache
if: needs.set-state.outputs.clean_cache == 'true'
run: |
npm run clean
- name: Build
run: |
npm run build
env:
PREFIX_PATHS: true # equivalent to --prefix-paths flag for 'gatsby build'
PATH_PREFIX: ${{ needs.set-state.outputs.path_prefix }}
GATSBY_ADOBE_LAUNCH_SRC: ${{ secrets.AIO_ADOBE_LAUNCH_PROD_SRC }}
REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_OWNER: ${{ github.event.repository.owner.login }}
REPO_NAME: ${{ github.event.repository.name }}
REPO_BRANCH: ${{ needs.set-state.outputs.branch_short_ref }}
GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.GOOGLE_OAUTH_CLIENT_ID }}
GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }}
GOOGLE_DOCS_TOKEN: ${{ secrets.GOOGLE_DOCS_TOKEN }}
GOOGLE_DOCS_FOLDER_ID: ${{ secrets.GOOGLE_DOCS_FOLDER_ID }}
GATSBY_IMS_SRC: ${{ secrets.AIO_IMS_PROD_SRC }}
GATSBY_IMS_CONFIG: ${{ secrets.AIO_IMS_PROD_CONFIG }}
ALGOLIA_WRITE_API_KEY: ${{ secrets.AIO_ALGOLIA_WRITE_API_KEY }}
ALGOLIA_INDEXATION_MODE: ${{ secrets.AIO_ALGOLIA_INDEXATION_MODE }}
ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME || github.event.repository.name }}
GATSBY_ALGOLIA_APP_ID: ${{ secrets.AIO_ALGOLIA_APP_ID }}
GATSBY_ALGOLIA_API_KEY: ${{ secrets.AIO_ALGOLIA_API_KEY }}
GATSBY_ALGOLIA_INDEX_ALL_SRC: ${{ secrets.AIO_ALGOLIA_INDEX_ALL_SRC }}
GATSBY_ALGOLIA_SEARCH_INDEX: ${{ secrets.AIO_ALGOLIA_SEARCH_INDEX }}
- name: Deploy
uses: icaraps/static-website-deploy@master
with:
enabled-static-website: 'true'
source: 'public'
target: ${{ needs.set-state.outputs.path_prefix }}
connection-string: ${{ secrets.AIO_AZURE_PROD_CONNECTION_STRING }}
remove-existing-files: 'true'
- name: Purge Fastly Cache
uses: icaraps/gatsby-fastly-purge-action@master
with:
fastly-token: ${{ secrets.AIO_FASTLY_TOKEN }}
fastly-url: '${{ secrets.AIO_FASTLY_PROD_URL }}${{ needs.set-state.outputs.path_prefix }}'