Add lint and test workflows
Tests / Test (Go) (push) Successful in 1m46s
Tests / Test (Python) (push) Successful in 14s
Lint / Lint (Go) (push) Successful in 21s
Lint / Lint (Python) (push) Successful in 10s
Tests / Test (Node/Svelte) (push) Successful in 12s
Lint / Lint (Node/Svelte) (push) Successful in 40s
Tests / Test (Go) (push) Successful in 1m46s
Tests / Test (Python) (push) Successful in 14s
Lint / Lint (Go) (push) Successful in 21s
Lint / Lint (Python) (push) Successful in 10s
Tests / Test (Node/Svelte) (push) Successful in 12s
Lint / Lint (Node/Svelte) (push) Successful in 40s
This commit is contained in:
1 parent
838a97d344
commit
fbbdab49bc
8 files changed
+242
-2
No files matched your search
@@ -0,0 +1,86 @@
|
|||||||
|
name: Lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "**"
|
||||||
|
paths:
|
||||||
|
- '.changeset/**'
|
||||||
|
- '.github/workflows/**'
|
||||||
|
- 'backend/**'
|
||||||
|
- 'packages/**'
|
||||||
|
- 'scripts/**'
|
||||||
|
- 'package.json'
|
||||||
|
- 'package-lock.json'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
paths:
|
||||||
|
- '.changeset/**'
|
||||||
|
- '.github/workflows/**'
|
||||||
|
- 'backend/**'
|
||||||
|
- 'packages/**'
|
||||||
|
- 'scripts/**'
|
||||||
|
- 'package.json'
|
||||||
|
- 'package-lock.json'
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
node:
|
||||||
|
name: Lint (Node/Svelte)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '24'
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: package-lock.json
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Run Node/Svelte lint checks
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
|
go:
|
||||||
|
name: Lint (Go)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: backend
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: backend/go.mod
|
||||||
|
cache: true
|
||||||
|
- name: Check gofmt
|
||||||
|
shell: bash
|
||||||
|
run: test -z "$(gofmt -l $(find . -type f -name '*.go'))"
|
||||||
|
- name: Run go vet
|
||||||
|
run: go vet ./...
|
||||||
|
|
||||||
|
python:
|
||||||
|
name: Lint (Python)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.12'
|
||||||
|
- name: Install package and Ruff
|
||||||
|
run: python -m pip install --upgrade pip ruff -e packages/python-backend
|
||||||
|
- name: Run Ruff
|
||||||
|
run: ruff check packages/python-backend/src packages/python-backend/tests
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "**"
|
||||||
|
paths:
|
||||||
|
- '.changeset/**'
|
||||||
|
- '.github/workflows/**'
|
||||||
|
- 'backend/**'
|
||||||
|
- 'packages/**'
|
||||||
|
- 'scripts/**'
|
||||||
|
- 'package.json'
|
||||||
|
- 'package-lock.json'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
paths:
|
||||||
|
- '.changeset/**'
|
||||||
|
- '.github/workflows/**'
|
||||||
|
- 'backend/**'
|
||||||
|
- 'packages/**'
|
||||||
|
- 'scripts/**'
|
||||||
|
- 'package.json'
|
||||||
|
- 'package-lock.json'
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
node:
|
||||||
|
name: Test (Node/Svelte)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '24'
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: package-lock.json
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Build and test Node/Svelte packages
|
||||||
|
run: npm test
|
||||||
|
|
||||||
|
go:
|
||||||
|
name: Test (Go)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: backend
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: backend/go.mod
|
||||||
|
cache: true
|
||||||
|
- name: Run Go tests
|
||||||
|
run: go test ./...
|
||||||
|
|
||||||
|
python:
|
||||||
|
name: Test (Python)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.12'
|
||||||
|
- name: Install package
|
||||||
|
run: python -m pip install --upgrade pip -e packages/python-backend
|
||||||
|
- name: Run Python tests
|
||||||
|
run: python -m unittest discover -s packages/python-backend/tests -p 'test_*.py'
|
||||||
@@ -9,6 +9,9 @@
|
|||||||
"check": "npm run check --workspace=@gabriel20xx/web-ui",
|
"check": "npm run check --workspace=@gabriel20xx/web-ui",
|
||||||
"build": "npm run package --workspace=@gabriel20xx/web-ui",
|
"build": "npm run package --workspace=@gabriel20xx/web-ui",
|
||||||
"package": "npm run package --workspace=@gabriel20xx/web-ui",
|
"package": "npm run package --workspace=@gabriel20xx/web-ui",
|
||||||
|
"lint": "npm run check && npm run lint:node",
|
||||||
|
"lint:node": "node scripts/check-node-syntax.mjs",
|
||||||
|
"test": "npm run build && npm run test:node-backend",
|
||||||
"test:node-backend": "npm test --workspace=@gabriel20xx/node-backend",
|
"test:node-backend": "npm test --workspace=@gabriel20xx/node-backend",
|
||||||
"changeset": "changeset",
|
"changeset": "changeset",
|
||||||
"version-packages": "changeset version",
|
"version-packages": "changeset version",
|
||||||
|
|||||||
@@ -16,3 +16,10 @@ dependencies = [
|
|||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
where = ["src"]
|
where = ["src"]
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
target-version = "py310"
|
||||||
|
line-length = 100
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = ["E", "F", "I"]
|
||||||
@@ -22,7 +22,8 @@ CREATE TABLE IF NOT EXISTS auth_users (
|
|||||||
ALTER TABLE auth_users ADD COLUMN IF NOT EXISTS email TEXT NOT NULL DEFAULT '';
|
ALTER TABLE auth_users ADD COLUMN IF NOT EXISTS email TEXT NOT NULL DEFAULT '';
|
||||||
ALTER TABLE auth_users ADD COLUMN IF NOT EXISTS created_at TIMESTAMPTZ NOT NULL DEFAULT now();
|
ALTER TABLE auth_users ADD COLUMN IF NOT EXISTS created_at TIMESTAMPTZ NOT NULL DEFAULT now();
|
||||||
ALTER TABLE auth_users ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
|
ALTER TABLE auth_users ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS auth_users_email_idx ON auth_users (lower(email)) WHERE email <> '';
|
CREATE UNIQUE INDEX IF NOT EXISTS auth_users_email_idx
|
||||||
|
ON auth_users (lower(email)) WHERE email <> '';
|
||||||
CREATE TABLE IF NOT EXISTS auth_sessions (
|
CREATE TABLE IF NOT EXISTS auth_sessions (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
user_id BIGINT NOT NULL REFERENCES auth_users(id) ON DELETE CASCADE,
|
user_id BIGINT NOT NULL REFERENCES auth_users(id) ON DELETE CASCADE,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from typing import Any, AsyncIterator, Awaitable, Callable, Sequence
|
from typing import Any, AsyncIterator, Awaitable, Callable
|
||||||
|
|
||||||
import asyncpg
|
import asyncpg
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from shared_backend.auth import hash_password, verify_password
|
||||||
|
from shared_backend.config import DatabaseConfig
|
||||||
|
from shared_backend.tokens import hash_token, new_session_token
|
||||||
|
|
||||||
|
|
||||||
|
class SharedBackendTests(unittest.TestCase):
|
||||||
|
def test_password_round_trip(self):
|
||||||
|
password_hash = hash_password("correct horse battery staple")
|
||||||
|
self.assertTrue(verify_password("correct horse battery staple", password_hash))
|
||||||
|
self.assertFalse(verify_password("wrong password", password_hash))
|
||||||
|
|
||||||
|
def test_session_token_hash(self):
|
||||||
|
token, token_hash = new_session_token()
|
||||||
|
self.assertNotEqual(token, token_hash)
|
||||||
|
self.assertEqual(hash_token(token), token_hash)
|
||||||
|
|
||||||
|
def test_database_config_from_environment(self):
|
||||||
|
config = DatabaseConfig.from_env(
|
||||||
|
{
|
||||||
|
**os.environ,
|
||||||
|
"DATABASE_URL": "postgresql://user:password@localhost:5432/app",
|
||||||
|
"DATABASE_MAX_CONNS": "7",
|
||||||
|
"DATABASE_MIN_CONNS": "2",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.assertEqual(config.max_size, 7)
|
||||||
|
self.assertEqual(config.min_size, 2)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { execFileSync } from 'node:child_process';
|
||||||
|
import { readdirSync, statSync } from 'node:fs';
|
||||||
|
import { join, relative } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const root = fileURLToPath(new URL('..', import.meta.url));
|
||||||
|
const directories = ['packages/node-backend/src', 'packages/node-backend/test'];
|
||||||
|
|
||||||
|
function javascriptFiles(directory) {
|
||||||
|
const absoluteDirectory = join(root, directory);
|
||||||
|
const files = [];
|
||||||
|
for (const entry of readdirSync(absoluteDirectory)) {
|
||||||
|
const absolutePath = join(absoluteDirectory, entry);
|
||||||
|
if (statSync(absolutePath).isFile() && /\.(?:c|m)?js$/.test(entry)) {
|
||||||
|
files.push(absolutePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const directory of directories) {
|
||||||
|
for (const file of javascriptFiles(directory)) {
|
||||||
|
execFileSync(process.execPath, ['--check', file], { stdio: 'inherit' });
|
||||||
|
console.log(`Syntax OK: ${relative(root, file)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user