Skip to content
Open
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: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
android: ${{ steps.filter.outputs.android }}
swift: ${{ steps.filter.outputs.swift }}
reactNative: ${{ steps.filter.outputs.reactNative }}
protocolCodegen: ${{ steps.filter.outputs.protocolCodegen }}
web: ${{ steps.filter.outputs.web }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand Down Expand Up @@ -68,6 +69,13 @@ jobs:
- '.github/workflows/rn-lint.yml'
- '.github/workflows/breaking-changes.yml'
- '.github/workflows/ci.yml'
protocolCodegen:
- 'protocol/**'
- 'platforms/react-native/package.json'
- 'platforms/react-native/pnpm-lock.yaml'
- '.github/actions/setup/**'
- '.github/workflows/protocol-codegen.yml'
- '.github/workflows/ci.yml'
web:
- 'platforms/web/**'
- '.github/workflows/web.yml'
Expand Down Expand Up @@ -143,6 +151,12 @@ jobs:
if: needs.changes.outputs.reactNative == 'true'
uses: ./.github/workflows/rn-lint.yml

protocol-codegen:
name: Protocol
needs: changes
if: needs.changes.outputs.protocolCodegen == 'true'
uses: ./.github/workflows/protocol-codegen.yml

web:
name: Web
needs: changes
Expand Down Expand Up @@ -184,6 +198,7 @@ jobs:
- rn-build-ios
- rn-check-packed-files
- rn-lint
- protocol-codegen
- web
- breaking-changes
runs-on: ubuntu-latest
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/protocol-codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Protocol Codegen Drift

on:
workflow_call:
workflow_dispatch:

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Setup Node.js, pnpm, and install dependencies
uses: ./.github/actions/setup
with:
node-version-file: protocol/package.json
cache-dependency-path: protocol/pnpm-lock.yaml
package-json-file: protocol/package.json
working-directory: protocol

- name: Regenerate protocol models
run: |
pnpm --dir protocol run codegen:kotlin
pnpm --dir protocol run codegen:swift
pnpm --dir protocol run codegen:typescript

- name: Check generated files are current
run: git diff --exit-code
1 change: 1 addition & 0 deletions platforms/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"eslint-plugin-prettier": "^5.5.4",
"jest": "^30.0.5",
"prettier": "^3.2.5",
"quicktype": "23.2.6",
"react": "19.1.0",
"react-native": "0.80.2",
"react-native-dotenv": "^3.4.11",
Expand Down
600 changes: 542 additions & 58 deletions platforms/react-native/pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"codegen:swift": "./scripts/generate_models.sh --lang swift",
"codegen:typescript": "./scripts/generate_models.sh --lang typescript"
},
"engines": {
"node": "22.14.0"
},
"devDependencies": {
"quicktype": "23.2.6"
"quicktype": "23.2.6",
"typescript": "5.9.2"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pin version

}
}
10 changes: 10 additions & 0 deletions protocol/pnpm-lock.yaml

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

27 changes: 27 additions & 0 deletions protocol/scripts/codegen_tools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const PROTOCOL_DIR = path.resolve(SCRIPT_DIR, "..");
export const REPO_ROOT = path.resolve(PROTOCOL_DIR, "..");
export const PACKAGE_JSON = path.join(PROTOCOL_DIR, "package.json");
export const QUICKTYPE_BIN = path.join(PROTOCOL_DIR, "node_modules", ".bin", "quicktype");
export const TSC_BIN = path.join(PROTOCOL_DIR, "node_modules", ".bin", "tsc");

export function run(command, args, options = {}) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -106,3 +107,29 @@ export async function requireQuicktype() {
throw new Error(`Unsupported quicktype version: ${actual}. Expected ${expected} from ${PACKAGE_JSON}.`);
}
}

export async function requireTypescript() {
if (!(await fileIsExecutable(TSC_BIN))) {
throw new Error(`TypeScript is required at ${TSC_BIN}. Run dev up or (cd protocol && pnpm install).`);
}

const packageJson = await readJson(PACKAGE_JSON);
const expected = packageJson.devDependencies?.typescript ?? "";
if (expected === "") {
throw new Error(`Missing TypeScript version in ${PACKAGE_JSON}`);
}

if (!/^[0-9]+[.][0-9]+[.][0-9]+(-[0-9A-Za-z.-]+)?$/.test(expected)) {
throw new Error(`TypeScript must use an exact version in ${PACKAGE_JSON}; found ${expected}.`);
}

const {stdout} = await run(TSC_BIN, ["--version"], {capture: true});
const actual = stdout.match(/^Version (\S+)/m)?.[1] ?? "";
if (actual === "") {
throw new Error(`Unable to determine TypeScript version from ${TSC_BIN}`);
}

if (actual !== expected) {
throw new Error(`Unsupported TypeScript version: ${actual}. Expected ${expected} from ${PACKAGE_JSON}.`);
}
}
7 changes: 4 additions & 3 deletions protocol/scripts/generate_models.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import {
PROTOCOL_DIR,
QUICKTYPE_BIN,
REPO_ROOT,
TSC_BIN,
readJson,
requireQuicktype,
requireTypescript,
run,
} from "./codegen_tools.mjs";

Expand Down Expand Up @@ -357,11 +359,10 @@ async function generateTypescript(specDir, output) {
await run("node", [path.join(PROTOCOL_DIR, "scripts", "generate_typescript_notifications.mjs")]);

const declarationOutput = path.join(PROTOCOL_DIR, "languages", "typescript", "src", "index.d.ts");
const tscBin = path.join(REPO_ROOT, "platforms", "react-native", "node_modules", "typescript", "bin", "tsc");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think we should be using protocol rather than react-native

const indexOutput = path.join(PROTOCOL_DIR, "languages", "typescript", "src", "index.ts");

await run("node", [
tscBin,
await requireTypescript();
await run(TSC_BIN, [
"--declaration",
"--emitDeclarationOnly",
"--noEmit",
Expand Down
Loading