Skip to content

Commit

Permalink
Merge /schemas and /raw into /api (#55)
Browse files Browse the repository at this point in the history
* first pass, cant build yet

* Update paths in validate_toml.yml

* try switching entries to an object

* try to configure vite correctly

* this should work now

* redo some changes that got lost in transit

* wtf is going wrong

* fixed schema directives
moved raw/ into the api/ dir
data is now fetched directly from the raw json files instead of from github, for the current api version

* specify working dir for pnpm setup

* fix schema path in validation workflow

* install ajv with pnpm

* just use npm fuck it

* try using a different relative path in prod

* copy raw data into dist when building

* another path attempt

* try using cloudflare static asset serving

* maybe use env directly?

* clone the request

* try using vite glob import

* remove extra copying step which is done by vite now

* fix: Ignore new dev artifact

---------

Co-authored-by: Gregory Danielson <[email protected]>
  • Loading branch information
TheOnlyTails and gregdan3 authored Feb 23, 2024
1 parent e43fcf0 commit bc7036e
Show file tree
Hide file tree
Showing 600 changed files with 1,184 additions and 3,392 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def insert_translations(
transformer,
)

raw_filename = Path("raw") / Path(data_type).stem
raw_filename = Path("api/raw") / Path(data_type).stem
with open(raw_filename.with_suffix(".json"), "w+") as data_file:
json.dump(result, data_file, separators=(",", ":"), sort_keys=True)

Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/publish_npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ permissions:
jobs:
publish-npm:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./api
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -30,16 +33,14 @@ jobs:
version: 8

- run: pnpm version from-git --no-commit-hooks --no-git-tag-version --allow-same-version
working-directory: ./schemas

- run: pnpm install -r --frozen-lockfile
- run: pnpm install --frozen-lockfile

- run: pnpm run -r build && pnpm install -r -f --frozen-lockfile && pnpm run -r build
- run: pnpm run generate && pnpm run build:lib

- run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
pnpm publish --no-git-checks --tag ${{ github.event.release.prerelease && 'next' || 'latest' }}
working-directory: ./schemas
pnpm publish --provenance --no-git-checks --tag ${{ github.event.release.prerelease && 'next' || 'latest' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -48,4 +49,4 @@ jobs:
with:
commit_message: "bump @kulupu-linku/sona version ${{ github.event.release.tag_name }}"
branch: ${{ github.event.repository.default_branch }}
file_pattern: schemas/package.json
file_pattern: api/package.json
17 changes: 9 additions & 8 deletions .github/workflows/validate_toml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
branches-ignore: ["l10n_*"]
paths:
- "**.toml"
- "schemas/src/**"
- "api/src/lib/**"

pull_request:
branches-ignore: ["l10n_*"]
paths:
- "**.toml"
- "schemas/src/**"
- "api/src/lib/**"

workflow_dispatch:

Expand All @@ -30,7 +30,7 @@ jobs:
uses: fkirc/skip-duplicate-actions@v5
with:
cancel_others: true
concurrent_skipping: 'outdated_runs'
concurrent_skipping: "outdated_runs"

validate:
needs: skip_check
Expand All @@ -49,7 +49,7 @@ jobs:
with:
filters: |
schemas:
- 'schemas/src/**'
- 'api/src/lib/**'
data:
- '**.toml'
Expand All @@ -60,11 +60,12 @@ jobs:
version: 8
run_install: |
- args: [--frozen-lockfile]
cwd: ./api
- name: Generate JSON Schemas
if: contains(steps.changes.outputs.changes, 'schemas')
run: pnpm run generate
working-directory: ./schemas
working-directory: ./api

- name: Commit schemas
if: contains(steps.changes.outputs.changes, 'schemas') && !github.event.pull_request.head.repo.fork
Expand All @@ -73,7 +74,7 @@ jobs:
message: "Generated schemas for ${{ github.event.pull_request.head.sha || github.event.head_commit.id || github.sha }}"

- name: Validate all files
run: npx --yes @taplo/cli check
run: pnpm dlx @taplo/cli check

- name: Setup Python
if: contains(steps.changes.outputs.changes, 'data')
Expand All @@ -92,9 +93,9 @@ jobs:
- name: Validate generated file
if: contains(steps.changes.outputs.changes, 'data')
run: |
list=(./raw/*.json)
list=(./api/raw/*.json)
for file in "${list[@]}"; do
npx ajv-cli -s "./schemas/generated/${file:6}" -c ajv-formats --errors=text -d $file;
npx ajv-cli -s "./api/generated/${file:10}" -c ajv-formats --errors=text -d $file;
done
- name: Commit packaged files
Expand Down
4 changes: 3 additions & 1 deletion api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
dist
dist

vite.config.ts.timestamp-*
6 changes: 3 additions & 3 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This folder holds the code for the sona API, hosted at https://api.linku.la/.

The API is built using TypeScript, Vite, and [Hono](https://hono.dev/), using Zod schemas verified against the source data, in the [schemas directory](../schemas).
The API is built using TypeScript, [Vite](https://vitejs.dev/), and [Hono](https://hono.dev/), using Zod schemas verified against the source data.

## Contributing

Expand All @@ -14,6 +14,6 @@ Requirements:
How to contribute:

- Fork the repo and make any changes you want.
- Build the schemas in `../schemas/` with `pnpm run build`
- Run the dev server using `pnpm run -F sona-api dev` and verify that your changes work.
- Build the schemas in with `pnpm run generate`
- Run the dev server using `pnpm run dev` and verify that your changes work.
- Create a pull request back to the main branch and request a review from a maintainer.
2 changes: 1 addition & 1 deletion schemas/generateSchemas.ts → api/generateSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as schemas from "./src/index";
import * as schemas from "./src/lib/index";
import { zodToJsonSchema } from "zod-to-json-schema";
import fs from "node:fs";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
69 changes: 59 additions & 10 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,75 @@
{
"name": "sona-api",
"version": "0.1.0",
"private": true,
"name": "@kulupu-linku/sona",
"version": "0.1.8",
"description": "A library providing TypeScript types and Zod schemas for the sona API",
"homepage": "https://linku.la/",
"bugs": {
"url": "https://github.com/lipu-linku/sona/issues/"
},
"license": "GPL-3.0-or-later",
"contributors": [
{
"name": "TheOnlyTails",
"url": "https://theonlytails.com/",
"email": "[email protected]"
},
{
"name": "gregdan3 (jan Kekan San)",
"url": "https://gregdan3.dev/",
"email": "[email protected]"
}
],
"repository": {
"url": "https://github.com/lipu-linku/sona.git",
"directory": "api",
"type": "git"
},
"scripts": {
"dev": "vite",
"build": "vite build"
"build": "vite build",
"build:lib": "vite build --mode lib",
"generate": "tsx ./generateSchemas.ts",
"generate:watch": "tsx ./generateSchemas.ts --watch-path=./**/*.ts"
},
"dependencies": {
"@hono/vite-cloudflare-pages": "^0.2.5",
"@hono/vite-dev-server": "^0.7.0",
"@hono/vite-dev-server": "^0.7.1",
"@hono/zod-validator": "^0.1.11",
"@kulupu-linku/sona": "workspace:^",
"hono": "^4.0.4",
"hono": "^3.12.12",
"p-lazy": "^4.0.0",
"vite": "^5.1.3",
"zod": "^3.22.4",
"zod-fetch": "^0.1.1",
"zod-validation-error": "^3.0.2"
},
"devDependencies": {
"@types/node": "^20.11.19",
"prettier": "^3.2.5",
"typescript": "^5.3.3"
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"vite": "^5.1.4",
"vite-plugin-dts": "^3.7.3",
"zod-to-json-schema": "^3.22.4"
},
"engines": {
"pnpm": ">=8"
},
"files": [
"/dist",
"/generated"
],
"main": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./utils": {
"import": "./dist/utils.js",
"types": "./dist/utils.d.ts"
},
"./client": {
"import": "./dist/client.js",
"types": "./dist/client.d.ts"
}
},
"type": "module"
}
Loading

0 comments on commit bc7036e

Please sign in to comment.