Skip to content

Commit cfd1bf7

Browse files
authored
Fix issue #44 (#66)
* add script to process reference docs * attempt to build with remote cache * typo * add reference mdx files * use html -> mdx pandoc converter * add reference mdx files * golang converter from html to md * remove reference files * test better converter * Run converter after upstream docs are copied * remove yaml files * fix missing links * fix more broken links * cleanup
1 parent 4838392 commit cfd1bf7

File tree

165 files changed

+42240
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+42240
-168
lines changed

.github/workflows/pull-from-bazel-build.yml

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,77 @@ jobs:
3131
steps:
3232
- uses: actions/checkout@v5
3333
with:
34-
# Dont auto-init submodules
34+
# Don't auto-init submodules
3535
submodules: false
3636

3737
- name: Checkout submodules
3838
run: git submodule update --init -- upstream
39-
39+
4040
- name: Checkout commit of Bazel Build submodule
4141
if: ${{ inputs.bazelCommitHash != '' }}
4242
working-directory: upstream
4343
run: git checkout '${{ inputs.bazelCommitHash }}'
4444

45+
- name: Setup Bazel
46+
uses: bazel-contrib/setup-bazel@0.15.0
47+
with:
48+
bazelisk-cache: true
49+
repository-cache: true
50+
51+
- name: Build reference documentation
52+
working-directory: upstream
53+
run: >
54+
bazel build
55+
--config=docs
56+
--build_metadata=ROLE=DOCS
57+
--remote_header=x-buildbuddy-api-key=${{ secrets.BUILDBUDDY_ORG_API_KEY }}
58+
--bes_results_url=https://app.buildbuddy.io/invocation/
59+
--bes_backend=grpcs://remote.buildbuddy.io
60+
--remote_cache=grpcs://remote.buildbuddy.io
61+
--remote_timeout=10m
62+
//src/main/java/com/google/devtools/build/lib:gen_reference_docs
63+
64+
# Upload reference-docs.zip as an artifact for debugging purposes
65+
- name: Upload reference docs artifact
66+
if: ${{ github.ref != 'refs/heads/main' }}
67+
uses: actions/upload-artifact@v4.6.2
68+
with:
69+
name: reference-docs
70+
path: upstream/bazel-bin/src/main/java/com/google/devtools/build/lib/reference-docs.zip
71+
retention-days: 7
72+
4573
- name: Clean up mdx files
4674
run: ./cleanup-mdx.sh
4775

76+
- name: Set up Go
77+
uses: actions/setup-go@v6
78+
with:
79+
go-version: '1.25.2'
80+
81+
- name: Initialize Go module for converter
82+
run: |
83+
cd html2md_converter
84+
go mod init html-to-md-converter
85+
go get github.com/JohannesKaufmann/html-to-markdown
86+
87+
- name: Build HTML to Markdown converter
88+
run: |
89+
cd html2md_converter
90+
go build -o html-to-md main.go
91+
92+
- name: Convert reference documentation HTML to Markdown
93+
run: |
94+
# Extract and convert HTML reference docs to Markdown
95+
./html2md_converter/html-to-md \
96+
-zip upstream/bazel-bin/src/main/java/com/google/devtools/build/lib/reference-docs.zip \
97+
-output reference-docs-temp
98+
4899
- name: Transform upstream docs to mdx
49100
run: ./copy-upstream-docs.sh
50101

51102
- name: Create versioned navigation
52103
run: ./docs.json.update.sh
104+
105+
- name: Clean up temporary files
106+
run: rm -rf reference-docs-temp
107+

copy-upstream-docs.sh

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
set -o errexit -o nounset -o pipefail
88

9-
SOURCE_DIR="upstream/site/en"
10-
DEST_DIR="${1:-.}" # Use first argument or current directory as default
9+
# Primary upstream directory
10+
UPSTREAM_SITE="upstream/site/en"
11+
12+
# Reference docs directory
13+
REFERENCE_DOCS="reference-docs-temp"
14+
15+
# Destination directory (default to current directory)
16+
DEST_DIR="${1:-.}"
17+
1118
# Files that live in this repo, not fetched from upstream
1219
LOCAL_FILES="
1320
index.mdx
@@ -43,6 +50,10 @@ query/language.mdx
4350
query/quickstart.mdx
4451
reference/flag-cheatsheet.mdx
4552
reference/test-encyclopedia.mdx
53+
reference/command-line-reference.mdx
54+
reference/be/be-nav.mdx
55+
reference/be/functions.mdx
56+
reference/be/platforms-and-toolchains.mdx
4657
release/rolling.mdx
4758
remote/ci.mdx
4859
remote/dynamic.mdx
@@ -53,53 +64,56 @@ start/go.mdx
5364
tutorials/ccp-toolchain-config.mdx
5465
"
5566

56-
# Check if source directory exists
57-
if [ ! -d "$SOURCE_DIR" ]; then
58-
echo "Error: Source directory '$SOURCE_DIR' not found"
67+
# Verify that at least one source exists
68+
if [ ! -d "$UPSTREAM_SITE" ] && [ ! -d "$REFERENCE_DOCS" ]; then
69+
echo "Error: neither source directory exists: '$UPSTREAM_SITE' or '$REFERENCE_DOCS'"
5970
exit 1
6071
fi
6172

62-
# Create destination directory if it doesn't exist
6373
if [ ! -d "$DEST_DIR" ]; then
6474
echo "Creating destination directory: $DEST_DIR"
6575
mkdir -p "$DEST_DIR"
6676
fi
6777

68-
echo "Finding all .md files in $SOURCE_DIR and copying to $DEST_DIR..."
69-
70-
# Find all .md files and copy them
71-
find "$SOURCE_DIR" -name "*.md" -type f | while read -r source_file; do
72-
# Get relative path from upstream/site/en
73-
relative_path="${source_file#$SOURCE_DIR/}"
74-
75-
# Convert .md to .mdx
76-
target_file="${relative_path%.md}.mdx"
77-
78-
# Create target directory if it doesn't exist
79-
target_dir=$(dirname "$DEST_DIR/$target_file")
80-
if [ "$target_dir" != "$DEST_DIR" ]; then
81-
mkdir -p "$target_dir"
78+
echo "Will search in '$UPSTREAM_SITE' and '$REFERENCE_DOCS' (if exists) to copy .md → .mdx to $DEST_DIR"
79+
80+
transform_docs() {
81+
local SOURCE_DIR="$1"
82+
if [ ! -d "$SOURCE_DIR" ]; then
83+
echo "Warning: source directory '$SOURCE_DIR' not found, skipping"
84+
return
8285
fi
83-
86+
87+
find "$SOURCE_DIR" -name "*.md" -type f | while read -r source_file; do
88+
# Derive the relative path inside the source tree
89+
relative_path="${source_file#$SOURCE_DIR/}"
90+
target_file="${relative_path%.md}.mdx"
91+
target_dir=$(dirname "$DEST_DIR/$target_file")
92+
93+
mkdir -p "$target_dir"
94+
8495
# Check if this file is in the BROKEN_FILES list
85-
if echo "$BROKEN_FILES" | grep -q "^$target_file$"; then
86-
echo "Skipping broken file: $target_file"
87-
continue
88-
fi
89-
96+
if echo "$BROKEN_FILES" | grep -q "^$target_file$"; then
97+
echo "Skipping broken file: $target_file"
98+
continue
99+
fi
100+
90101
# Transform and copy the file
91102
echo "Transforming and copying $source_file to $DEST_DIR/$target_file"
92103
awk -f transform-docs.awk "$source_file" > "$DEST_DIR/$target_file"
93-
done
104+
done
105+
}
94106

95-
echo "Successfully copied all .md files to .mdx files in $DEST_DIR"
107+
# Copy from both sources
108+
transform_docs "$UPSTREAM_SITE"
109+
transform_docs "$REFERENCE_DOCS"
96110

97-
# Convert community YAML files to MDX
98111
echo "Converting community YAML files to MDX..."
99112
./convert-community-to-mdx.sh "$DEST_DIR/community/experts"
100113
./convert-community-to-mdx.sh "$DEST_DIR/community/partners"
101114

102-
# Copy community images to destination community/images/
103-
# We don't need to do this for images under a docs/ folder, so many other images already work
115+
echo "Copying community images..."
104116
mkdir -p "$DEST_DIR/community/images"
105117
cp upstream/site/en/community/images/* "$DEST_DIR/community/images/"
118+
119+
echo "Done copying docs."

0 commit comments

Comments
 (0)