Migrate to using taskfiles

This commit is contained in:
Andras Schmelczer 2026-01-12 22:42:09 +00:00
parent 0e1849061b
commit 6ea7d53a49
21 changed files with 564 additions and 391 deletions

25
taskfiles/database.yml Normal file
View file

@ -0,0 +1,25 @@
version: "3"
vars:
DATABASE_URL: "sqlite://db.sqlite3"
MIGRATIONS_PATH: "src/app_state/database/migrations"
tasks:
setup:
desc: Create and migrate database
sources:
- "{{.MIGRATIONS_PATH}}/**/*.sql"
generates:
- "db.sqlite3"
cmds:
- which sqlx || cargo install sqlx-cli
- sqlx database create --database-url {{.DATABASE_URL}} 2>/dev/null || true
- sqlx migrate run --source {{.MIGRATIONS_PATH}} --database-url {{.DATABASE_URL}}
- cargo sqlx prepare --workspace
add-migration:
desc: Add a new migration
requires:
vars: [NAME]
cmds:
- sqlx migrate add --source {{.MIGRATIONS_PATH}} {{.NAME}}

35
taskfiles/docs.yml Normal file
View file

@ -0,0 +1,35 @@
version: "3"
tasks:
install:
desc: Install docs dependencies
run: once
cmds:
- npm ci
build:
desc: Build documentation
deps: [install]
cmds:
- npm run build
lint:
desc: Check formatting and spelling
deps: [install]
cmds:
- npm run format:check
- npm run spell:check
check:
desc: Run all documentation checks
cmds:
- task: :check-node
- task: install
- task: lint
- task: build
dev:
desc: Start documentation dev server
deps: [install]
cmds:
- npm run dev

134
taskfiles/e2e.yml Normal file
View file

@ -0,0 +1,134 @@
version: "3"
vars:
SERVER_URL: "http://localhost:3000"
MAX_RETRIES: 30
RETRY_INTERVAL: 5
LOG_DIR: "{{.ROOT_DIR}}/logs"
tasks:
run:
desc: Run E2E tests with specified number of processes
summary: |
Runs multiple concurrent test clients against the sync server.
Each client performs random file operations to test synchronization.
Usage: task e2e -- <process_count>
Example: task e2e -- 8
deps: [prepare]
requires:
vars: [PROCESS_COUNT]
preconditions:
- sh: test "{{.PROCESS_COUNT}}" -ge 1 2>/dev/null
msg: "PROCESS_COUNT must be a positive integer (got: {{.PROCESS_COUNT}})"
dir: "{{.ROOT_DIR}}"
env:
NO_COLOR: "1"
FORCE_COLOR: "0"
cmds:
- task: wait-for-server
- task: setup-logs
- defer: { task: cleanup-pipes }
- task: spawn-clients
prepare:
desc: Build frontend for E2E tests
internal: true
dir: "{{.ROOT_DIR}}"
cmds:
- task: :check-node
- task: :frontend:build
wait-for-server:
desc: Wait for server to become available
internal: true
silent: true
cmds:
- for: { var: ATTEMPTS, split: "\n" }
cmd: |
if curl -s -f -o /dev/null {{.SERVER_URL}}; then
echo "Server available at {{.SERVER_URL}}"
exit 0
fi
echo "Attempt {{.ITEM}}/{{.MAX_RETRIES}}: waiting {{.RETRY_INTERVAL}}s..."
sleep {{.RETRY_INTERVAL}}
if [ "{{.ITEM}}" = "{{.MAX_RETRIES}}" ]; then
echo "Error: Server not available after {{.MAX_RETRIES}} attempts"
exit 1
fi
vars:
ATTEMPTS:
sh: seq 1 {{.MAX_RETRIES}}
setup-logs:
internal: true
status:
- test -d {{.LOG_DIR}}
cmds:
- mkdir -p {{.LOG_DIR}}
cleanup-pipes:
internal: true
cmds:
- rm -f /tmp/vaultlink_pipe_* 2>/dev/null || true
spawn-clients:
internal: true
dir: "{{.ROOT_DIR}}/frontend"
set: [errexit, pipefail]
cmds:
- |
pids=()
# Start all client processes
for i in $(seq 1 {{.PROCESS_COUNT}}); do
pipe="/tmp/vaultlink_pipe_$$_$i"
mkfifo "$pipe"
node test-client/dist/cli.js > "$pipe" 2>&1 &
pid=$!
pids+=($pid)
echo "Started client $i (PID: $pid)"
(sed "s/^/[PID $pid] /" < "$pipe" > "{{.LOG_DIR}}/log_${i}.log"; rm "$pipe") &
done
echo "Monitoring {{.PROCESS_COUNT}} client processes..."
# Monitor loop
while true; do
# Check for failures
for i in $(seq 1 {{.PROCESS_COUNT}}); do
idx=$((i-1))
pid=${pids[$idx]}
[ -z "$pid" ] && continue
if ! kill -0 $pid 2>/dev/null; then
wait $pid
code=$?
if [ $code -ne 0 ]; then
echo "Client $i (PID $pid) failed with exit code $code"
echo "===== Log: {{.LOG_DIR}}/log_${i}.log ====="
cat "{{.LOG_DIR}}/log_${i}.log"
# Kill remaining processes
for p in "${pids[@]}"; do
[ -n "$p" ] && kill $p 2>/dev/null || true
done
exit 1
fi
echo "Client $i (PID $pid) completed successfully"
pids[$idx]=""
fi
done
# Check if all done
all_done=true
for pid in "${pids[@]}"; do
[ -n "$pid" ] && kill -0 $pid 2>/dev/null && all_done=false && break
done
if $all_done; then
echo "All {{.PROCESS_COUNT}} clients completed successfully"
exit 0
fi
sleep 0.2
done

41
taskfiles/frontend.yml Normal file
View file

@ -0,0 +1,41 @@
version: "3"
tasks:
install:
desc: Install frontend dependencies
run: once
cmds:
- npm ci
build:
desc: Build all frontend workspaces
deps: [install]
cmds:
- npm run build
test:
desc: Run all frontend tests
cmds:
- npm run test
lint:
desc: Lint and format TypeScript code
cmds:
- npm run lint
dev:
desc: Start development mode
cmds:
- npm run dev
workspace:
desc: Run npm script in specific workspace
summary: |
Run any npm script in a specific workspace.
Usage: task frontend:workspace WORKSPACE=<name> SCRIPT=<script>
Example: task frontend:workspace WORKSPACE=sync-client SCRIPT=build
requires:
vars: [WORKSPACE, SCRIPT]
cmds:
- npm run {{.SCRIPT}} -w {{.WORKSPACE}}

44
taskfiles/release.yml Normal file
View file

@ -0,0 +1,44 @@
version: "3"
tasks:
bump:
desc: Bump version (usage - task release:bump -- patch|minor|major)
dir: "{{.ROOT_DIR}}"
requires:
vars:
- name: CLI_ARGS
enum: [patch, minor, major]
preconditions:
- sh: test -z "$(git status --porcelain)"
msg: "Working directory not clean. Commit or stash changes first."
vars:
BUMP_TYPE: "{{.CLI_ARGS}}"
cmds:
- echo "Creating {{.BUMP_TYPE}} release..."
- cd sync-server && cargo set-version --bump {{.BUMP_TYPE}}
- cd frontend && npm version {{.BUMP_TYPE}} --workspaces
- cp frontend/obsidian-plugin/manifest.json manifest.json
- task: :format
- |
git add .
TAG=$(node -p "require('./frontend/obsidian-plugin/package.json').version")
git commit -m "Bump versions to $TAG"
git push
git tag -a $TAG -m "Release $TAG"
git push origin $TAG
echo "Released $TAG"
create-release:
desc: Create GitHub release with all artifacts
dir: "{{.ROOT_DIR}}"
cmds:
- task: :db:setup
- task: :frontend:build
- task: :rust:build-binaries
- |
tag="${GITHUB_REF#refs/tags/}"
mkdir -p release
cp frontend/obsidian-plugin/dist/* release/
cp sync-server/artifacts/sync-server-* release/
cd release
gh release create "$tag" --title="$tag" --draft *

73
taskfiles/rust.yml Normal file
View file

@ -0,0 +1,73 @@
version: "3"
tasks:
build:
desc: Build sync-server
cmds:
- cargo build {{if .RELEASE}}--release{{end}}
test:
desc: Run Rust tests
cmds:
- cargo test --verbose
lint:
desc: Run all linters (clippy, fmt check, machete)
cmds:
- cargo fmt --all -- --check
- cargo clippy --all-targets --all-features
- cargo machete --with-metadata
lint-fix:
desc: Auto-fix linting issues (fmt, clippy)
cmds:
- cargo fmt --all
- cargo clippy --all-targets --all-features --fix --allow-dirty --allow-staged
run:
desc: Run the sync server
cmds:
- cargo run {{.CONFIG | default "config-e2e.yml"}} {{if .NO_COLOR}}--color never{{end}}
export-bindings:
desc: Export TypeScript bindings
cmds:
- cargo test export_bindings
build-binaries:
desc: Build cross-platform release binaries
summary: |
Builds release binaries for multiple platforms.
Default targets: linux-x86_64, linux-x86_64-musl, linux-aarch64, windows-x86_64
Override with: task rust:build-binaries TARGETS="x86_64-unknown-linux-gnu"
vars:
TARGETS: '{{.TARGETS | default "x86_64-unknown-linux-gnu x86_64-unknown-linux-musl aarch64-unknown-linux-gnu x86_64-pc-windows-gnu"}}'
cmds:
- mkdir -p artifacts
- rm -f artifacts/sync-server-*
- for: { var: TARGETS }
task: build-target
vars:
TARGET: "{{.ITEM}}"
build-target:
internal: true
label: "build-{{.TARGET}}"
vars:
EXT: '{{if contains "windows" .TARGET}}.exe{{end}}'
LINKER_VAR: >-
{{if eq .TARGET "aarch64-unknown-linux-gnu"}}CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
{{else if eq .TARGET "x86_64-unknown-linux-musl"}}CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc
{{else if eq .TARGET "x86_64-pc-windows-gnu"}}CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc
{{end}}
OUTPUT_NAME: >-
{{.TARGET | replace "x86_64-unknown-linux-gnu" "linux-x86_64"
| replace "x86_64-unknown-linux-musl" "linux-x86_64-musl"
| replace "aarch64-unknown-linux-gnu" "linux-aarch64"
| replace "x86_64-pc-windows-gnu" "windows-x86_64"}}
cmds:
- rustup target add {{.TARGET}} 2>/dev/null || true
- '{{.LINKER_VAR}} cargo build --release --target {{.TARGET}}'
- cp target/{{.TARGET}}/release/sync_server{{.EXT}} artifacts/sync-server-{{.OUTPUT_NAME}}{{.EXT}}
- echo "Built sync-server-{{.OUTPUT_NAME}}{{.EXT}}"