@@ -15,65 +15,59 @@ def _docs_build_impl(ctx):
1515 source_files = ctx .files .srcs
1616 package_json = ctx .file .package_json
1717
18- # Create a comprehensive build script that handles everything
19- build_script = ctx .actions .declare_file (ctx .attr .name + "_build_docs.sh" )
20- ctx .actions .write (
21- output = build_script ,
22- content = """
23- #!/bin/bash
24- set -euo pipefail
25-
26- NODE="$1"
27- NPM="$2"
28- OUTPUT_TAR="$3"
29- PACKAGE_JSON="$4"
30- shift 4
31-
32- # Create temporary workspace
33- WORK_DIR="$(mktemp -d)"
34- echo "Working in: $WORK_DIR"
35-
36- # Copy package.json
37- cp "$PACKAGE_JSON" "$WORK_DIR/package.json"
38-
39- # Copy all source files, maintaining docs-site structure
40- for src_file in "$@"; do
41- if [[ "$src_file" == docs-site/* ]]; then
42- # Remove docs-site/ prefix to get relative path
43- rel_path="${src_file#docs-site/}"
44- dest_file="$WORK_DIR/$rel_path"
45- dest_dir="$(dirname "$dest_file")"
46- mkdir -p "$dest_dir"
47- cp "$src_file" "$dest_file"
48- fi
49- done
50-
51- # Change to workspace
52- cd "$WORK_DIR"
53-
54- # Install dependencies using hermetic npm
55- "$NPM" install --no-audit --no-fund
56-
57- # Build documentation site
58- "$NPM" run build
59-
60- # Package the built site
61- tar -czf "$OUTPUT_TAR" -C dist .
62-
63- echo "Documentation build complete: $OUTPUT_TAR"
64- """ ,
65- is_executable = True ,
66- )
6718
68- # Run the comprehensive build script
69- build_args = [node . path , npm . path , docs_archive . path , package_json . path ]
19+ # Prepare input files list
20+ input_file_args = []
7021 for src in source_files :
7122 if src .path .startswith ("docs-site/" ):
72- build_args .append (src .path )
73-
74- ctx .actions .run (
75- executable = build_script ,
76- arguments = build_args ,
23+ input_file_args .append (src .path )
24+
25+ ctx .actions .run_shell (
26+ command = """
27+ set -euo pipefail
28+
29+ # Store execution root and output path
30+ EXEC_ROOT="$(pwd)"
31+ OUTPUT_TAR="$1"
32+ PACKAGE_JSON="$2"
33+ shift 2
34+
35+ # Create temporary workspace
36+ WORK_DIR="$(mktemp -d)"
37+ echo "Working in: $WORK_DIR"
38+
39+ # Copy package.json
40+ cp "$PACKAGE_JSON" "$WORK_DIR/package.json"
41+
42+ # Copy all source files, maintaining docs-site structure
43+ for src_file in "$@"; do
44+ if [[ "$src_file" == docs-site/* ]]; then
45+ # Remove docs-site/ prefix to get relative path
46+ rel_path="${src_file#docs-site/}"
47+ dest_file="$WORK_DIR/$rel_path"
48+ dest_dir="$(dirname "$dest_file")"
49+ mkdir -p "$dest_dir"
50+ cp "$src_file" "$dest_file"
51+ fi
52+ done
53+
54+ # Change to workspace for npm operations
55+ cd "$WORK_DIR"
56+
57+ # Install dependencies using hermetic npm (from PATH via tools)
58+ npm install --no-audit --no-fund
59+
60+ # Build documentation site
61+ npm run build
62+
63+ # Return to execution root and create output file there
64+ cd "$EXEC_ROOT"
65+ mkdir -p "$(dirname "$OUTPUT_TAR")"
66+ tar -czf "$OUTPUT_TAR" -C "$WORK_DIR/dist" .
67+
68+ echo "Documentation build complete: $OUTPUT_TAR"
69+ """ ,
70+ arguments = [docs_archive .path , package_json .path ] + input_file_args ,
7771 inputs = source_files + [package_json ],
7872 outputs = [docs_archive ],
7973 tools = [node , npm ],
0 commit comments