Skip to content
Merged
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
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 absolute path in __dirname (catches any CI runner OS)
if grep -qE 'var __dirname\s*=\s*"(/|[A-Za-z]:\\)' packages/dbt-tools/dist/index.js; then
echo "::error::dbt-tools bundle contains hardcoded absolute path in __dirname"
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
41 changes: 37 additions & 4 deletions packages/dbt-tools/script/copy-python.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
import { cpSync } from "fs"
import { cpSync, existsSync, 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")
if (!existsSync(bridgePy)) {
console.error(`ERROR: node_python_bridge.py not found at ${bridgePy}`)
console.error(` Is @altimateai/dbt-integration up to date?`)
process.exit(1)
}
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)) {
// import.meta.dirname is supported by Bun and Node >= 20.11.0.
// Fallback via __require handles older runtimes where import.meta.dirname is unavailable.
const replacement = `var __dirname = typeof import.meta.dirname === "string" ? import.meta.dirname : __require("path").dirname(__require("url").fileURLToPath(import.meta.url))`
code = code.replace(pattern, replacement)
writeFileSync(indexPath, code)
console.log(`Patched __dirname in dist/index.js`)
} else {
const found = code.match(/var __dirname[^;]*/)?.[0] ?? "(not found)"
console.error(`ERROR: could not find python-bridge __dirname to patch — the bundle format may have changed`)
console.error(` Pattern: ${pattern}`)
console.error(` Nearest match: ${found}`)
process.exit(1)
}
Loading
Loading