Trigger on the test branch #224
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deployment | |
on: | |
push: | |
branches: | |
- production | |
- test | |
workflow_call: | |
inputs: | |
environment: | |
description: Environment to deploy to | |
required: true | |
default: ${{ github.event_name == 'pull_request' && 'preview' || github.ref_name }} | |
type: string | |
concurrency: | |
group: ${{ inputs.environment }}_deployment | |
cancel-in-progress: true | |
jobs: | |
deployment: | |
name: Deploy | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ inputs.environment }} | |
url: ${{ steps.deploy-production.outputs.url || steps.deploy-preview.outputs.url }} | |
steps: | |
- run: echo "Deployment environment is ${{ inputs.environment }}" && exit 1 | |
- 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 | |
- name: Download audio records from the Firebase RTDB | |
run: firebase database:get /audio/records --output $RUNNER_TEMP/audios.json --project ${{ vars.GCP_PROJECT_ID }} | |
- uses: algolia/setup-algolia-cli@v1.1.0 | |
# Mimicking 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 '.[]?' $RUNNER_TEMP/audios.json | 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: ${{ vars.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@v4 | |
- 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 build | |
name: Build frontend | |
working-directory: frontend | |
env: | |
AUDIOS_DATA_PATH: ${{ runner.temp }}/audios.json | |
ALGOLIA_APPLICATION_ID: ${{ vars.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 }} | |
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }} | |
- name: Deploy to production | |
run: | | |
firebase deploy --only hosting --project ${{ vars.GCP_PROJECT_ID }} --force --non-interactive | |
# Inspired by https://superuser.com/a/943466 and https://stackoverflow.com/a/74998363 | |
set -o pipefail # https://stackoverflow.com/a/19804002 | |
firebase hosting:sites:list --json --project $GCP_PROJECT_ID |\ | |
jq '.result.sites[] | select(.type == "DEFAULT_SITE") | .defaultUrl' --raw-output |\ | |
(echo -n "url=" && cat) >> $GITHUB_OUTPUT | |
id: deploy-production | |
if: ${{ inputs.environment == 'production' }} | |
- name: Deploy to a preview channel | |
run: | | |
set -o pipefail # https://stackoverflow.com/a/19804002 | |
firebase hosting:channel:deploy ${{ github.head_ref }} --json --project ${{ vars.GCP_PROJECT_ID }} |\ | |
jq '.result."${{ vars.GCP_PROJECT_ID }}".url' --raw-output |\ | |
(echo -n "url=" && cat) >> $GITHUB_OUTPUT | |
id: deploy-preview | |
if: ${{ inputs.environment != 'production' }} | |
- name: Create a tag | |
# Adding tag only if a new version is deployed | |
if: ${{ github.event_name == 'push' }} | |
continue-on-error: true | |
run: | | |
git tag -f $(date +'%Y-%m-%d') | |
git push -f origin --tags |