Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtimes): Deno canary #5077

Draft
wants to merge 24 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/check-engines-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ skipped_projects=(
webpack-browser-custom-output # Client is generated into a subfolder
yarn3-workspaces-pnp # Client is generated into a subfolder
serverless-framework-lambda-pnpm # Client is generated into a subfolder
deno # Client is generated into a subfolder
# custom output
jest-with-multiple-generators # No generated Client locally in default path, both Clients have custom `output`
netlify-cli # Client is generated into `../functions/generated/client` via use of `output`
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/scripts/detect-jobs-to-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ async function detectJobsTorun({ filesChanged, GITHUB_REF }) {
if (totalNumberOfFilesChangedInsideDirectories != filesChanged.length) {
console.debug('totalNumberOfFilesChangedInsideDirectories != filesChanged.length')
console.debug('Fallback to run all tests.')
return fallbackRunAllJobs
return ['runtimes']
//return fallbackRunAllJobs
} else {
console.log('Only the following directory/ies will be tested:')
console.log(jobsToRun)
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/scripts/detect-jobs-to-run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('detect-jobs-to-run', () => {
"databases",
"databases-macos",
"test-runners",
"runtimes",
"community-generators",
]
`)
Expand Down Expand Up @@ -119,6 +120,7 @@ describe('detect-jobs-to-run', () => {
"databases",
"databases-macos",
"test-runners",
"runtimes",
"community-generators",
]
`)
Expand Down Expand Up @@ -155,6 +157,7 @@ describe('detect-jobs-to-run', () => {
"databases",
"databases-macos",
"test-runners",
"runtimes",
"community-generators",
]
`)
Expand Down Expand Up @@ -191,6 +194,7 @@ describe('detect-jobs-to-run', () => {
"databases",
"databases-macos",
"test-runners",
"runtimes",
"community-generators",
]
`)
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ jobs:
- databases
- databases-macos
- test-runners
- runtimes
if: always()
steps:
- run: echo "Ok"
Expand Down Expand Up @@ -137,6 +138,7 @@ jobs:
- databases
- databases-macos
- test-runners
- runtimes
if: success() && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/integration' || github.ref == 'refs/heads/patch-dev' || github.ref == 'refs/heads/latest')
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -179,6 +181,7 @@ jobs:
- databases
- databases-macos
- test-runners
- runtimes
if: failure() && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/integration' || github.ref == 'refs/heads/patch-dev' || github.ref == 'refs/heads/latest')
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -1858,3 +1861,53 @@ jobs:
- name: notify-slack
if: failure()
run: bash .github/slack/notify-failure.sh ${{ github.job }} ${{ matrix.test-runner }}


runtimes:
needs: [detect_jobs_to_run]
if: contains(fromJSON(needs.detect_jobs_to_run.outputs.jobs), 'runtimes')

timeout-minutes: 10
strategy:
fail-fast: false
matrix:
runtime:
- deno
#- bun
clientEngine: ['library', 'binary']
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
concurrency: ${{ github.job }}-${{ matrix.runtime }}-${{ matrix.clientEngine }}
env:
RUNTIMES_DENO_DATABASE_URL: ${{ secrets.DATAPROXY_COMMON_URL_SOURCE }}

steps:
- uses: actions/checkout@v4

- uses: pnpm/[email protected]
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: 16
cache: 'pnpm'
cache-dependency-path: ${{ github.job }}/${{ matrix.runtime }}/pnpm-lock.yaml

- name: use deno v1.x
uses: denoland/setup-deno@v1
with:
deno-version: canary

- name: Define Client Engine Type to test
run: echo "PRISMA_CLIENT_ENGINE_TYPE=${{ matrix.clientEngine }}" >> $GITHUB_ENV

- name: Install Dependencies
run: pnpm install

- name: test ${{ matrix.runtime }}
run: bash .github/scripts/test-project.sh ${{ github.job }} ${{ matrix.runtime }}

- name: notify-slack
if: failure()
run: bash .github/slack/notify-failure.sh ${{ github.job }} ${{ matrix.runtime }}
2 changes: 2 additions & 0 deletions runtimes/deno/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
generated
10 changes: 10 additions & 0 deletions runtimes/deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Deno

Runs Prisma Client with Deno.

## How to run this

```sh
source ./prepare.sh && ./run.sh && ./test.sh
```

10 changes: 10 additions & 0 deletions runtimes/deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "deno",
"license": "MIT",
"dependencies": {
"@prisma/client": "5.15.0-dev.16"
},
"devDependencies": {
"prisma": "5.15.0-dev.16"
}
}
65 changes: 65 additions & 0 deletions runtimes/deno/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions runtimes/deno/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

export PRISMA_TELEMETRY_INFORMATION='ecosystem-tests runtimes deno build'

# Install Deno CLI (not needed on GH Actions, only here for reference for local testing)
# curl -fsSL https://deno.land/x/install/install.sh | sh
# alias deno='/home/gitpod/.deno/bin/deno'

deno --version
34 changes: 34 additions & 0 deletions runtimes/deno/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
generator client {
provider = "prisma-client-js"
output = "../generated/client"
engineType = "binary" // overwritten when run in CI via env var
// previewFeatures = ["deno"]
}

datasource db {
provider = "postgresql"
url = env("RUNTIMES_DENO_DATABASE_URL")
}

model Post {
post_id Int @id @default(autoincrement())
content String?
title String
author_id Int?
author User? @relation(fields: [author_id], references: [user_id])
}

model Profile {
bio String?
profile_id Int @id @default(autoincrement())
user_id Int
user User @relation(fields: [user_id], references: [user_id])
}

model User {
email String @unique
name String?
user_id Int @id @default(autoincrement())
posts Post[]
profiles Profile[]
}
7 changes: 7 additions & 0 deletions runtimes/deno/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -eu

version=$( jq -r '.devDependencies.prisma' package.json )

deno run -A npm:prisma@$version generate
20 changes: 20 additions & 0 deletions runtimes/deno/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { type PrismaClient } from '../generated/client/index.d.ts'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const Prisma = require('../generated/client/index.js')

// const prisma = new PrismaClient();
export const prisma: PrismaClient = new Prisma.PrismaClient({ log: ['query', 'info', 'warn', 'error'] })

export async function getUsers() {
// Do a query and disconnect
// So we also test that connection is re-established in next query below
await prisma.user.findFirst();
await prisma.$disconnect();

// query should re-connect automatically
return await prisma.$transaction([
prisma.user.findFirst(),
prisma.user.findMany(),
]);
}
11 changes: 11 additions & 0 deletions runtimes/deno/src/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { type PrismaClient } from '../generated/client/index.d.ts'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const Prisma = require('../generated/client/index.js')

// const prisma = new PrismaClient();
const prisma: PrismaClient = new Prisma.PrismaClient({ log: ['query', 'info', 'warn', 'error'] })

console.log("foo")
const users = await prisma.user.findFirst();
console.log(users)
5 changes: 5 additions & 0 deletions runtimes/deno/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -eu

deno test -A --no-check
69 changes: 69 additions & 0 deletions runtimes/deno/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { getUsers } from "./src/index.ts";

Deno.test(
"can run query",
{ sanitizeOps: false, sanitizeResources: false },
async () => {
const users = await getUsers();
assertEquals(users, [
{
"email": "[email protected]",
"name": "Autumn",
"user_id": 1,
},
[
{
"email": "[email protected]",
"name": "Autumn",
"user_id": 1,
},
{
"email": "[email protected]",
"name": "Marguerite",
"user_id": 2,
},
{
"email": "[email protected]",
"name": "Jana",
"user_id": 3,
},
{
"email": "[email protected]",
"name": "Pink",
"user_id": 4,
},
{
"email": "[email protected]",
"name": "Oren",
"user_id": 5,
},
{
"email": "[email protected]",
"name": "Sigmund",
"user_id": 6,
},
{
"email": "[email protected]",
"name": "Toy",
"user_id": 7,
},
{
"email": "[email protected]",
"name": "Brooklyn",
"user_id": 8,
},
{
"email": "[email protected]",
"name": "Cassandre",
"user_id": 9,
},
{
"email": "[email protected]",
"name": "Jazmyne",
"user_id": 10,
},
],
]);
},
);
Loading