Skip to content

Commit 931b52d

Browse files
committed
Make generate-ts easier to handle
Ideally, it's clear why tests fail and how to fix them. - add a cache - focus the test-runs to only the crates that harbor ts type definitions - remove CI dependencies as the dependents hang if there was no Rust change, which causes the definitions job to not run.
1 parent 0e3caf7 commit 931b52d

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

.github/workflows/push.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,22 @@ jobs:
6464
needs: changes
6565
if: ${{ needs.changes.outputs.node == 'true' || needs.changes.outputs.rust == 'true' }}
6666
runs-on: ubuntu-latest
67-
container:
68-
image: ghcr.io/gitbutlerapp/ci-base-image:latest
6967
env:
7068
CARGO_TERM_COLOR: always
7169
steps:
7270
- uses: actions/checkout@v6
7371
with:
7472
persist-credentials: false
75-
- uses: ./.github/actions/init-env-node
76-
- run: pnpm generate-ts-definitions
73+
- name: Rust Cache
74+
uses: Swatinem/[email protected]
75+
with:
76+
shared-key: ts-def-gen
77+
save-if: ${{ github.ref == 'refs/heads/master' }}
78+
- run: |
79+
sudo apt install libdbus-1-dev pkg-config
80+
./scripts/generate-ts-definitions-from-rust.sh
7781
7882
lint-node:
79-
needs: generate-ts-definitions
8083
if: ${{ needs.changes.outputs.node == 'true' || needs.changes.outputs.rust == 'true' }}
8184
runs-on: ubuntu-latest
8285
steps:
@@ -87,7 +90,6 @@ jobs:
8790
- run: pnpm lint
8891

8992
check-node:
90-
needs: generate-ts-definitions
9193
if: ${{ needs.changes.outputs.node == 'true' || needs.changes.outputs.rust == 'true' }}
9294
runs-on: ubuntu-latest
9395
steps:
@@ -98,7 +100,6 @@ jobs:
98100
- run: pnpm check
99101

100102
unittest-node:
101-
needs: generate-ts-definitions
102103
if: ${{ needs.changes.outputs.node == 'true' }}
103104
runs-on: ubuntu-latest
104105
steps:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ at the [DEVELOPMENT.md](DEVELOPMENT.md) file.
137137
<a href="https://github.com/gitbutlerapp/gitbutler/graphs/contributors">
138138
<img src="https://contrib.rocks/image?repo=gitbutlerapp/gitbutler" />
139139
</a>
140+
hi

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"rustfmt": "cargo +nightly fmt -- --config-path rustfmt-nightly.toml",
3939
"isgood": "pnpm check && pnpm lint",
4040
"begood": "pnpm format && pnpm fix",
41-
"generate-ts-definitions": "pnpm --filter @gitbutler/core generate-ts"
41+
"generate-ts-definitions": "scripts/generate-ts-definitions-from-rust.sh"
4242
},
4343
"devDependencies": {
4444
"@eslint/js": "9.33.0",

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"check": "tsc --noEmit",
88
"build": "tsc -p tsconfig.json",
99
"format": "prettier --write .",
10-
"generate-ts": "TS_RS_EXPORT_DIR=\"$PNPM_SCRIPT_SRC_DIR/src/generated\" cargo test --features export-ts export_bindings && pnpm format",
1110
"package": "tsc -p tsconfig.json"
1211
},
1312
"exports": {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
git rev-parse --show-toplevel
6+
git_root="$(git rev-parse --show-toplevel 2>/dev/null)"
7+
cd "$git_root"
8+
9+
CRATE_ARGS="$(git grep "export-ts" | awk -F: '{ split($1, parts, "/"); if (length(parts) >= 3) { if (parts[1] == "crates") { crate = parts[2] } else { next } if (!seen[crate]++) print "-p " crate } }')"
10+
11+
# NOTE: export_bindings is generated by the TS proc-macro, and doesn't actually exist.
12+
TS_RS_EXPORT_DIR="$PWD/packages/core/src/generated" cargo test ${CRATE_ARGS} --features export-ts export_bindings
13+
pnpm format
14+
15+
if ! git diff --quiet; then
16+
git status
17+
echo "There are changed TS bindings. This error will go away with `git add .`, and on CI when the changes are committed."
18+
exit 2
19+
fi

0 commit comments

Comments
 (0)