-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (84 loc) · 3.64 KB
/
preview.yml
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
# Generate static site preview for production site
name: Preview Content
on:
workflow_dispatch:
push:
branches: feat/eu-west1-deployment
# Only keep one active build per ref (e.g. pr branch, push branch, triggering workflow ref)
concurrency:
group: preview-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Setup Node 18
uses: actions/setup-node@v3
with:
node-version: 18.x
#############################################################################
# Node Modules
# Manually restore any previous cache to speed install
# As immutable install will not change cache only save new cache if not hit
# Uses fine-grained methods from https://github.com/actions/cache
#############################################################################
- uses: actions/cache/restore@v3
id: cache
with:
path: ./.yarn/cache
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-yarn-v1-
- name: Install node modules
run: yarn install --immutable && npm i -g vercel
- uses: actions/cache/save@v3
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ./.yarn/cache
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
#############################################################################
# Gcloud Setup
# Populate service account credentials to file
# Authenticate to google servers
# Initialize gcloud cli
#############################################################################
- name: Setup Credentials
id: service-account
run: |
echo ${{secrets.GCP_SA_KEY_B64}} | base64 --decode > ./service-account.json
- name: GCP Auth
uses: "google-github-actions/auth@v2"
with:
project_id: "sami-website-365718"
credentials_json: ${{secrets.GCP_SA_KEY_B64}}
token_format: "access_token"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v2"
with:
version: ">= 363.0.0"
# TODO - refactor actions - 1 to create pr, then preview based on pr
#############################################################################
# Export production
#############################################################################
# Export production and rename to match dev configuration (production-local)
- name: Import production data locally
run: |
echo "STRAPI_READONLY_TOKEN=${{secrets.STRAPI_READONLY_TOKEN}}" > config/docker.local.env
yarn scripts strapi export --environment docker --ci
cp config/docker.local.env config/development.local.env
cp data/db/sami-production.db data/db/sami-dev.db
- name: Build
run: yarn scripts cli build --environment=development --no-export --no-preview --no-deploy
# HACK - split build-deploy above for easier debugging
- name: Deploy
run: |
cd frontend
vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
vercel build
vercel deploy --prebuilt
# NOTE - also possible to do without intermediate but requires interaction with live cloud-run api
# - name: Generate preview
# run: yarn scripts cli build --environment=docker --export --no-backend --no-preview --deploy