Skip to content

Commit 33b3f02

Browse files
authored
dev: Add CI doc prettier check to local rust_lint.sh (#19254)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> A small step towards #19227 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> - Move doc prettier check command to a local script - Add this script to the lint-check runner `dev/rust_lint.sh` to make local development easier (Technically it's neither rust nor lint, but keeping all non functional tests here seem to be the most convenient.) ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent 044a4a7 commit 33b3f02

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

.github/workflows/dev.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,8 @@ jobs:
4848
with:
4949
node-version: "20"
5050
- name: Prettier check
51-
run: |
52-
# if you encounter error, rerun the command below and commit the changes
53-
#
54-
# ignore subproject CHANGELOG.md because they are machine generated
55-
npx prettier@2.7.1 --write \
56-
'{datafusion,datafusion-cli,datafusion-examples,dev,docs}/**/*.md' \
57-
'!datafusion/CHANGELOG.md' \
58-
README.md \
59-
CONTRIBUTING.md
60-
git diff --exit-code
51+
# if you encounter error, see instructions inside the script
52+
run: ci/scripts/doc_prettier_check.sh
6153

6254
typos:
6355
name: Spell Check with Typos
@@ -72,4 +64,4 @@ jobs:
7264
- name: Install typos-cli
7365
run: cargo install typos-cli --locked --version 1.37.0
7466
- name: Run typos check
75-
run: ci/scripts/typos_check.sh
67+
run: ci/scripts/typos_check.sh

ci/scripts/doc_prettier_check.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
21+
22+
MODE="--check"
23+
ACTION="Checking"
24+
if [ $# -gt 0 ]; then
25+
if [ "$1" = "--write" ]; then
26+
MODE="--write"
27+
ACTION="Formatting"
28+
else
29+
echo "Usage: $0 [--write]" >&2
30+
exit 1
31+
fi
32+
fi
33+
34+
echo "$SCRIPT_PATH: $ACTION documents with prettier"
35+
36+
# Ensure `npx` is available
37+
if ! command -v npx >/dev/null 2>&1; then
38+
echo "npx is required to run the prettier check. Install Node.js (e.g., brew install node) and re-run." >&2
39+
exit 1
40+
fi
41+
42+
# Ignore subproject CHANGELOG.md because it is machine generated
43+
npx prettier@2.7.1 $MODE \
44+
'{datafusion,datafusion-cli,datafusion-examples,dev,docs}/**/*.md' \
45+
'!datafusion/CHANGELOG.md' \
46+
README.md \
47+
CONTRIBUTING.md
48+
status=$?
49+
50+
if [ $status -ne 0 ]; then
51+
if [ "$MODE" = "--check" ]; then
52+
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
53+
else
54+
echo "Prettier format failed. Files may have been modified; commit any changes and re-run." >&2
55+
fi
56+
exit $status
57+
fi

dev/rust_lint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ ci/scripts/rust_toml_fmt.sh
4949
ci/scripts/rust_docs.sh
5050
ci/scripts/license_header.sh
5151
ci/scripts/typos_check.sh
52+
ci/scripts/doc_prettier_check.sh

0 commit comments

Comments
 (0)