Skip to content

Merge pull request #1148 from maxmind/greg/fix-workflows #762

Merge pull request #1148 from maxmind/greg/fix-workflows

Merge pull request #1148 from maxmind/greg/fix-workflows #762

Workflow file for this run

name: Production
on:
push:
branches:
- main
env:
FIREBASE_PROJECT_ID: mm-dev-site-production
FIREBASE_SERVICE_ACCOUNT: "${{ secrets.PRODUCTION_FIREBASE_SERVICE_ACCOUNT }}"
concurrency: production_deploy
jobs:
cache-keys:
name: Cache keys
runs-on: ubuntu-latest
outputs:
build: build-${{ steps.build.outputs.hash }}-v2
node-modules: node-modules-${{ steps.node-modules.outputs.hash }}-v1
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- id: build
run: echo "::set-output name=hash::${{ hashFiles('bin/**', 'content/**', 'firebase/**', 'functions/src/**', 'src/**', 'static/**', '**/package.json', '**/package-lock.json') }}"
- id: node-modules
run: echo "::set-output name=hash::${{ hashFiles('**/package-lock.json') }}"
build:
needs: cache-keys
name: Build
runs-on: ubuntu-latest
outputs:
is-cached-build: ${{ steps.cached-build.outputs.cache-hit }}
steps:
- name: Check Out repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Get cached dependencies
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
node_modules
functions/node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}
- if: steps.cache-node-modules.outputs.cache-hit != 'true'
name: Install dependencies
run: npm ci
- name: Get cached build
id: cached-build
uses: actions/cache@v3
with:
path: |
functions/lib
public
firebase.json
key: ${{ needs.cache-keys.outputs.build }}
- if: steps.cached-build.outputs.cache-hit != 'true'
name: Build
env:
GATSBY_URL: https://dev.maxmind.com
run: npm run build
test-unit:
if: needs.build.outputs.is-cached-build != 'true'
name: Test – Unit
needs: [cache-keys, build]
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Get cached dependencies
uses: actions/cache@v3
with:
path: |
node_modules
functions/node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}
- name: Run unit tests
run: npm run test:unit
deploy-hosting:
name: Deploy – Hosting
needs: [cache-keys, build, test-unit]
# Only run this job if test jobs either ran successfully or were skipped
# because a previously tested build was cached.
# Inspired by https://github.com/actions/runner/issues/491#issuecomment-850884422
if: |
always() &&
(needs.test-unit.result == 'success' || needs.test-unit.result == 'skipped')
runs-on: ubuntu-latest
permissions:
checks: write
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Get cached build
uses: actions/cache@v3
with:
path: |
functions/lib
public
firebase.json
key: ${{ needs.cache-keys.outputs.build }}
- name: Deploy Firebase live channel
uses: FirebaseExtended/action-hosting-deploy@4d0d0023f1d92b9b7d16dda64b3d7abd2c98974b # v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ env.FIREBASE_SERVICE_ACCOUNT }}"
projectId: ${{ env.FIREBASE_PROJECT_ID }}
channelId: live
deploy-functions:
name: Deploy - Functions
needs: [cache-keys, build, test-unit]
# Only run this job if test jobs either ran successfully or were skipped
# because a previously tested build was cached.
# Inspired by https://github.com/actions/runner/issues/491#issuecomment-850884422
if: |
always() &&
(needs.test-unit.result == 'success' || needs.test-unit.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Get cached build
uses: actions/cache@v3
with:
path: |
functions/lib
public
firebase.json
key: ${{ needs.cache-keys.outputs.build }}
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@ee9693ff89cdf73862b8a13988f6a71070e8fc58 # v0.2.1
with:
project_id: ${{ env.FIREBASE_PROJECT_ID }}
service_account_key: "${{ env.FIREBASE_SERVICE_ACCOUNT }}"
export_default_credentials: true
- name: Get cached dependencies
uses: actions/cache@v3
with:
path: |
node_modules
functions/node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}
- name: Deploy all other Firebase resources
run: npm exec -- firebase deploy --except hosting --project ${{ env.FIREBASE_PROJECT_ID }} --force
test-e2e:
name: Test – End-to-end
needs: [cache-keys, deploy-hosting, deploy-functions]
# Force this step to run after successful deployment jobs
if: |
always() &&
needs.deploy-hosting.result == 'success' &&
needs.deploy-functions.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- name: Get cached dependencies
uses: actions/cache@v3
with:
path: |
node_modules
functions/node_modules
key: ${{ needs.cache-keys.outputs.node-modules }}
- name: Run end-to-end tests
env:
E2E_TARGET_URL: https://dev.maxmind.com
run: npm run test:e2e