Repository navigation
250 lines (243 loc) · 11 KB
/
Copy pathci.yml
File metadata and controls
250 lines (243 loc) · 11 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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: ci
on:
push:
pull_request:
# A new prisma release can break the action without any change here, so the
# newest CLIs are checked on a schedule too. Failures go to Slack.
schedule:
- cron: "17 */6 * * *"
workflow_dispatch:
repository_dispatch:
types: [prisma-released]
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
# Match runs.using in action.yml.
node-version: 24
- name: Syntax-check the action scripts
# node --check reads only its first argument, so one invocation per file.
run: |
node --check main.mjs
node --check post.mjs
node --check credentials.mjs
- name: Unit-test the action scripts
run: node --test tests/*.test.mjs
- name: Sanity-check action.yml
run: |
node -e '
const { readFileSync, existsSync } = require("node:fs");
const src = readFileSync("action.yml", "utf8");
const checks = [
["name: Deploy to Prisma Cloud", /^name: Deploy to Prisma Cloud$/m],
["runs.using: node24", /^ using: node24$/m],
["runs.main: main.mjs", /^ main: main\.mjs$/m],
["runs.post: post.mjs", /^ post: post\.mjs$/m],
];
for (const name of ["build-command", "install-command", "module", "mode", "environment", "stage", "prisma-version", "working-directory", "api-url"]) {
checks.push([`input ${name}`, new RegExp(`^ ${name}:$`, "m")]);
}
for (const name of ["outcome", "build-id", "url", "urls"]) {
checks.push([`output ${name}`, new RegExp(`^ ${name}:$`, "m")]);
}
const missing = checks.filter(([, re]) => !re.test(src)).map(([what]) => what);
for (const file of ["main.mjs", "post.mjs"]) {
if (!existsSync(file)) missing.push(`referenced file ${file}`);
}
if (missing.length > 0) {
console.error(`action.yml sanity check failed, missing: ${missing.join(", ")}`);
process.exit(1);
}
console.log("action.yml sanity check passed");
'
prisma-cli:
name: prisma ${{ matrix.prisma }} accepts the action's arguments
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# rc.29 is the last CLI that takes --stage. latest is an npm dist-tag,
# so a scheduled run tests each new release.
prisma: [8.0.0-rc.29, 8.0.0-rc.33, latest]
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
- name: Install prisma@${{ matrix.prisma }}
run: npm install --prefix "$RUNNER_TEMP/prisma" --no-save --no-package-lock "prisma@${{ matrix.prisma }}"
- name: Run the action's arguments against the CLI
env:
PRISMA_CLI_BINS: ${{ runner.temp }}/prisma/node_modules/.bin/prisma
run: node --test tests/prisma-cli.test.mjs
e2e:
name: The action deploys a real app with prisma ${{ matrix.prisma }}
# Pull requests from forks get no secrets. Branch pushes are covered by
# their pull request.
if: >-
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
(github.event_name != 'push' || github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
# pinned is the version in e2e/app's lockfile; latest moves the app to
# prisma@latest and the Composer version it bundles.
prisma: [pinned, latest]
permissions:
contents: read
# The sweep reads whether the run that made an environment has finished.
actions: read
env:
ENVIRONMENT: e2e-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.prisma }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
- name: Move the app to prisma@latest and its Composer version
if: matrix.prisma == 'latest'
working-directory: e2e/app
run: |
prisma=$(npm view prisma@latest version)
composer=$(npm view "prisma@$prisma" dependencies.@prisma/composer-cli)
echo "prisma $prisma, Composer $composer"
exact='^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'
if ! [[ $prisma =~ $exact && $composer =~ $exact ]]; then
echo "::error::could not resolve exact versions from npm: prisma \"$prisma\", Composer \"$composer\""
exit 1
fi
npm pkg set "devDependencies.prisma=$prisma" "dependencies.@prisma/composer=$composer" "dependencies.@prisma/composer-prisma-cloud=$composer"
bun install
- name: Deploy with the action
id: deploy
uses: ./
timeout-minutes: 15
env:
PRISMA_SERVICE_TOKEN: ${{ secrets.PRISMA_SERVICE_TOKEN }}
with:
working-directory: e2e/app
build-command: bun run build
environment: ${{ env.ENVIRONMENT }}
- name: Check the action's outputs and the deployed service
env:
OUTCOME: ${{ steps.deploy.outputs.outcome }}
URL: ${{ steps.deploy.outputs.url }}
URLS: ${{ steps.deploy.outputs.urls }}
REPORT_PATH: ${{ steps.deploy.outputs.report-path }}
timeout-minutes: 5
run: node e2e/verify.mjs
- name: Destroy the environment
if: always() && steps.deploy.outcome != 'skipped' && steps.deploy.outputs.outcome != 'skipped-no-credential'
working-directory: e2e/app
timeout-minutes: 10
env:
PRISMA_SERVICE_TOKEN: ${{ secrets.PRISMA_SERVICE_TOKEN }}
PRISMA_WORKSPACE_ID: ${{ secrets.PRISMA_WORKSPACE_ID }}
run: bun scripts/destroy.ts
- name: Destroy environments earlier runs left behind
if: always() && steps.deploy.outcome != 'skipped' && steps.deploy.outputs.outcome != 'skipped-no-credential'
working-directory: e2e/app
timeout-minutes: 10
env:
PRISMA_SERVICE_TOKEN: ${{ secrets.PRISMA_SERVICE_TOKEN }}
PRISMA_WORKSPACE_ID: ${{ secrets.PRISMA_WORKSPACE_ID }}
GITHUB_TOKEN: ${{ github.token }}
run: bun scripts/sweep.ts
e2e-single-app:
name: The action deploys a repository with no Composer module, ${{ matrix.name }}
if: >-
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
(github.event_name != 'push' || github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- name: and no config file
app: single-app
id: plain
# The action installs first, then runs the app's own prisma from its lockfile.
- name: with a prisma.config.ts
app: single-app-config
id: config
permissions:
contents: read
# The sweep reads whether the run that made a Project has finished.
actions: read
env:
# The action cannot destroy a deploy with no Composer module, so each run
# deploys into a Project of its own and deletes that Project afterwards.
PROJECT: cloud-deploy-action-e2e-single-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.id }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
# No Bun: the action runs the CLI under Node.js in this mode.
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
- name: Give the app a body only this run has
run: printf '{"project":"%s"}' "$PROJECT" > "e2e/${{ matrix.app }}/run.json"
# No environment input: a pull request run deploys to an environment named
# after its branch, and a run on main deploys to production.
- name: Deploy with the action
id: deploy
uses: ./
timeout-minutes: 15
env:
PRISMA_SERVICE_TOKEN: ${{ secrets.PRISMA_SERVICE_TOKEN }}
# The deploy creates the Project, which needs a region. Same as e2e/app.
PRISMA_REGION: us-east-1
with:
working-directory: e2e/${{ matrix.app }}
name: ${{ env.PROJECT }}
- name: Check the action's outputs and the deployed service
env:
OUTCOME: ${{ steps.deploy.outputs.outcome }}
URL: ${{ steps.deploy.outputs.url }}
URLS: ${{ steps.deploy.outputs.urls }}
REPORT_PATH: ${{ steps.deploy.outputs.report-path }}
EXPECTED_BODY: '{"project":"${{ env.PROJECT }}"}'
timeout-minutes: 5
run: node e2e/verify.mjs
- name: Delete the Project, and Projects earlier runs left behind
if: always() && steps.deploy.outcome != 'skipped' && steps.deploy.outputs.outcome != 'skipped-no-credential'
timeout-minutes: 10
env:
PRISMA_SERVICE_TOKEN: ${{ secrets.PRISMA_SERVICE_TOKEN }}
PRISMA_WORKSPACE_ID: ${{ secrets.PRISMA_WORKSPACE_ID }}
GITHUB_TOKEN: ${{ github.token }}
run: node e2e/single-app-cleanup.mjs
report-failure:
name: Report a failure on main, a scheduled, manual or prisma-released run to Slack
needs: [check, prisma-cli, e2e, e2e-single-app]
# failure() misses a needed job that was cancelled or lost its runner.
if: >-
always() &&
(contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) &&
github.event_name != 'pull_request' &&
(github.event_name != 'push' || github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
steps:
- name: Post to Slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
TEXT: >-
:rotating_light: prisma/cloud-deploy-action CI failed on a ${{ github.event_name }} run of ${{ github.ref_name }}
(check: ${{ needs.check.result }}, prisma CLI arguments: ${{ needs.prisma-cli.result }}, end-to-end deploy: ${{ needs.e2e.result }}, end-to-end deploy with no Composer module: ${{ needs.e2e-single-app.result }}).
Deploys that use the action may be broken.
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ -z "$SLACK_WEBHOOK_URL" ]; then
echo "::error::the SLACK_WEBHOOK_URL secret is not set, so this failure was not reported"
exit 1
fi
jq -n --arg text "$TEXT" '{text: $text}' |
curl --fail-with-body --silent --show-error -X POST -H 'Content-Type: application/json' --data @- "$SLACK_WEBHOOK_URL"