This commit is contained in:
Andras Schmelczer 2025-10-18 15:36:49 +01:00
parent 0c42c23669
commit 352c71af65
185 changed files with 20165 additions and 0 deletions

View file

@ -0,0 +1,44 @@
#!/bin/bash
set -e
cd "$(dirname "$0")/../sync-server"
# Setup database
sqlx database create --database-url sqlite://db.sqlite3 2>/dev/null || true
sqlx migrate run --source src/app_state/database/migrations --database-url sqlite://db.sqlite3
targets=${@:-"x86_64-unknown-linux-gnu x86_64-unknown-linux-musl aarch64-unknown-linux-gnu x86_64-pc-windows-gnu"}
mkdir -p artifacts
rm -f artifacts/sync-server-*
for target in $targets; do
echo "Building $target..."
# Set linkers for cross-compilation
case "$target" in
aarch64-unknown-linux-gnu)
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc ;;
x86_64-unknown-linux-musl)
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc ;;
x86_64-pc-windows-gnu)
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc ;;
esac
rustup target add "$target" 2>/dev/null || true
cargo build --release --target "$target"
ext=""
[[ "$target" == *windows* ]] && ext=".exe"
name="sync-server-${target//-/_}$ext"
name="${name//x86_64_unknown_linux_gnu/linux-x86_64}"
name="${name//x86_64_unknown_linux_musl/linux-x86_64-musl}"
name="${name//aarch64_unknown_linux_gnu/linux-aarch64}"
name="${name//x86_64_pc_windows_gnu/windows-x86_64}"
cp "target/$target/release/sync_server$ext" "artifacts/$name"
echo "✓ Built $name"
done

45
scripts/bump-version.sh Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
set -e
if [[ -z $1 ]]; then
echo "Usage: $0 {patch|minor|major}"
exit 1
fi
if [[ $1 =~ ^(patch|minor|major)$ ]]; then
echo "Creating a new '$1' version"
else
echo "Invalid argument: $1"
echo "Usage: $0 {patch|minor|major}"
exit 1
fi
if [[ -n $(git status --porcelain) ]]; then
echo "Your working directory is not clean. Please commit or stash your changes before proceeding."
exit 1
else
echo "Your working directory is clean."
fi
echo "Bumping sync-server versions"
cd sync-server
cargo set-version --bump $1
echo "Bumping frontend versions"
cd ../frontend
npm version $1 --workspaces
cd ..
cp frontend/obsidian-plugin/manifest.json manifest.json # for BRAT, otherwise it wouldn't update
# Commit and tag
git add .
TAG=$(node -p "require('./frontend/obsidian-plugin/package.json').version")
git commit -m "Bump versions to $TAG"
git push
echo "Tagging $TAG"
git tag -a $TAG -m "Release $TAG"
git push origin $TAG
echo "Done"

27
scripts/check.sh Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e
echo "Running checks in sync-server"
cd sync-server
cargo test --verbose
cargo clippy --all-targets --all-features
cargo fmt --all -- --check
cargo machete
echo "Running checks in frontend"
cd ../frontend
npm ci
npm run build
npm run test
npm run lint
if [[ $(git status --porcelain) ]]; then
git status --porcelain
echo "Failing CI because the working directory is not clean after linting"
exit 1
fi
echo "Success"
cd ..

4
scripts/clean-up.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
rm -rf sync-server/databases
rm -rf logs

98
scripts/e2e.sh Executable file
View file

@ -0,0 +1,98 @@
#!/bin/bash
set -e
set -o pipefail
node_version=$(node -v | sed 's/^v\([0-9]*\).*/\1/')
if [ "$node_version" != "22" ]; then
echo "Error: This script requires Node.js version 22, found: $node_version"
exit 1
fi
# Check if the argument is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <number_of_processes>"
exit 1
fi
# Get the number of processes from the first argument
process_count=$1
mkdir -p logs
cd frontend
npm ci
npm run build
../scripts/utils/wait-for-server.sh
cd ..
scripts/update-api-types.sh
if [[ $(git status --porcelain) ]]; then
git status --porcelain
echo "Failing CI because the working directory is not clean after generating api types"
exit 1
fi
cd frontend
pids=()
for i in $(seq 1 $process_count); do
node test-client/dist/cli.js > "../logs/log_${i}.log" 2>&1 &
pids+=($!)
done
cd ..
print_failed_log() {
for i in $(seq 1 $process_count); do
if [ -n "${pids[$i-1]}" ] && ! kill -0 ${pids[$i-1]} 2>/dev/null; then
# Get the exit code of the process
wait ${pids[$i-1]}
exit_code=$?
# Only consider non-zero exit codes as failures
if [ $exit_code -ne 0 ]; then
cat "$(pwd)/logs/log_${i}.log"
echo "Process ${pids[$i-1]} failed with exit code $exit_code. Log file: $(pwd)/logs/log_${i}.log"
return 0
else
echo "Process ${pids[$i-1]} completed successfully with exit code 0"
# Mark this PID as processed by setting it to empty
pids[$i-1]=""
fi
fi
done
return 1
}
echo "Monitoring $process_count processes"
# Monitor processes
while true; do
if print_failed_log; then
# Kill remaining processes
for pid in "${pids[@]}"; do
if [ -n "$pid" ]; then
kill $pid 2>/dev/null || true
fi
done
exit 1
fi
# Check if all processes have completed
all_done=true
for pid in "${pids[@]}"; do
if [ -n "$pid" ] && kill -0 $pid 2>/dev/null; then
all_done=false
break
fi
done
if $all_done; then
echo "All processes completed successfully"
exit 0
fi
sleep 0.2
done

15
scripts/update-api-types.sh Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
set -e
rm -rf sync-server/bindings
cd sync-server
cargo test export_bindings
cd -
cp -r sync-server/bindings/* frontend/sync-client/src/services/types/
cd frontend
npm run lint || npx prettier --write sync-client/src/services/types/*.ts
cd -

View file

@ -0,0 +1,24 @@
#!/bin/bash
set -e
SERVER_URL="http://localhost:3000"
MAX_RETRIES=30
RETRY_INTERVAL_IN_SECONDS=5
echo "Waiting for $SERVER_URL to become available..."
count=0
while [ $count -lt $MAX_RETRIES ]; do
if curl -s -f -o /dev/null $SERVER_URL; then
echo "$SERVER_URL is now available!"
break
fi
echo "Attempt $(($count+1))/$MAX_RETRIES: $SERVER_URL not available yet, retrying in ${RETRY_INTERVAL_IN_SECONDS}s..."
sleep $RETRY_INTERVAL_IN_SECONDS
count=$(($count+1))
done
if [ $count -eq $MAX_RETRIES ]; then
echo "Error: $SERVER_URL did not become available after $MAX_RETRIES attempts."
exit 1
fi