-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f426901
commit 298a154
Showing
19 changed files
with
453 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.github/helm/affine/charts/graphql/templates/copilot-test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{{ if .Values.app.copilot.enabled }} | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
name: {{ include "graphql.fullname" . }}-copilot-test | ||
labels: | ||
{{- include "graphql.labels" . | nindent 4 }} | ||
annotations: | ||
"helm.sh/hook": post-install,post-upgrade | ||
"helm.sh/hook-weight": "1" | ||
"helm.sh/hook-delete-policy": before-hook-creation | ||
spec: | ||
schedule: "0 8 * * *" | ||
jobTemplate: | ||
spec: | ||
template: | ||
spec: | ||
serviceAccountName: {{ include "graphql.serviceAccountName" . }} | ||
containers: | ||
- name: {{ .Chart.Name }} | ||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||
command: ["yarn", "test:copilot:e2e:cron"] | ||
env: | ||
- name: AFFINE_ENV | ||
value: "{{ .Release.Namespace }}" | ||
- name: SLACK_BOT_TOKEN | ||
valueFrom: | ||
secretKeyRef: | ||
name: "{{ .Values.app.copilot.secretName }}" | ||
key: slackBotToken | ||
- name: CHANNEL_ID | ||
valueFrom: | ||
secretKeyRef: | ||
name: "{{ .Values.app.copilot.secretName }}" | ||
key: slackChannelId | ||
- name: COPILOT_E2E_ENDPOINT | ||
value: "http://{{ include "graphql.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:3000" | ||
- name: DATABASE_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: pg-postgresql | ||
key: postgres-password | ||
- name: DATABASE_URL | ||
value: postgres://{{ .Values.global.database.user }}:$(DATABASE_PASSWORD)@{{ .Values.global.database.url }}:{{ .Values.global.database.port }}/{{ .Values.global.database.name }} | ||
- name: COPILOT_OPENAI_API_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: "{{ .Values.app.copilot.secretName }}" | ||
key: openaiSecret | ||
- name: COPILOT_FAL_API_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: "{{ .Values.app.copilot.secretName }}" | ||
key: falSecret | ||
- name: COPILOT_UNSPLASH_API_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: "{{ .Values.app.copilot.secretName }}" | ||
key: unsplashSecret | ||
resources: | ||
requests: | ||
cpu: '100m' | ||
memory: '200Mi' | ||
restartPolicy: Never | ||
backoffLimit: 1 | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// start process | ||
|
||
import { spawn } from 'node:child_process'; | ||
|
||
import { WebClient } from '@slack/web-api'; | ||
import { jsxslack } from 'jsx-slack'; | ||
import { marked, Renderer } from 'marked'; | ||
import { Parser } from 'tap-parser'; | ||
|
||
async function runTest() { | ||
const tester = new Promise(resolve => { | ||
const test = spawn( | ||
'npx', | ||
[ | ||
'ava', | ||
'--config', | ||
'tests/ava.docker.config.js', | ||
'tests/**/copilot-*.e2e.ts', | ||
'--tap', | ||
], | ||
{ env: { ...process.env, NODE_NO_WARNINGS: 1 } } | ||
); | ||
|
||
const parser = new Parser(); | ||
test.stdout.on('data', data => { | ||
console.log(data.toString()); | ||
parser.write(data); | ||
}); | ||
|
||
test.on('close', _ => { | ||
const failures = parser?.failures.filter(f => !!f.fullname); | ||
const timeouts = parser?.failures.filter(f => !f.fullname); | ||
const result = [ | ||
`${parser.results.pass} passed`, | ||
`${parser.results.fail - timeouts.length} failed`, | ||
`${timeouts.length} timeouts`, | ||
`${parser.results.skip} skipped`, | ||
]; | ||
const report = [ | ||
`Test finished with ${result.join(', ')}.`, | ||
failures?.length > 0 | ||
? `Failed tests: \n\n${failures.map(failure => `- ${failure.fullname}`).join('\n')}` | ||
: '', | ||
]; | ||
resolve(report.join('\n\n')); | ||
}); | ||
}); | ||
|
||
try { | ||
return await tester; | ||
} catch (e) { | ||
return e.message; | ||
} | ||
} | ||
|
||
function render(markdown) { | ||
const rendered = marked(markdown, { | ||
renderer: new (class CustomRenderer extends Renderer { | ||
heading({ tokens }) { | ||
return ` | ||
<Fragment> | ||
<Section><b>${tokens[0].text}</b></Section> | ||
<Divider /> | ||
</Fragment>`; | ||
} | ||
|
||
paragraph({ tokens }) { | ||
return `<Section><p>${tokens[0].text}</p></Section>`; | ||
} | ||
|
||
list(token) { | ||
return `<Section>${super.list(token)}</Section>`; | ||
} | ||
|
||
hr() { | ||
return `<Divider />`; | ||
} | ||
})(), | ||
}); | ||
return jsxslack([`<Blocks>${rendered}</Blocks>`]); | ||
} | ||
|
||
async function main() { | ||
const { CHANNEL_ID, SLACK_BOT_TOKEN, AFFINE_ENV } = process.env; | ||
|
||
const report = await runTest(); | ||
const blocks = render( | ||
[`# AFFiNE Copilot Test ${AFFINE_ENV} Env Test Result`, report].join('\n\n') | ||
); | ||
const { ok } = await new WebClient(SLACK_BOT_TOKEN).chat.postMessage({ | ||
channel: CHANNEL_ID, | ||
text: `AFFiNE Copilot Test ${AFFINE_ENV} Env Test Result`, | ||
blocks, | ||
}); | ||
|
||
console.assert(ok, 'Failed to send a message to Slack'); | ||
} | ||
|
||
await main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import packageJson from '../package.json' with { type: 'json' }; | ||
|
||
export default { | ||
...packageJson.ava, | ||
environmentVariables: { | ||
...packageJson.ava.environmentVariables, | ||
TS_NODE_PROJECT: './tests/tsconfig.docker.json', | ||
}, | ||
}; |
Oops, something went wrong.