Skip to content
Merged
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
15 changes: 8 additions & 7 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
APP_ENV=test
PORT=3021
GOOGLE_CLIENT_ID=...test.apps.googleusercontent.com
CLIENT_SECRET=GOC...test
REDIRECT_URI=http://localhost:7737/api/auth/google

CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
CLICKHOUSE_HOST=http://localhost:8443
CLICKHOUSE_USER=default
CLICKHOUSE_PASSWORD=token_pass
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
CLICKHOUSE_USER=default
CLIENT_SECRET=GOC...test
GOOGLE_CLIENT_ID=...test.apps.googleusercontent.com
PORT=3021
REDIRECT_URI=http://localhost:7737/api/auth/google
# Get values from `deno task dev:env`
# then copy missing variables and replace APP_ENV to the matching values
6 changes: 1 addition & 5 deletions .github/workflows/ga-build-image.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Workflow to build and push a Docker image to GitHub Container Registry

name: '🐳 Build Docker Image'

on:
push:
branches: ['master']

on: { push: { branches: ['master'] } }
jobs:
build-image:
name: 🏗️ Build Image
Expand Down
25 changes: 10 additions & 15 deletions .github/workflows/ga-compliance.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# Workflow for DevTools Compliance

name: DevTools Compliance

on:
pull_request:
types:
[
opened,
edited,
synchronize,
reopened,
labeled,
unlabeled,
assigned,
unassigned,
]
- opened
- edited
- synchronize
- reopened
- labeled
- unlabeled
- assigned
- unassigned

jobs:
check-compliance:
Expand All @@ -23,9 +19,8 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
uses: actions/checkout@v5
with: { fetch-depth: 0 }

- name: Show PR Labels and Assignees
run: |
Expand Down
26 changes: 5 additions & 21 deletions .github/workflows/ga-linter-fmt.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
# Workflow for DevTools CI/CD
# This workflow runs linting and formatting checks on pull requests.
# It ensures that the code adheres to style guidelines and is free of linting errors.

name: DevTools CI/CD

on:
pull_request:
types: [opened, reopened, synchronize]
pull_request: { types: [opened, reopened, synchronize] }

jobs:
lint-and-format:
name: Lint and Format Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
uses: actions/checkout@v5
with: { fetch-depth: 0 }

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Cache Deno dependencies
uses: actions/cache@v4
with:
path: |
~/.deno
~/node_modules
~/.cache/deno

key: ${{ runner.os }}-deno-v2-${{ hashFiles('deno.json') }}
with: { deno-version: v2.x, cache: true }

- name: 🔍 Get all changed files
id: changed-file-list
Expand All @@ -45,7 +29,7 @@ jobs:

- name: Run formatter
if: steps.changed-file-list.outputs.changed_files != ''
run: deno task fmt --permit-no-files --check ${{ steps.changed-file-list.outputs.changed_files }}
run: deno task fmt --permit-no-files ${{ steps.changed-file-list.outputs.changed_files }}

- name: Run check
if: steps.changed-file-list.outputs.changed_files != ''
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/ga-redeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ jobs:
name: 💽 Redeploy DevTools
runs-on: devtools.01edu.ai
environment: production

permissions:
packages: read
contents: read

permissions: { packages: read, contents: read }
steps:
- name: 🔐 Login to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
Expand Down
4 changes: 2 additions & 2 deletions api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
verifyGoogleToken,
verifyState,
} from '/api/lib/google-oauth.ts'
import { respond } from '/api/lib/response.ts'
import { respond } from '@01edu/api/response'
import { authenticateOauthUser } from '/api/user.ts'
import { savePicture } from '/api/picture.ts'
import type { RequestContext } from '/api/lib/context.ts'
import type { RequestContext } from '@01edu/api/context'

interface GoogleTokens {
access_token: string
Expand Down
15 changes: 11 additions & 4 deletions api/clickhouse-client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { createClient } from 'npm:@clickhouse/client'
import { createClient } from '@clickhouse/client'
import {
CLICKHOUSE_HOST,
CLICKHOUSE_PASSWORD,
CLICKHOUSE_USER,
} from './lib/env.ts'
import { respond } from './lib/response.ts'
import { respond } from '@01edu/api/response'
import { log } from './lib/log.ts'
import { ARR, NUM, OBJ, optional, STR, UNION } from './lib/validator.ts'
import { Asserted } from './lib/router.ts'
import {
ARR,
type Asserted,
NUM,
OBJ,
optional,
STR,
UNION,
} from '@01edu/api/validator'

const LogSchema = OBJ({
timestamp: NUM('The timestamp of the log event'),
Expand Down
46 changes: 0 additions & 46 deletions api/lib/context.ts

This file was deleted.

56 changes: 16 additions & 40 deletions api/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,22 @@
const env = Deno.env.toObject()
import { ENV } from '@01edu/api/env'

type AppEnvironments = 'dev' | 'test' | 'prod'

export const APP_ENV = env.APP_ENV || 'dev' as AppEnvironments
if (APP_ENV !== 'dev' && APP_ENV !== 'test' && APP_ENV !== 'prod') {
throw Error(`APP_ENV: "${env.APP_ENV}" must be "dev", "test" or "prod"`)
}

export const PORT = Number(env.PORT) || 2119
export const Picture_Dir = env.PICTURE_DIR || './.picture'

export const GOOGLE_CLIENT_ID = env.GOOGLE_CLIENT_ID
if (!GOOGLE_CLIENT_ID) {
throw Error('GOOGLE_CLIENT_ID: field required in the env')
}
export const CLIENT_SECRET = env.CLIENT_SECRET
if (!CLIENT_SECRET) {
throw Error('CLIENT_SECRET: field required in the env')
}
export const REDIRECT_URI = env.REDIRECT_URI
if (!REDIRECT_URI) {
throw Error('REDIRECT_URI: field required in the env')
}
export const PORT = Number(ENV('PORT', '2119'))
export const PICTURE_DIR = ENV('PICTURE_DIR', './.picture')
export const GOOGLE_CLIENT_ID = ENV('GOOGLE_CLIENT_ID')
export const CLIENT_SECRET = ENV('CLIENT_SECRET')
export const REDIRECT_URI = ENV('REDIRECT_URI')
export const ORIGIN = new URL(REDIRECT_URI).origin
export const SECRET = ENV(
'SECRET',
'iUokBru8WPSMAuMspijlt7F-Cnpqyg84F36b1G681h0',
)

export const SECRET = env.SECRET ||
'iUokBru8WPSMAuMspijlt7F-Cnpqyg84F36b1G681h0'

export const CLICKHOUSE_HOST = env.CLICKHOUSE_HOST
if (!CLICKHOUSE_HOST) {
throw Error('CLICKHOUSE_HOST: field required in the env')
}
export const CLICKHOUSE_USER = env.CLICKHOUSE_USER
if (!CLICKHOUSE_USER) {
throw Error('CLICKHOUSE_USER: field required in the env')
}
export const CLICKHOUSE_PASSWORD = env.CLICKHOUSE_PASSWORD
if (!CLICKHOUSE_PASSWORD) {
throw Error('CLICKHOUSE_PASSWORD: field required in the env')
}
export const CLICKHOUSE_HOST = ENV('CLICKHOUSE_HOST')
export const CLICKHOUSE_USER = ENV('CLICKHOUSE_USER')
export const CLICKHOUSE_PASSWORD = ENV('CLICKHOUSE_PASSWORD')

// Optional interval (ms) for refreshing external SQL database schemas
// Defaults to 24 hours
export const DB_SCHEMA_REFRESH_MS = Number(env.DB_SCHEMA_REFRESH_MS) ||
24 * 60 * 60 * 1000
export const DB_SCHEMA_REFRESH_MS = Number(
ENV('DB_SCHEMA_REFRESH_MS', `${24 * 60 * 60 * 1000}`),
)
11 changes: 3 additions & 8 deletions api/lib/json_store.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
// db_test.ts
import { afterEach, beforeEach, describe, it } from 'jsr:@std/testing/bdd'
import {
assert,
assertEquals,
assertExists,
assertRejects,
} from 'jsr:@std/assert'
import { afterEach, beforeEach, describe, it } from '@std/testing/bdd'
import { assert, assertEquals, assertExists, assertRejects } from '@std/assert'
import { createCollection } from './json_store.ts'
import { ensureDir } from 'jsr:@std/fs'
import { ensureDir } from '@std/fs'

type User = {
id: number
Expand Down
6 changes: 3 additions & 3 deletions api/lib/json_store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// zero-db.ts
import { join } from 'jsr:@std/path'
import { APP_ENV } from './env.ts'
import { ensureDir } from 'jsr:@std/fs'
import { join } from '@std/path'
import { APP_ENV } from '@01edu/api/env'
import { ensureDir } from '@std/fs'

const DB_DIR = APP_ENV === 'test' ? './db_test' : './db'

Expand Down
Loading
Loading