-
Notifications
You must be signed in to change notification settings - Fork 2
93 lines (79 loc) · 3.24 KB
/
Copy pathdeploy.yml
File metadata and controls
93 lines (79 loc) · 3.24 KB
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
name: Deploy
on:
workflow_run:
# Gate on CI passing — this workflow only fires after lint/typecheck/format/test succeeds
workflows: ["Lint/Typecheck/Format/Test"]
types: [completed]
# Only watch these branches — PRs from feature branches don't trigger this
branches: [develop, main]
# Required for google-github-actions/auth to request an OIDC token from GitHub
permissions:
id-token: write
contents: read
jobs:
deploy-dev:
# Three conditions must all be true:
# 1. CI passed (not cancelled or failed)
# 2. This was a push (merge), not a PR CI run
# 3. The push was to develop specifically
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'develop'
runs-on: ubuntu-latest
# Scopes WIF_PROVIDER and WIF_SERVICE_ACCOUNT vars to the dev environment
environment: dev
steps:
# Check out the exact commit that triggered CI — not just the branch HEAD
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "npm"
- name: Install dependencies
run: npm ci
# Exchange GitHub's OIDC token for a short-lived GCP access token
# via Workload Identity Federation. Sets GOOGLE_APPLICATION_CREDENTIALS.
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
workload_identity_provider: ${{ vars.WIF_PROVIDER }}
service_account: ${{ vars.WIF_SERVICE_ACCOUNT }}
# Build + copy .clasp.dev.json + push using ADC credentials from the step above.
# Note: the existing deploy:dev npm script calls clasp push without --adc,
# so we inline the commands here instead.
- name: Deploy to dev
run: npm run build && cp .clasp.dev.json .clasp.json && npx clasp push --adc
deploy-prod:
# Same gate logic, but only fires on pushes to main
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'main'
runs-on: ubuntu-latest
environment: prod
steps:
# Check out the exact commit that triggered CI — not just the branch HEAD
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "npm"
- name: Install dependencies
run: npm ci
# Exchange GitHub's OIDC token for a short-lived GCP access token
# via Workload Identity Federation. Sets GOOGLE_APPLICATION_CREDENTIALS.
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
workload_identity_provider: ${{ vars.WIF_PROVIDER }}
service_account: ${{ vars.WIF_SERVICE_ACCOUNT }}
# Build + copy .clasp.prod.json + push using ADC credentials from the step above.
- name: Deploy to prod
run: npm run build && cp .clasp.prod.json .clasp.json && npx clasp push --adc