Skip to content

Apache DataFusion SQL Query Engine

dev: Add CI doc prettier check to local `rust_lint.sh` (#19254)

Yongting You33b3f0216479
diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml
index 1bd51fb895..1ec7c16b48 100644
--- a/.github/workflows/dev.yml
+++ b/.github/workflows/dev.yml
@@ -48,16 +48,8 @@ jobs:
with:
node-version: "20"
- name: Prettier check
- run: |
- # if you encounter error, rerun the command below and commit the changes
- #
- # ignore subproject CHANGELOG.md because they are machine generated
- npx [email protected] --write \
- '{datafusion,datafusion-cli,datafusion-examples,dev,docs}/**/*.md' \
- '!datafusion/CHANGELOG.md' \
- README.md \
- CONTRIBUTING.md
- git diff --exit-code
+ # if you encounter error, see instructions inside the script
+ run: ci/scripts/doc_prettier_check.sh
typos:
name: Spell Check with Typos
@@ -72,4 +64,4 @@ jobs:
- name: Install typos-cli
run: cargo install typos-cli --locked --version 1.37.0
- name: Run typos check
- run: ci/scripts/typos_check.sh
\ No newline at end of file
+ run: ci/scripts/typos_check.sh
diff --git a/ci/scripts/doc_prettier_check.sh b/ci/scripts/doc_prettier_check.sh
new file mode 100755
index 0000000000..d94a0d1c96
--- /dev/null
+++ b/ci/scripts/doc_prettier_check.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
+
+MODE="--check"
+ACTION="Checking"
+if [ $# -gt 0 ]; then
+ if [ "$1" = "--write" ]; then
+ MODE="--write"
+ ACTION="Formatting"
+ else
+ echo "Usage: $0 [--write]" >&2
+ exit 1
+ fi
+fi
+
+echo "$SCRIPT_PATH: $ACTION documents with prettier"
+
+# Ensure `npx` is available
+if ! command -v npx >/dev/null 2>&1; then
+ echo "npx is required to run the prettier check. Install Node.js (e.g., brew install node) and re-run." >&2
+ exit 1
+fi
+
+# Ignore subproject CHANGELOG.md because it is machine generated
+npx [email protected] $MODE \
+ '{datafusion,datafusion-cli,datafusion-examples,dev,docs}/**/*.md' \
+ '!datafusion/CHANGELOG.md' \
+ README.md \
+ CONTRIBUTING.md
+status=$?
+
+if [ $status -ne 0 ]; then
+ if [ "$MODE" = "--check" ]; then
+ echo "Prettier check failed. Re-run with --write (e.g., ./ci/scripts/doc_prettier_check.sh --write) to format files, commit the changes, and re-run the check." >&2
+ else
+ echo "Prettier format failed. Files may have been modified; commit any changes and re-run." >&2
+ fi
+ exit $status
+fi
diff --git a/dev/rust_lint.sh b/dev/rust_lint.sh
index 490720c537..21d4611846 100755
--- a/dev/rust_lint.sh
+++ b/dev/rust_lint.sh
@@ -49,3 +49,4 @@ ci/scripts/rust_toml_fmt.sh
ci/scripts/rust_docs.sh
ci/scripts/license_header.sh
ci/scripts/typos_check.sh
+ci/scripts/doc_prettier_check.sh