forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (160 loc) · 6.64 KB
/
test.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
name: CI
# Run on `push` only for main, if not it will trigger `push` & `pull_request` on PRs at the same time
on:
push:
branches:
- main
- '*.*.x'
paths-ignore:
# Any update here needs to be done for `pull_request`, see below
# and all files (test.yml, benchmark.yml, release-ci.yml, bundle-size.yml)
- '*.md'
- '*.bench.ts'
- 'LICENSE'
- '.dockerignore'
- 'scripts/ci/publish.ts'
- '.github/CODEOWNERS'
- '.github/renovate.json'
- '.github/ISSUE_TEMPLATE/**'
- '.github/DISCUSSION_TEMPLATE/**'
- '.devcontainer/**'
- '.vscode/**'
- 'graphs/**'
- 'sandbox/**'
pull_request:
paths-ignore:
# Any update here needs to be done for `push`, see above
# and all files (test.yml, benchmark.yml, release-ci.yml)
- '*.md'
- '*.bench.ts'
- 'LICENSE'
- '.dockerignore'
- 'scripts/ci/publish.ts'
- '.github/CODEOWNERS'
- '.github/renovate.json'
- '.github/ISSUE_TEMPLATE/**'
- '.github/DISCUSSION_TEMPLATE/**'
- '.devcontainer/**'
- '.vscode/**'
- 'graphs/**'
- 'sandbox/**'
workflow_dispatch:
jobs:
detect_jobs_to_run:
name: Detect jobs to run
runs-on: ubuntu-latest
outputs:
jobs: ${{ steps.detect.outputs.jobs }}
queryEngine: ${{ steps.enginesOutput.outputs.queryEngine }}
steps:
- uses: actions/checkout@v4
- id: files
uses: Ana06/[email protected] # it's a fork of jitterbit/get-changed-files@v1 which works better with pull requests
with:
format: 'json'
- id: detect
run: ./.github/workflows/scripts/detect-jobs-to-run.js <<< '${{ steps.files.outputs.all }}'
- name: Debug Pull Request Event
if: ${{ github.event_name == 'pull_request' }}
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
echo "Pull Request: ${{ github.event.pull_request.number }}"
echo "Pull Request Author: ${{ github.event.pull_request.user.login }}"
echo "Pull Request Author Association: ${{ github.event.pull_request.author_association }}"
echo "Pull Request Body contains /integration: ${{ contains(env.PR_BODY, '/integration') }}"
- name: Find "ci test all" comment
uses: peter-evans/find-comment@v3
id: findTestAllComment
if: ${{ github.event_name == 'pull_request' }}
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: 'ci test all'
- id: enginesOutput
name: Decide on which engine types to run the next workflow
run: |
if [ -z "${{ steps.findTestAllComment.outputs.comment-id }}" ]; then
echo 'queryEngine=["library"]' >> "$GITHUB_OUTPUT"
else
echo 'queryEngine=["library","binary"]' >> "$GITHUB_OUTPUT"
fi
- name: Trigger npm release workflow for integration release
env:
PR_BODY: ${{ github.event.pull_request.body }}
# See https://docs.github.com/en/graphql/reference/enums
# https://michaelheap.com/github-actions-check-permission/
# Check if
# - the PR body contains `/integration`
# - the PR author has permissions to trigger the workflow (must be part of the org or a collaborator)
if: |
github.event_name == 'pull_request' &&
contains(env.PR_BODY, '/integration') &&
(
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'CONTRIBUTOR'
)
uses: benc-uk/workflow-dispatch@v1
with:
workflow: release-ci.yml
token: ${{ secrets.BOT_TOKEN }}
inputs: '{ "forceIntegrationRelease": "true" }'
ref: ${{ github.event.pull_request.head.ref }}
build_custom_engine:
name: Build custom engine
needs: detect_jobs_to_run
uses: ./.github/workflows/build-engine-branch.yml
check_custom_engine:
name: Block merge if custom engine is used
needs: build_custom_engine
runs-on: ubuntu-latest
steps:
- name: Find past custom engine comment
uses: peter-evans/find-comment@v3
id: findEngineComment
if: ${{ github.event_name == 'pull_request' }}
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: '<!-- custom-engine -->'
- name: Create or update comment (block)
uses: peter-evans/create-or-update-comment@v4
if: ${{ needs.build_custom_engine.outputs.engineHash != '' }}
with:
comment-id: ${{ steps.findEngineComment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- custom-engine -->
🔴 **CUSTOM ENGINE IS USED**
This PR is using custom engine:
Branch: [`${{ needs.build_custom_engine.outputs.branchName }}`](https://github.com/prisma/prisma-engines/tree/${{ needs.build_custom_engine.outputs.branchName }})
Commit: [`${{ needs.build_custom_engine.outputs.engineHash }}`](https://github.com/prisma/prisma-engines/commit/${{ needs.build_custom_engine.outputs.engineHash }}).
Don't forget to remove `/engine-branch` command from PR body and re-run the tests with default engine before merging.
edit-mode: replace
- name: Create or update comment (clear)
uses: peter-evans/create-or-update-comment@v4
if: ${{ steps.findEngineComment.outputs.comment-id != '' && needs.build_custom_engine.outputs.engineHash == '' }}
with:
comment-id: ${{ steps.findEngineComment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- custom-engine -->
🟢 All good, this PR is no longer uses custom engine.
edit-mode: replace
- name: Block merge
if: ${{ needs.build_custom_engine.outputs.engineHash != '' }}
run: |
echo "Custom engine is used, failing the job"
echo "Don't forget to remove /engine-branch command from PR body before merge"
exit 1
run_tests:
name: Tests
needs:
- detect_jobs_to_run
- build_custom_engine
uses: ./.github/workflows/test-template.yml
with:
jobsToRun: ${{ needs.detect_jobs_to_run.outputs.jobs }}
queryEngine: ${{ needs.detect_jobs_to_run.outputs.queryEngine }}
engineHash: ${{ needs.build_custom_engine.outputs.engineHash }}
secrets: inherit