-
Notifications
You must be signed in to change notification settings - Fork 227
253 lines (248 loc) · 10.8 KB
/
query-planner-ci.yaml
File metadata and controls
253 lines (248 loc) · 10.8 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
251
252
253
name: Query Planner CI
on:
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled
paths:
# This workflow should run every time router-ci and cli-ci runs
- 'pnpm-lock.yaml'
- 'cli/**/*'
- 'connect/**/*'
- '.github/workflows/cli-ci.yaml'
- 'router/**/*'
- 'connect/**/*'
- '.github/workflows/router-ci.yaml'
- '.github/workflows/query-planner-ci.yaml'
env:
CI: true
DO_NOT_TRACK: '1'
permissions:
pull-requests: write
contents: read
packages: write
concurrency:
group: ${{github.workflow}}-${{github.head_ref}}
cancel-in-progress: true
jobs:
check-labels-and-engine-changes:
runs-on: ubuntu-latest
outputs:
has_label: ${{ steps.check_label.outputs.has_label }}
has_skip_label: ${{ steps.check_label_skip.outputs.has_label }}
engine_changed: ${{ steps.check_engine_changes.outputs.engine_changed }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: router/go.mod
cache: true
- name: Check for query-planner label
id: check_label
uses: actions/github-script@v7
with:
script: |
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const hasLabel = labels.data.some(label => label.name === 'query-planner');
core.setOutput('has_label', hasLabel ? 'true' : 'false');
- name: Check for query-planner-skip label
id: check_label_skip
uses: actions/github-script@v7
with:
script: |
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const hasLabel = labels.data.some(label => label.name === 'query-planner-skip');
core.setOutput('has_label', hasLabel ? 'true' : 'false');
- name: Check for changes of engine
id: check_engine_changes
working-directory: router
run: |
current_engine_version=$(go list -f '{{.Version}}' -m github.com/wundergraph/graphql-go-tools/v2)
git show ${{ github.event.pull_request.base.sha }}:router/go.mod > base.go.mod
previous_engine_version=$(go list -f '{{.Version}}' -modfile base.go.mod -m github.com/wundergraph/graphql-go-tools/v2)
if [ "$current_engine_version" != "$previous_engine_version" ]; then
echo "engine_changed=true" >> $GITHUB_OUTPUT
echo "Engine has been changed from $previous_engine_version to $current_engine_version"
else
echo "engine_changed=false" >> $GITHUB_OUTPUT
echo "Engine has not been changed"
fi
filter-changes:
runs-on: ubuntu-latest
outputs:
router_changed: ${{ steps.filter.outputs.router }}
cli_changed: ${{ steps.filter.outputs.cli }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Filter Changes
id: filter
uses: dorny/paths-filter@v2
with:
filters: |
router:
- 'demo/**/*'
- 'router/**/*'
- 'router-tests/**/*'
- 'connect/**/*'
- '.github/workflows/router-ci.yaml'
cli:
- 'cli/**/*'
- 'connect/**/*'
- '.github/workflows/cli-ci.yaml'
build-router:
needs: [filter-changes, check-labels-and-engine-changes]
# This is a limitation of GitHub. Only organization members can push to GitHub Container Registry
# For now, we will disable the push to the GitHub Container Registry for external contributor
if: ${{ needs.filter-changes.outputs.router_changed == 'true' && github.event.pull_request.head.repo.full_name == github.repository && needs.check-labels-and-engine-changes.outputs.has_skip_label != 'true'}}
runs-on: ubuntu-latest
outputs:
image_ref: ${{ steps.build_push_image.outputs.image_ref }}
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build-push-image
id: build_push_image
with:
docker_username: ${{secrets.DOCKER_USERNAME}}
docker_password: ${{secrets.DOCKER_PASSWORD}}
docker_context: router
dockerfile: router/Dockerfile
token: ${{secrets.GITHUB_TOKEN}}
image_name: router-qp
image_description: 'Cosmo Router Query Planner'
image_platforms: linux/amd64
build-cli:
needs: [filter-changes, check-labels-and-engine-changes]
if: ${{ needs.filter-changes.outputs.cli_changed == 'true' && needs.check-labels-and-engine-changes.outputs.has_skip_label != 'true'}}
runs-on: ubuntu-latest
outputs:
wgc: ${{ steps.cli-build.outputs.artifact-url }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/cli-build
id: cli-build
with:
github-sha: ${{ github.sha }}
target: bun-linux-x64
cli-release-url:
needs: [filter-changes, check-labels-and-engine-changes]
runs-on: ubuntu-latest
if: ${{ needs.filter-changes.outputs.cli_changed != 'true' && needs.check-labels-and-engine-changes.outputs.has_skip_label != 'true'}}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- id: release-url
run: |
url=`gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/wundergraph/cosmo/releases --jq '.[] | select(.name | startswith("wgc@")) | .assets[] | select(.name | endswith("-bun-linux-x64.gz")) | .browser_download_url' | head -n 1`
echo "wgc=$url" >> $GITHUB_OUTPUT
outputs:
wgc: ${{ steps.release-url.outputs.wgc }}
build_test: # This job is use to lock the merge of the PR if anything fails in the query planner
runs-on: ubuntu-latest
if: ${{ always() }}
needs: [build-router, build-cli, cli-release-url, check-labels-and-engine-changes]
outputs:
workflow_url: ${{ steps.trigger_workflow.outputs.workflow_url }}
workflow_id: ${{ steps.trigger_workflow.outputs.workflow_id }}
steps:
- uses: convictional/trigger-workflow-and-wait@v1.6.5
if: ${{ (needs.check-labels-and-engine-changes.outputs.has_label == 'true' || needs.check-labels-and-engine-changes.outputs.engine_changed == 'true') && needs.check-labels-and-engine-changes.outputs.has_skip_label != 'true' }}
id: trigger_workflow
name: Trigger Query Planner CI
with:
owner: wundergraph
repo: cosmo-celestial
ref: master
github_token: ${{ secrets.GH_TOKEN_CELESTIAL_TRIGGER }}
propagate_failure: true
workflow_file_name: 'query-planner-tester.yaml'
client_payload: >-
{
"branch": "query-plan/pr-${{ github.event.pull_request.number }}",
"router": "${{ needs.build-router.outputs.image_ref || 'ghcr.io/wundergraph/cosmo/router:latest' }}",
"wgc": "${{ needs.build-cli.outputs.wgc || needs.cli-release-url.outputs.wgc }}"
}
get_pr_url:
needs: [build_test, check-labels-and-engine-changes]
runs-on: ubuntu-latest
if: ${{ always() && (needs.check-labels-and-engine-changes.outputs.has_label == 'true' || needs.check-labels-and-engine-changes.outputs.engine_changed == 'true') && needs.check-labels-and-engine-changes.outputs.has_skip_label != 'true' }}
outputs:
pullrequest_url: ${{ steps.get_url.outputs.pr_url }}
steps:
- name: Download PR info artifact
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN_CELESTIAL_TRIGGER }}
script: |
const fs = require('fs');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: 'wundergraph',
repo: 'cosmo-celestial',
run_id: '${{ needs.build_test.outputs.workflow_id }}'
});
const artifact = artifacts.data.artifacts.find(a => a.name === 'pull-request-info');
if (!artifact) {
throw new Error('Could not find pull-request-info artifact');
}
const download = await github.rest.actions.downloadArtifact({
owner: 'wundergraph',
repo: 'cosmo-celestial',
artifact_id: artifact.id,
archive_format: 'zip'
});
fs.writeFileSync('artifact.zip', Buffer.from(download.data));
- name: Unzip artifact
run: unzip artifact.zip
- name: Get PR URL
id: get_url
run: |
pr_url=$(cat pr-url.txt)
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
comment-on-failure:
needs: [build_test, get_pr_url, check-labels-and-engine-changes]
if: ${{ (needs.check-labels-and-engine-changes.outputs.has_label == 'true' || needs.check-labels-and-engine-changes.outputs.engine_changed == 'true') && needs.check-labels-and-engine-changes.outputs.has_skip_label != 'true' && failure() }}
runs-on: ubuntu-latest
steps:
- name: Comment PR on failure
if: ${{ needs.get_pr_url.outputs.pullrequest_url == '' }}
uses: mshick/add-pr-comment@v2
with:
message: |
❌ Internal Query Planner CI failed to run.
- name: Comment PR on failure
if: ${{ needs.get_pr_url.outputs.pullrequest_url != '' }}
uses: mshick/add-pr-comment@v2
with:
message: |
# ❌ Internal Query Planner CI checks failed
The Internal Query Planner CI checks failed in the celestial repository, and this is going to stop the merge of this PR.
If you are part of the WunderGraph organization, you can [see the PR with more details](${{ needs.get_pr_url.outputs.pullrequest_url }}).
comment-on-success:
needs: [build_test, get_pr_url, check-labels-and-engine-changes]
if: ${{ (needs.check-labels-and-engine-changes.outputs.has_label == 'true' || needs.check-labels-and-engine-changes.outputs.engine_changed == 'true') && needs.check-labels-and-engine-changes.outputs.has_skip_label != 'true' && success() }}
runs-on: ubuntu-latest
steps:
- name: Comment PR on failure
if: ${{ needs.get_pr_url.outputs.pullrequest_url != '' }}
uses: mshick/add-pr-comment@v2
with:
message: |
# ✅ Internal Query Planner CI checks passed
The Internal Query Planner CI checks passed in the celestial repository, and this is going to allow the merge of this PR.
If you are part of the WunderGraph organization, you can [see the PR with more details](${{ needs.get_pr_url.outputs.pullrequest_url }}).