Skip to content
Open
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
85 changes: 56 additions & 29 deletions ci/scripts/doc_prettier_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,68 @@
# 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
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
PRETTIER_VERSION="2.7.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to keep using this old version ?
Latest is https://www.npmjs.com/package/prettier/v/3.7.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think it's supposed to get updated manually.
We can do so separately since it might have a large code diff.

PRETTIER_TARGETS=(
'{datafusion,datafusion-cli,datafusion-examples,dev,docs}/**/*.md'
'!datafusion/CHANGELOG.md'
README.md
CONTRIBUTING.md
)

source "${SCRIPT_DIR}/utils/git.sh"

MODE="check"
ALLOW_DIRTY=0

usage() {
cat >&2 <<EOF
Usage: $SCRIPT_NAME [--write] [--allow-dirty]
Runs prettier@${PRETTIER_VERSION} over markdown docs.
--write Run with \`--write\` to format files (requires a clean git worktree, no uncommitted changes).
--allow-dirty Allow \`--write\` to run even when the git worktree has uncommitted changes.
EOF
exit 1
}

while [[ $# -gt 0 ]]; do
case "$1" in
--write)
MODE="write"
;;
--allow-dirty)
ALLOW_DIRTY=1
;;
-h|--help)
usage
;;
*)
usage
;;
esac
shift
done

if [[ "$MODE" == "write" && $ALLOW_DIRTY -eq 0 ]]; then
require_clean_work_tree "$SCRIPT_NAME" || exit 1
fi

echo "$SCRIPT_PATH: $ACTION documents with prettier"
echo "[${SCRIPT_NAME}] prettier@${PRETTIER_VERSION} ${MODE}"

# 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

PRETTIER_MODE=(--check)
if [[ "$MODE" == "write" ]]; then
PRETTIER_MODE=(--write)
fi

# Ignore subproject CHANGELOG.md because it is machine generated
npx "prettier@${PRETTIER_VERSION}" "${PRETTIER_MODE[@]}" "${PRETTIER_TARGETS[@]}"
62 changes: 59 additions & 3 deletions ci/scripts/license_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,62 @@
# specific language governing permissions and limitations
# under the License.

# Check Apache license header
set -ex
hawkeye check --config licenserc.toml
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"

source "${SCRIPT_DIR}/utils/git.sh"

MODE="check"
ALLOW_DIRTY=0
HAWKEYE_CONFIG="licenserc.toml"

usage() {
cat >&2 <<EOF
Usage: $SCRIPT_NAME [--write] [--allow-dirty]
Checks Apache license headers with \`hawkeye check --config $HAWKEYE_CONFIG\`.
--write Run \`hawkeye format --config $HAWKEYE_CONFIG\` to auto-add/fix headers (requires a clean git worktree, no uncommitted changes).
--allow-dirty Allow \`--write\` to run even when the git worktree has uncommitted changes.
EOF
exit 1
}

while [[ $# -gt 0 ]]; do
case "$1" in
--write)
MODE="write"
;;
--allow-dirty)
ALLOW_DIRTY=1
;;
-h|--help)
usage
;;
*)
usage
;;
esac
shift
done

if [[ "$MODE" == "write" && $ALLOW_DIRTY -eq 0 ]]; then
require_clean_work_tree "$SCRIPT_NAME" || exit 1
fi

if [[ "$MODE" == "write" ]]; then
echo "[${SCRIPT_NAME}] \`hawkeye format --config ${HAWKEYE_CONFIG}\`"
if ! hawkeye format --config "${HAWKEYE_CONFIG}"; then
status=$?
# hawkeye returns exit code 1 when it applies fixes; treat that as success.
if [[ $status -eq 1 ]]; then
echo "[${SCRIPT_NAME}] hawkeye format applied fixes (exit 1 treated as success)"
else
exit $status
fi
fi
else
echo "[${SCRIPT_NAME}] \`hawkeye check --config ${HAWKEYE_CONFIG}\`"
hawkeye check --config "${HAWKEYE_CONFIG}"
fi
59 changes: 57 additions & 2 deletions ci/scripts/rust_clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,60 @@
# specific language governing permissions and limitations
# under the License.

set -ex
cargo clippy --all-targets --workspace --features avro,integration-tests,extended_tests -- -D warnings
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
CLIPPY_FEATURES="avro,integration-tests,extended_tests"
CLIPPY_ARGS=(--all-targets --workspace --features "$CLIPPY_FEATURES")
CLIPPY_LINT_ARGS=(-- -D warnings)

source "${SCRIPT_DIR}/utils/git.sh"

MODE="check"
ALLOW_DIRTY=0

usage() {
cat >&2 <<EOF
Usage: $SCRIPT_NAME [--write] [--allow-dirty]

Runs \`cargo clippy\` to lint.
--write Run \`cargo clippy --fix\` to apply fixes for clippy lints (requires a clean git worktree, no uncommitted changes).
--allow-dirty Allow \`--write\` to run even when the git worktree has uncommitted or staged changes.
EOF
exit 1
}

while [[ $# -gt 0 ]]; do
case "$1" in
--write)
MODE="write"
;;
--allow-dirty)
ALLOW_DIRTY=1
;;
-h|--help)
usage
;;
*)
usage
;;
esac
shift
done

if [[ "$MODE" == "write" && $ALLOW_DIRTY -eq 0 ]]; then
require_clean_work_tree "$SCRIPT_NAME" || exit 1
fi

CLIPPY_CMD=(cargo clippy)
if [[ "$MODE" == "write" ]]; then
CLIPPY_CMD+=(--fix)
if [[ $ALLOW_DIRTY -eq 1 ]]; then
CLIPPY_CMD+=(--allow-dirty --allow-staged)
fi
fi
CLIPPY_CMD+=("${CLIPPY_ARGS[@]}" "${CLIPPY_LINT_ARGS[@]}")

echo "[${SCRIPT_NAME}] \`${CLIPPY_CMD[*]}\`"
"${CLIPPY_CMD[@]}"
1 change: 1 addition & 0 deletions ci/scripts/rust_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.

# Note: cargo doc does not support an auto-fix mode; this script runs the check-only build.
set -ex
export RUSTDOCFLAGS="-D warnings"
cargo doc --document-private-items --no-deps --workspace
51 changes: 49 additions & 2 deletions ci/scripts/rust_fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,52 @@
# specific language governing permissions and limitations
# under the License.

set -ex
cargo fmt --all -- --check
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
source "${SCRIPT_DIR}/utils/git.sh"

MODE="check"
ALLOW_DIRTY=0

usage() {
cat >&2 <<EOF
Usage: $0 [--write] [--allow-dirty]

Runs \`cargo fmt --all -- --check\` by default to verify Rust formatting.
--write Run \`cargo fmt --all\` to auto-fix formatting (requires a clean git worktree, no uncommitted changes).
--allow-dirty Allow \`--write\` to run even when the git worktree has uncommitted changes.
EOF
exit 1
}

while [[ $# -gt 0 ]]; do
case "$1" in
--write)
MODE="write"
;;
--allow-dirty)
ALLOW_DIRTY=1
;;
-h|--help)
usage
;;
*)
usage
;;
esac
shift
done

if [[ "$MODE" == "write" && $ALLOW_DIRTY -eq 0 ]]; then
require_clean_work_tree "$SCRIPT_NAME" || exit 1
fi

if [[ "$MODE" == "write" ]]; then
echo "[${SCRIPT_NAME}] \`cargo fmt --all\`"
cargo fmt --all
else
echo "[${SCRIPT_NAME}] \`cargo fmt --all -- --check\`"
cargo fmt --all -- --check
fi
55 changes: 50 additions & 5 deletions ci/scripts/rust_toml_fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,53 @@
# specific language governing permissions and limitations
# under the License.

# Run `taplo format` with flag `--check` in dry run to check formatting
# without overwritng the file. If any error occur, you may want to
# rerun `taplo format` to fix the formatting automatically.
set -ex
taplo format --check
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"

source "${SCRIPT_DIR}/utils/git.sh"

MODE="check"
ALLOW_DIRTY=0

usage() {
cat >&2 <<EOF
Usage: $0 [--write] [--allow-dirty]

Runs \`taplo format --check\` by default to verify TOML formatting.
--write Run \`taplo format\` to auto-fix formatting (best-effort; requires a clean git worktree, no uncommitted changes).
--allow-dirty Allow \`--write\` to run even when the git worktree has uncommitted changes.
EOF
exit 1
}

while [[ $# -gt 0 ]]; do
case "$1" in
--write)
MODE="write"
;;
--allow-dirty)
ALLOW_DIRTY=1
;;
-h|--help)
usage
;;
*)
usage
;;
esac
shift
done

if [[ "$MODE" == "write" && $ALLOW_DIRTY -eq 0 ]]; then
require_clean_work_tree "$SCRIPT_NAME" || exit 1
fi

if [[ "$MODE" == "write" ]]; then
echo "[${SCRIPT_NAME}] \`taplo format\`"
taplo format
else
echo "[${SCRIPT_NAME}] \`taplo format --check\`"
taplo format --check
fi
Loading