mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-07 00:53:28 +00:00
8e8747a769
* Autoformat script * Executable + package.json * Fix pnpm format not exiting * Fix exit handling * Allow to only run fontend autoformat * Rename script to autoformat.sh - Fix exit handling * Add style check to CI - Replace deprecated actions-rs-plus/clippy-check@v2 with giraffate/clippy-action@v1 * Use HEAD as ancestor when running in CI * Improve uncommmited erro message * Increate timeout for Type and style check action * Run Clippy when ci.yml file changes * increase cypress timeout
76 lines
1.7 KiB
Bash
Executable file
76 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -Eeumo pipefail
|
|
|
|
has() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
handle_exit() {
|
|
_exit=$?
|
|
set +e
|
|
trap '' SIGINT
|
|
trap - EXIT
|
|
if [ "$_exit" -ne 0 ]; then
|
|
git restore --staged .
|
|
git restore .
|
|
fi
|
|
exit "$_exit"
|
|
}
|
|
|
|
cleanup() {
|
|
set +e
|
|
trap '' SIGINT
|
|
trap - EXIT
|
|
jobs -p | xargs kill -SIGTERM
|
|
git restore --staged .
|
|
git restore .
|
|
kill -- -$$ 2>/dev/null
|
|
}
|
|
|
|
if ! has git pnpm; then
|
|
echo "Missing at on of the required dependencies: git, pnpm" >&2
|
|
exit 1
|
|
fi
|
|
|
|
__dirname="$(CDPATH='' cd "$(dirname "$0")" && pwd -P)"
|
|
|
|
# Change to the root directory of the repository
|
|
cd "$__dirname/.."
|
|
|
|
if [ -n "$(git diff --name-only HEAD)" ] || [ -n "$(git ls-files --others --exclude-standard)" ]; then
|
|
echo "Uncommitted changes found. Please commit or stash your changes before running this script." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Find the common ancestor of the current branch and main
|
|
if [ -n "${CI:-}" ]; then
|
|
ancestor="HEAD"
|
|
elif ! ancestor="$(git merge-base HEAD origin/main)"; then
|
|
echo "Failed to find the common ancestor of the current branch and main." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Handle errors and cleanup after formating has started
|
|
trap 'handle_exit' EXIT
|
|
trap 'cleanup' SIGINT
|
|
|
|
# Run the linter and formatter for frontend
|
|
# Use a background processes to avoid pnpm weird handling of CTRL+C
|
|
pnpm run -r lint --fix &
|
|
wait
|
|
pnpm run format &
|
|
wait
|
|
|
|
if [ "${1:-}" != "only-frontend" ]; then
|
|
# Run clippy and formatter for backend
|
|
cargo clippy --fix --all --all-targets --all-features --allow-dirty --allow-staged
|
|
cargo fmt --all
|
|
fi
|
|
|
|
# Add all fixes for changes made in this branch
|
|
git diff --cached --name-only "$ancestor" | xargs git add
|
|
|
|
# Restore unrelated changes
|
|
git restore .
|