-
Notifications
You must be signed in to change notification settings - Fork 6
105 lines (96 loc) · 3.38 KB
/
deploy-step.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
on:
workflow_call:
inputs:
CREATE_REVIEW_PATH:
required: true
type: string
environment:
required: true
type: string
GCP_PROJECT_ID:
required: true
type: string
GCP_WORKLOAD_IDENTITY_PROVIDER:
required: true
type: string
GCP_SERVICE_ACCOUNT:
required: true
type: string
GH_APP_ID:
required: true
type: string
SUBSCRIPTION_NAME:
required: true
type: string
TOPIC_NAME:
required: true
type: string
WEBHOOK_PATH:
required: true
type: string
secrets:
GH_PRIVATE_KEY:
required: true
GH_WEBHOOK_SECRET:
required: true
CHAT_GPT_API_KEY:
required: true
jobs:
provision:
name: 'Provision and deploy'
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: write
steps:
- uses: actions/checkout@v4
- name: 'Authenticate with GCP'
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ inputs.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ inputs.GCP_SERVICE_ACCOUNT }}
- name: 'Set up Cloud SDK'
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ inputs.GCP_PROJECT_ID }}
- name: Update secrets in GCP Secret Manager
uses: nearform-actions/github-action-gcp-secrets@v1
with:
secrets: |-
gh-private-key-${{ inputs.environment }}:"${{ secrets.GH_PRIVATE_KEY }}"
gh-webhook-secret-${{ inputs.environment }}:"${{ secrets.GH_WEBHOOK_SECRET }}"
chat-gpt-api-key-${{ inputs.environment }}:"${{ secrets.CHAT_GPT_API_KEY }}"
- name: 'Deploy webhook to Cloud Run'
id: deploy-webhook
run: >-
gcloud functions deploy ${{ inputs.WEBHOOK_PATH }}
--runtime=nodejs20
--source=.
--entry-point=webhook
--set-secrets=PRIVATE_KEY=projects/${{ inputs.GCP_PROJECT_ID }}/secrets/gh-private-key-${{ inputs.environment }}:latest
--set-secrets=WEBHOOK_SECRET=projects/${{ inputs.GCP_PROJECT_ID }}/secrets/gh-webhook-secret-${{ inputs.environment }}:latest
--set-env-vars=APP_ID="${{ inputs.GH_APP_ID }}"
--set-env-vars=PROJECT_ID="${{ inputs.GCP_PROJECT_ID }}"
--set-env-vars=TOPIC_NAME="${{ inputs.TOPIC_NAME }}"
--trigger-http
--allow-unauthenticated
--region=us-central1
--gen2
- name: 'Deploy createReview to Cloud Run'
id: deploy-createReview
run: >-
gcloud functions deploy ${{ inputs.CREATE_REVIEW_PATH }}
--runtime=nodejs20
--source=.
--entry-point=createReview
--set-secrets=PRIVATE_KEY=projects/${{ inputs.GCP_PROJECT_ID }}/secrets/gh-private-key-${{ inputs.environment }}:latest
--set-secrets=CHAT_GPT_API_KEY=projects/${{ inputs.GCP_PROJECT_ID }}/secrets/chat-gpt-api-key-${{ inputs.environment }}:latest
--set-env-vars=APP_ID="${{ inputs.GH_APP_ID }}"
--set-env-vars=SUBSCRIPTION_NAME="${{ inputs.SUBSCRIPTION_NAME }}"
--trigger-topic="${{ inputs.TOPIC_NAME }}"
--allow-unauthenticated
--region=us-central1
--gen2
- name: 'Show summary'
run: >-
echo "App successfully deployed."