Skip to content

Build, Test, Deploy - Site #823

Build, Test, Deploy - Site

Build, Test, Deploy - Site #823

Workflow file for this run

name: Build, Test, Deploy - Site
on:
push:
paths:
- site/**
- .github/workflows/tbd-site.yml
pull_request:
paths:
- site/**
- .github/workflows/tbd-site.yml
workflow_dispatch:
jobs:
#########################
## Site Testing & Building
#########################
test-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: site/pnpm-lock.yaml
- name: Install dependencies
working-directory: site
run: pnpm install
- name: Test and Build
working-directory: site
run: pnpm t
env:
SANITY_PROJECT_ID: ${{ secrets.SANITY_PROJECT_ID }}
SANITY_DATASET: ${{ secrets.SANITY_DATASET }}
SANITY_TOKEN: ${{ secrets.SANITY_TOKEN }}
SANITY_WEBHOOK_SECRET: ${{ secrets.SANITY_WEBHOOK_SECRET }}
- name: Upload search build
# Let non-Dependabot branches and PRs do a preview deploy
if: (github.ref_type == 'branch' && !startsWith(github.ref_name , 'dependabot')) || github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: search
path: |
./site/public/pagefind
./site/.generated
#########################
## Deploy site to Firebase (Branches and PRs only)
#########################
deploy:
needs: test-build
runs-on: ubuntu-latest
# Let non-Dependabot branches and PRs do a preview deploy
if: (github.ref_type == 'branch' && !startsWith(github.ref_name , 'dependabot')) || github.event_name == 'pull_request'
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
steps:
- name: Set Channel ID - Branch
if: github.ref_type == 'branch'
run: echo "CHANNEL_ID=branch-${{ github.ref_name }}" >> $GITHUB_ENV
- name: Set Channel ID - Live
if: github.ref == 'refs/heads/main'
run: echo "CHANNEL_ID=live" >> $GITHUB_ENV
- name: Set Channel ID - PR
if: github.event_name == 'pull_request'
run: echo "CHANNEL_ID=pr-${{ github.event.number }}" >> $GITHUB_ENV
- name: Set Expiry
if: env.CHANNEL_ID != 'live'
run: echo "EXPIRES=30d" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
cache-dependency-path: site/pnpm-lock.yaml
- name: Install dependencies
working-directory: site
run: pnpm install
- name: Build Pregen
working-directory: site
run: pnpm pregen
env:
SANITY_PROJECT_ID: ${{ secrets.SANITY_PROJECT_ID }}
SANITY_DATASET: ${{ secrets.SANITY_DATASET }}
SANITY_TOKEN: ${{ secrets.SANITY_TOKEN }}
SANITY_WEBHOOK_SECRET: ${{ secrets.SANITY_WEBHOOK_SECRET }}
- name: Make .env file
uses: SpicyPizza/[email protected]
with:
envkey_SANITY_WEBHOOK_SECRET: ${{ secrets.SANITY_WEBHOOK_SECRET }}
envkey_GITHUB_TOKEN: ${{ secrets.WORKFLOW_PAT }}
envkey_SANITY_PROJECT_ID: ${{ secrets.SANITY_PROJECT_ID }}
envkey_SANITY_DATASET: ${{ secrets.SANITY_DATASET }}
envkey_SANITY_TOKEN: ${{ secrets.SANITY_TOKEN }}
envkey_PREVIEW_KEY: ${{ secrets.PREVIEW_KEY }}
directory: site
- name: Deploy Hosting
uses: FirebaseExtended/action-hosting-deploy@v0
with:
entryPoint: site
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_CROS_STAGING }}
channelId: ${{ env.CHANNEL_ID }}
expires: ${{ env.EXPIRES }}
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
SANITY_PROJECT_ID: ${{ secrets.SANITY_PROJECT_ID }}
SANITY_DATASET: ${{ secrets.SANITY_DATASET }}
SANITY_TOKEN: ${{ secrets.SANITY_TOKEN }}
SANITY_WEBHOOK_SECRET: ${{ secrets.SANITY_WEBHOOK_SECRET }}
GITHUB_TOKEN: ${{ secrets.WORKFLOW_PAT }}