-
Notifications
You must be signed in to change notification settings - Fork 4
111 lines (98 loc) · 4.56 KB
/
deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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