-
Notifications
You must be signed in to change notification settings - Fork 1
210 lines (193 loc) · 7.63 KB
/
cypress.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
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
name: cypress
on:
pull_request:
branches: [ main ]
paths: [ "apps/admin-panel/**" ]
push:
branches: [ main ]
paths: [ "apps/admin-panel/**" ]
workflow_dispatch:
jobs:
cypress-test-run-in-browserstack:
name: browserstack / local tunnel into tilt up
runs-on: ubuntu-latest
steps:
- uses: docker/login-action@v3
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}
- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v8
- uses: actions/checkout@v4
- uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
- name: build backend
run: nix develop -c make build-for-tests
- name: sync dataform-branch
run: nix develop -c make push-dataform-branch
env:
DATAFORM_BRANCH: "gha-dataform"
- name: keep tilt running
run: nix develop -c make tilt-in-ci
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
TF_VAR_sa_creds: ${{ secrets.GOOGLE_SA_BASE64 }}
SA_CREDS_BASE64: ${{ secrets.GOOGLE_SA_BASE64 }}
SUMSUB_KEY: ${{ secrets.SUMSUB_KEY }}
SUMSUB_SECRET: ${{ secrets.SUMSUB_SECRET }}
TF_VAR_name_prefix: "gha"
- name: system info
run: |
free -h
df -h
- name: run cypress tests
run: nix develop -c make test-cypress-in-ci-through-browserstack
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
- name: upload cypress screenshots
uses: actions/upload-artifact@v4
with:
name: screenshots
path: apps/admin-panel/cypress/manuals/screenshots/*
manual-generation:
name: manual pdfs / upload to lana-manuals
needs: cypress-test-run-in-browserstack
runs-on: ubuntu-latest
steps:
- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v8
- uses: actions/checkout@v4
- run: mkdir -p apps/admin-panel/cypress/manuals/screenshots
- uses: actions/download-artifact@v4
with:
name: screenshots
path: apps/admin-panel/cypress/manuals/screenshots
- name: generate pdfs
run: cd apps/admin-panel && nix develop -c pnpm run local:pdf
- run: ls -R apps/admin-panel/cypress/manuals
- uses: actions/upload-artifact@v4
with:
name: pdfs
path: apps/admin-panel/cypress/manuals/results/*
- name: generate manual page
run: |
cd apps/admin-panel/cypress/manuals/results
cat <<EOF > index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lana Bank Manuals</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 font-sans">
<div class="max-w-5xl mx-auto mt-10 p-5">
<h1 class="text-3xl font-bold text-center text-gray-800 mb-6">
Lana Bank - Manuals for Regulators
</h1>
<div class="overflow-x-auto">
<table class="w-full border-collapse bg-white shadow-md rounded-lg">
<thead>
<tr class="bg-gray-800 text-white">
<th class="py-3 px-5 text-left">#</th>
<th class="py-3 px-5 text-left">Manual Name</th>
<th class="py-3 px-5 text-left">View</th>
</tr>
</thead>
<tbody>
EOF
COUNTER=1
for pdf in *.pdf; do
echo "<tr class='hover:bg-gray-50 border-b'>
<td class='py-3 px-5'>$COUNTER</td>
<td class='py-3 px-5'>${pdf%.pdf}</td>
<td class='py-3 px-5'>
<a href='$pdf' class='text-blue-600 hover:underline' target='_blank'>Open</a>
</td>
</tr>" >> index.html
((COUNTER++))
done
cat <<EOF >> index.html
</tbody>
</table>
</div>
</div>
</body>
</html>
EOF
- name: Install Netlify CLI
run: npm install -g netlify-cli
- name: Deploy to Netlify (Pull Request)
id: netlify_deploy
if: github.event_name == 'pull_request'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: 61296920-bd52-43a3-9253-78db17a78d9c
run: |
GITHUB_SHA="${{ github.sha }}"
SHORT_SHA="${GITHUB_SHA::7}"
ALIAS="pr-${{ github.event.pull_request.number }}-commit-${SHORT_SHA}"
netlify deploy \
--dir=apps/admin-panel/cypress/manuals/results \
--site=$NETLIFY_SITE_ID \
--auth=$NETLIFY_AUTH_TOKEN \
--alias="$ALIAS" \
--message="Manuals Preview for PR #${{ github.event.pull_request.number }} Commit $GITHUB_SHA" \
--json > deploy-info.json
DEPLOY_URL=$(jq -r '.deploy_url' deploy-info.json)
echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
- name: Deploy to Netlify (Push to Main)
if: github.event_name == 'push'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: 61296920-bd52-43a3-9253-78db17a78d9c
run: |
netlify deploy \
--prod \
--dir=apps/admin-panel/cypress/manuals/results \
--site=$NETLIFY_SITE_ID \
--auth=$NETLIFY_AUTH_TOKEN \
--message="Manuals Build for Commit ${{ github.sha }}" \
--json > deploy-info.json
DEPLOY_URL=$(jq -r '.deploy_url' deploy-info.json)
echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
- name: Create or Update Preview Comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const prNumber = context.payload.pull_request.number;
const deployUrl = '${{ steps.netlify_deploy.outputs.deploy_url }}';
const commentBody = `<!-- Manuals Preview Comment -->\nManuals preview: [Link to Manuals](${deployUrl})`;
// Fetch existing comments on the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
// Identify if the bot has already made a comment
const botLogin = 'github-actions[bot]'
const existingComment = comments.find(
comment => comment.user.login === botLogin && comment.body.includes('<!-- Manuals Preview Comment -->')
);
if (existingComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody,
});
}