Skip to content

Commit fb02d02

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 fb02d02

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

.github/workflows/push.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,24 @@ 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
73+
- name: Rust Cache
74+
uses: Swatinem/rust-cache@v2.8.1
75+
with:
76+
shared-key: ts-def-gen
77+
save-if: ${{ github.ref == 'refs/heads/master' }}
78+
# Node is needed for the formatting of typescript files.
7579
- uses: ./.github/actions/init-env-node
76-
- run: pnpm generate-ts-definitions
80+
- run: |
81+
sudo apt install libdbus-1-dev pkg-config
82+
./scripts/generate-ts-definitions-from-rust.sh
7783
7884
lint-node:
79-
needs: generate-ts-definitions
8085
if: ${{ needs.changes.outputs.node == 'true' || needs.changes.outputs.rust == 'true' }}
8186
runs-on: ubuntu-latest
8287
steps:
@@ -87,7 +92,6 @@ jobs:
8792
- run: pnpm lint
8893

8994
check-node:
90-
needs: generate-ts-definitions
9195
if: ${{ needs.changes.outputs.node == 'true' || needs.changes.outputs.rust == 'true' }}
9296
runs-on: ubuntu-latest
9397
steps:
@@ -98,7 +102,6 @@ jobs:
98102
- run: pnpm check
99103

100104
unittest-node:
101-
needs: generate-ts-definitions
102105
if: ${{ needs.changes.outputs.node == 'true' }}
103106
runs-on: ubuntu-latest
104107
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)