Skip to content

Update preview workflow #519

Update preview workflow

Update preview workflow #519

Workflow file for this run

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Site preview
on:
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Allows GitHub variables to be more widely used
- uses: FranzDiebold/github-env-vars-action@v2
# Checkout both data and website repos
- name: Checkout data
uses: actions/checkout@v2
with:
path: data
- name: Checkout website
uses: actions/checkout@v2
with:
repository: audioxide/website
path: website
# Setup node (including yarn)
- name: Use Node.js 20
uses: actions/setup-node@v1
with:
node-version: 20
# Setup caching for images to reduce processing time
- name: Cache images
uses: actions/[email protected]
with:
# A list of files, directories, and wildcard patterns to cache and restore
path: data/dist
# An explicit key for restoring and saving the cache
key: ${{ env.CI_HEAD_REF_SLUG }}
# Setup caching for dependencies
- name: Cache dependencies
uses: actions/[email protected]
with:
# A list of files, directories, and wildcard patterns to cache and restore
path: |
data/node_modules
website/node_modules
# An explicit key for restoring and saving the cache
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
- run: yarn
working-directory: data
env:
GITHUB_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Hack away at the config to remove hard coded environment variables
- run: sed -i "s|^\s*environment.*$||g" netlify.toml
working-directory: data
# Build and deploy the data repo
- run: npx netlify deploy --build --alias data-preview-$CI_REF_NAME_SLUG
working-directory: data
env:
GITHUB_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use the repo specific token
# Concatenate branch specific URLs
SITE_URL: https://data-preview-${{ env.CI_REF_NAME_SLUG }}--clever-murdock-f2e04c.netlify.app
API_URL: https://data-preview-${{ env.CI_REF_NAME_SLUG }}--clever-murdock-f2e04c.netlify.app/api
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.API_NETLIFY_SITE_ID }}
- run: yarn
working-directory: website
env:
GITHUB_REGISTRY_TOKEN: ${{ secrets.REGISTRY_RETRIEVAL_TOKEN }}
# Hack away at the prod build step so we can set our own variables
- run: sed -i "s|export SITE_URL=\$URL && export EXT_API_URL=\$PROD_API_URL && [^&]*&& ||g" netlify.toml
working-directory: website
# Swap out SITE_URL placeholders in the config
- run: sed -i "s|\"SITE_URL|\"${SITE_URL}|g" netlify.toml
working-directory: website
env:
SITE_URL: https://data-preview-${{ env.CI_REF_NAME_SLUG }}--clever-murdock-f2e04c.netlify.app
# Build from the config and deploy the website
- run: npx netlify deploy --build --alias data-preview-$CI_REF_NAME_SLUG
working-directory: website
env:
GITHUB_REGISTRY_TOKEN: ${{ secrets.REGISTRY_RETRIEVAL_TOKEN }} # Use our own token for org wide access
SITE_URL: https://data-preview-${{ env.CI_REF_NAME_SLUG }}--clever-murdock-f2e04c.netlify.app
API_URL: https://data-preview-${{ env.CI_REF_NAME_SLUG }}--clever-murdock-f2e04c.netlify.app/api
EXT_API_URL: https://data-preview-${{ env.CI_REF_NAME_SLUG }}--wizardly-payne-3612b7.netlify.app
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.WEB_NETLIFY_SITE_ID }}
- uses: mshick/add-pr-comment@v1
with:
message: Preview this PR at https://data-preview-${{ env.CI_REF_NAME_SLUG }}--clever-murdock-f2e04c.netlify.app
repo-token: ${{ secrets.GITHUB_TOKEN }}