Skip to content

Commit

Permalink
feat(runtimes): Deno 1.44.2 (#5082)
Browse files Browse the repository at this point in the history
Co-authored-by: Joël Galeran <[email protected]>
  • Loading branch information
janpio and Jolg42 authored Jun 13, 2024
1 parent 3fd11e6 commit a520c03
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 1 deletion.
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
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 @@ -36,6 +36,7 @@ describe('detect-jobs-to-run', () => {
"databases",
"databases-macos",
"test-runners",
"runtimes",
"process-managers",
"docker",
"docker-unsupported",
Expand Down Expand Up @@ -116,6 +117,7 @@ describe('detect-jobs-to-run', () => {
"databases",
"databases-macos",
"test-runners",
"runtimes",
"process-managers",
"docker",
"docker-unsupported",
Expand Down Expand Up @@ -152,6 +154,7 @@ describe('detect-jobs-to-run', () => {
"databases",
"databases-macos",
"test-runners",
"runtimes",
"process-managers",
"docker",
"docker-unsupported",
Expand Down Expand Up @@ -188,6 +191,7 @@ describe('detect-jobs-to-run', () => {
"databases",
"databases-macos",
"test-runners",
"runtimes",
"process-managers",
"docker",
"docker-unsupported",
Expand Down
55 changes: 54 additions & 1 deletion .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 @@ -1682,6 +1685,57 @@ jobs:
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: v1.44.2

- 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 }}


process-managers:
needs: [detect_jobs_to_run]
if: contains(fromJSON(needs.detect_jobs_to_run.outputs.jobs), 'process-managers')
Expand All @@ -1696,7 +1750,6 @@ jobs:

steps:
- uses: actions/checkout@v4

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

Expand Down
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
33 changes: 33 additions & 0 deletions runtimes/deno/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
generator client {
provider = "prisma-client-js"
output = "../generated/client"
engineType = "binary" // overwritten when run in CI via env var
}

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(),
]);
}
10 changes: 10 additions & 0 deletions runtimes/deno/src/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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'] })

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,
},
],
]);
},
);

0 comments on commit a520c03

Please sign in to comment.