Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ jobs:
run: bun run build
working-directory: packages/dbt-tools

- name: Smoke test dbt-tools bundle
run: |
# Verify node_python_bridge.py was copied into dist
if [ ! -f packages/dbt-tools/dist/node_python_bridge.py ]; then
echo "::error::node_python_bridge.py missing from dbt-tools dist"
exit 1
fi
# Verify no hardcoded CI runner paths remain in the bundle
if grep -q 'home/runner' packages/dbt-tools/dist/index.js; then
echo "::error::dbt-tools bundle contains hardcoded CI runner path"
exit 1
fi
# Verify __dirname was patched to runtime resolution
if ! grep -q 'import.meta.dirname' packages/dbt-tools/dist/index.js; then
echo "::error::dbt-tools bundle missing import.meta.dirname patch"
exit 1
fi
echo "dbt-tools smoke test passed"

- name: Free disk space for artifact download + npm publish
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /usr/local/share/boost
Expand Down
2 changes: 1 addition & 1 deletion packages/dbt-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"build": "bun build src/index.ts --outdir dist --target node --format esm && bun run script/copy-python.ts",
"typecheck": "tsc --noEmit",
"test": "bun test test/cli.test.ts test/config.test.ts test/dbt-cli.test.ts test/dbt-resolve.test.ts --timeout 30000",
"test": "bun test test/cli.test.ts test/config.test.ts test/dbt-cli.test.ts test/dbt-resolve.test.ts test/build-integrity.test.ts --timeout 30000",
"test:e2e": "bun test test/e2e/ --timeout 300000"
},
"dependencies": {
Expand Down
30 changes: 26 additions & 4 deletions packages/dbt-tools/script/copy-python.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import { cpSync } from "fs"
import { cpSync, readFileSync, writeFileSync } from "fs"
import { dirname, join } from "path"

const dist = join(import.meta.dir, "..", "dist")

// 1. Copy altimate_python_packages
const resolved = require.resolve("@altimateai/dbt-integration")
const source = join(dirname(resolved), "altimate_python_packages")
const target = join(import.meta.dir, "..", "dist", "altimate_python_packages")

cpSync(source, target, { recursive: true })
cpSync(source, join(dist, "altimate_python_packages"), { recursive: true })
console.log(`Copied altimate_python_packages → dist/`)

// 2. Copy node_python_bridge.py into dist so it lives next to index.js
// node_python_bridge.py is shipped in dbt-integration's dist
const bridgePy = join(dirname(resolved), "node_python_bridge.py")
cpSync(bridgePy, join(dist, "node_python_bridge.py"))
console.log(`Copied node_python_bridge.py → dist/`)

// 3. Fix the hardcoded __dirname that bun bakes at compile time.
// Replace it with a runtime resolution so the bridge script is found
// relative to the built index.js, not the CI runner's node_modules.
const indexPath = join(dist, "index.js")
let code = readFileSync(indexPath, "utf8")
const pattern = /var __dirname\s*=\s*"[^"]*python-bridge[^"]*"/
if (pattern.test(code)) {
code = code.replace(pattern, `var __dirname = import.meta.dirname`)
writeFileSync(indexPath, code)
console.log(`Patched __dirname in dist/index.js`)
} else {
console.error(`ERROR: could not find python-bridge __dirname to patch — the bundle format may have changed`)
process.exit(1)
}
28 changes: 28 additions & 0 deletions packages/dbt-tools/test/build-integrity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, test, expect, beforeAll } from "bun:test"
import { existsSync, readFileSync } from "fs"
import { join } from "path"
import { $ } from "bun"

const dist = join(import.meta.dir, "../dist")

describe("build integrity", () => {
beforeAll(async () => {
// Rebuild to test the actual build output
await $`bun run build`.cwd(join(import.meta.dir, ".."))
})

test("node_python_bridge.py exists in dist", () => {
expect(existsSync(join(dist, "node_python_bridge.py"))).toBe(true)
})

test("no hardcoded CI runner paths in bundle", () => {
const code = readFileSync(join(dist, "index.js"), "utf8")
expect(code).not.toContain("home/runner")
})

test("__dirname is patched to runtime resolution", () => {
const code = readFileSync(join(dist, "index.js"), "utf8")
expect(code).toContain("import.meta.dirname")
expect(code).not.toMatch(/var __dirname\s*=\s*"\//)
})
})
Loading