-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (135 loc) · 4.5 KB
/
ci.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: CI
on:
push:
workflow_dispatch:
env:
GCLOUD_VERSION: 351.0.0
IMAGE: gh-app-api
GH_APP_REDIRECT_URI: 'https://gh-app.acot.dev/auth/callback'
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version-file: '.node-version'
cache: 'yarn'
- run: yarn --immutable
- name: 'Setup web config'
working-directory: packages/web
run: |
echo "VITE_API_URL=https://gh-app-api.acot.dev/" >> .env
echo "VITE_GH_APP_CLIENT_ID=${{ secrets.GH_APP_CLIENT_ID }}" >> .env
echo "VITE_GH_APP_REDIRECT_URI=${{ env.GH_APP_REDIRECT_URI }}" >> .env
- run: yarn build
- uses: actions/upload-artifact@v2
with:
name: build
retention-days: 1
path: |
packages/web/dist
*/*/lib
!node_modules
test:
runs-on: ubuntu-20.04
needs: [build]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version-file: '.node-version'
cache: 'yarn'
- uses: actions/download-artifact@v2
with:
name: build
- run: yarn --immutable
- run: yarn test
lint:
runs-on: ubuntu-20.04
needs: [build]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version-file: '.node-version'
cache: 'yarn'
- uses: actions/download-artifact@v2
with:
name: build
- run: yarn --immutable
- run: yarn lint
- run: git diff --exit-code || exit 1
pass:
runs-on: ubuntu-20.04
needs: [build, test, lint]
steps:
- run: exit 0
deploy_api:
runs-on: ubuntu-20.04
needs: [pass]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@v0.3.0
with:
version: ${{ env.GCLOUD_VERSION }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
export_default_credentials: true
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ github.ref }}-${{ github.sha }}
restore-keys: |
${{ github.ref }}-${{ github.sha }}
${{ github.ref }}
refs/head/main
- name: Configure gcloud
run: gcloud auth configure-docker
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Publish Docker image
uses: docker/build-push-action@v2
with:
push: true
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ secrets.GCP_HOSTNAME }}/${{ secrets.GCP_PROJECT_ID }}/${{ env.IMAGE }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Deploy Docker image to Cloud Run
run: |
gcloud run deploy ${IMAGE} \
--image ${{ secrets.GCP_HOSTNAME }}/${{ secrets.GCP_PROJECT_ID }}/${IMAGE}:latest \
--region ${{ secrets.GCP_REGION }} \
--max-instances 10 \
--memory "2Gi" \
--service-account ${{ secrets.GCP_CLOUD_RUN_SERVICE_ACCOUNT }} \
--set-env-vars "GCP_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}" \
--set-env-vars "APP_TOKEN_KEY=${{ secrets.APP_TOKEN_KEY }}" \
--set-env-vars "GH_APP_ID=${{ secrets.GH_APP_ID }}" \
--set-env-vars "GH_APP_CLIENT_ID=${{ secrets.GH_APP_CLIENT_ID }}" \
--set-env-vars "GH_APP_CLIENT_SECRET=${{ secrets.GH_APP_CLIENT_SECRET }}" \
--set-env-vars "GH_APP_REDIRECT_URI=${{ env.GH_APP_REDIRECT_URI }}" \
--set-env-vars "GH_APP_PEM=${{ secrets.GH_APP_PEM }}" \
--allow-unauthenticated \
deploy_web:
runs-on: ubuntu-20.04
needs: [pass]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@v0.3.0
with:
version: ${{ env.GCLOUD_VERSION }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
export_default_credentials: true
- uses: actions/download-artifact@v2
with:
name: build
- name: Deploy
working-directory: packages/web
run: gcloud app deploy app.yaml