Skip to content

Deployment

Deployment #37

Workflow file for this run

name: Deployment
on:
push:
branches:
- production
workflow_dispatch:
concurrency:
group: production_deployment
cancel-in-progress: true
jobs:
deployment:
name: Deploy
runs-on: ubuntu-latest
environment:
name: production
url: ${{ steps.get-site-url.outputs.channel-url}}
env:
GCP_PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}
steps:
# Setting environment variables which depend on the runner, cannot set in jobs.env: https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
- run: echo "AUDIOS_DATA_PATH=$RUNNER_TEMP/audios.json" >> $GITHUB_ENV
- run: echo "GOOGLE_APPLICATION_CREDENTIALS=$RUNNER_TEMP/service-account.json" >> $GITHUB_ENV
- run: echo $SERVICE_ACCOUNT > $GOOGLE_APPLICATION_CREDENTIALS
env:
SERVICE_ACCOUNT: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- run: curl -sL firebase.tools | analytics=false bash
# Downloading audios data file from Firebase RTDB
- run: firebase database:get /audio/records --output $AUDIOS_DATA_PATH --project $GCP_PROJECT_ID
- uses: algolia/setup-algolia-cli@v1.1.0
# Mimicing the behaviour of replace-all-objects: https://www.algolia.com/doc/api-reference/api-methods/replace-all-objects/
# For pipefail: https://stackoverflow.com/a/19804002
- name: Update Algolia index
run: |
set -o pipefail
algolia indices copy $INDEX $TEMP_INDEX --scope settings,synonyms,rules --confirm
# https://www.algolia.com/doc/tools/cli/examples/recipes/#import-from-a-json-file
jq -c '.[]?' $AUDIOS_DATA_PATH | algolia objects import $TEMP_INDEX -F -
algolia indices move $TEMP_INDEX $INDEX --confirm
env:
ALGOLIA_CLI_TELEMETRY: 0
# CLI uses these two env variable for authentication: https://github.com/algolia/setup-algolia-cli/issues/4#issuecomment-1465172597
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
ALGOLIA_ADMIN_API_KEY: ${{ secrets.ALGOLIA_ADMIN_API_KEY }}
INDEX: ${{ vars.ALGOLIA_INDEX_AUDIOS }}
TEMP_INDEX: ${{ vars.ALGOLIA_INDEX_AUDIOS }}_tmp
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: frontend/package.json
cache: npm
cache-dependency-path: frontend/package-lock.json
- run: |
npm ci
npm run lint
npm run check-js-typing
npm test --if-present
npm run build
name: Prepare frontend
working-directory: frontend
env:
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
ALGOLIA_INDEX_AUDIOS: ${{ vars.ALGOLIA_INDEX_AUDIOS }}
ALGOLIA_INDEX_MEMORIES: ${{ vars.ALGOLIA_INDEX_MEMORIES}}
STORAGE_BASE_URL: ${{ vars.STORAGE_BASE_URL}}
DONATION_URL: ${{ vars.DONATION_URL}}
FEEDBACK_FORM_AUDIOS: ${{ vars.FEEDBACK_FORM_AUDIOS}}
FEEDBACK_FORM_MEMORIES: ${{ vars.FEEDBACK_FORM_MEMORIES }}
DIRECTUS_URL: ${{ vars.DIRECTUS_URL }}
DIRECTUS_STATIC_TOKEN: ${{ secrets.DIRECTUS_STATIC_TOKEN }}
# Deploying
- run: firebase deploy --only hosting --project $GCP_PROJECT_ID --force --non-interactive
# Inspired by https://superuser.com/a/943466 and https://stackoverflow.com/a/74998363
- name: Get site URL
run: |
set -o pipefail
firebase hosting:sites:list --json --project $GCP_PROJECT_ID |\
jq '.result.sites[] | select(.type == "DEFAULT_SITE") | .defaultUrl' --raw-output |\
(echo -n "channel-url=" && cat) >> $GITHUB_OUTPUT
id: get-site-url