-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathworkflows.dhall
219 lines (195 loc) · 5.99 KB
/
workflows.dhall
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
let Prelude = ./Prelude.dhall
let A = ./apps.dhall
let Map = Prelude.Map.Type
let default = Prelude.Text.default
let not = Prelude.Bool.not
let null = Prelude.Optional.null
let Env = < Staging | Production >
let App = A.App
let Step =
{ Type =
{ id : Optional Text
, name : Optional Text
, uses : Optional Text
, run : Optional Text
, `with` : Map Text Text
, env : Map Text Text
, shell : Optional Text
, continue-on-error : Optional Bool
}
, default =
{ id = None Text
, name = None Text
, uses = None Text
, run = None Text
, `with` = [] : Map Text Text
, env = [] : Map Text Text
, shell = None Text
, continue-on-error = None Bool
}
}
let setupSteps =
\(env : Env) ->
[ Step::{
, name = Some "Checkout repo"
, uses = Some "actions/checkout@v4"
}
, Step::{
, name = Some "Auth Cloud SDK"
, uses = Some "google-github-actions/auth@v2"
, `with` = toMap
{ project_id =
merge
{ Staging = "ksf-staging", Production = "ksf-production" }
env
, credentials_json =
merge
{ Staging = "\${{ secrets.GCP_PREVIEW_KEY }}"
, Production = "\${{ secrets.GCP_PRODUCTION_KEY }}"
}
env
, create_credentials_file = "true"
}
}
, Step::{
, name = Some "Setup Cloud SDK"
, uses = Some "google-github-actions/setup-gcloud@v2"
}
, Step::{
, run = Some
''
yarn install --pure-lockfile
mkdir -p build
''
}
]
let mkCacheAppStep =
\(app : App.Type) ->
let caches = default app.caches
let lockfile = default app.lockfile
in Step::{
, name = Some "Setup build cache for ${app.name}"
, uses = Some "actions/cache@v4"
, `with` = toMap
{ path = caches
, key =
"\${{ runner.os }}-${app.deployDir}-\${{ hashFiles('apps/${app.buildDir}/${lockfile}')}}"
}
}
let mkBuildStep =
\(app : App.Type) ->
Step::{
, name = Some "Build ${app.name}"
, env = app.env
, shell = Some "bash"
, run = Some
''
ruby deploy.rb ${app.buildDir}
cp -R apps/${app.buildDir}/dist build/${app.deployDir}
''
}
let mkUploadStep =
\(env : Env) ->
\(app : App.Type) ->
Step::{
, name = Some "Upload ${app.name}"
, uses = Some "google-github-actions/upload-cloud-storage@v2"
, `with` = toMap
{ path = "build/${app.deployDir}"
, destination =
merge
{ Staging =
"deploy-previews/\${{ github.sha }}/${app.deployDir}"
, Production = "ksf-frontends/${app.deployDir}"
}
env
, parent = "false"
}
}
let checkCISteps =
[ Step::{ name = Some "Checkout repo", uses = Some "actions/checkout@v4" }
, Step::{
, name = Some "Check CI script has been generated from Dhall"
, run = Some
''
git config --global --add safe.directory $(pwd)
chmod 666 .github/workflows/*
make
chmod 644 .github/workflows/*
git diff --exit-code
''
}
]
let linkPreviewsStep =
\(apps : List App.Type) ->
\(previewUrl : Text) ->
Step::{
, name = Some "Post preview links"
, uses = Some
"unsplash/comment-on-pr@ffe8f97ccc63ce12c3c23c6885b169db67958d3b"
, env = toMap { GITHUB_TOKEN = "\${{ secrets.GITHUB_TOKEN }}" }
, `with` = toMap
{ msg =
let renderAppLink =
\(app : App.Type) ->
"- [${app.name}](${previewUrl}/${app.deployDir}/index.html)"
in ''
Deploy previews are ready :sunglasses:
${Prelude.Text.concatMapSep
"\n"
App.Type
renderAppLink
apps}
''
, check_for_duplicate_msg = "false"
}
}
let refreshCDNSteps =
\(cdnName : Text) ->
[ Step::{
, name = Some "Auth Cloud SDK"
, uses = Some "google-github-actions/auth@v2"
, `with` = toMap
{ project_id = "ksf-production"
, credentials_json = "\${{ secrets.GCP_PRODUCTION_KEY }}"
, create_credentials_file = "true"
}
}
, Step::{
, name = Some "Install gcloud"
, uses = Some "google-github-actions/setup-gcloud@v2"
}
, Step::{
, name = Some "Invalidate CDN cache for '${cdnName}'"
, run = Some
''
gcloud compute url-maps invalidate-cdn-cache ${cdnName} --path "/*"
''
}
]
let refreshCDNJob =
\(cdnName : Text) ->
\(jobName : Text) ->
{ runs-on = "ubuntu-latest"
, steps = refreshCDNSteps cdnName
, needs = jobName
}
let uploadSteps =
\(env : Env) -> Prelude.List.map App.Type Step.Type (mkUploadStep env)
let buildSteps = Prelude.List.map App.Type Step.Type mkBuildStep
let cacheSteps = Prelude.List.map App.Type Step.Type mkCacheAppStep
let hasLockfile
: App.Type -> Bool
= \(a : App.Type) -> not (null Text a.lockfile)
in { Step
, Prelude
, Env
, setupSteps
, buildSteps
, uploadSteps
, checkCISteps
, linkPreviewsStep
, refreshCDNJob
, cacheSteps
, hasLockfile
}