mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
ci: overhaul CI workflows for reliability and maintainability
- add CODEOWNERS assigning .github/ to @neonsolstice - configure automated updates for npm, docker, and github-actions ecosystems - replace custom change-detection bash script with dorny/paths-filter@v4 - consolidate lint, typecheck, and test into a single checks matrix job - gate per-package change detection via has-changes step (matrix unavailable in job-level if) - fix duplicate actions/setup-node call in setup-node-pnpm composite action - scope pnpm store cache key by pnpm version to prevent stale cross-version cache hits - pin all action references to commit SHAs - fix container-image concurrency group to use commit SHA across all trigger types - add timeout-minutes to all jobs - document fail-fast: false rationale and checks: write trade-off
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
ENV_FILE="${1:-.env.prod}"
|
||||
OUT_DIR="${2:-$ROOT_DIR/local/backups}"
|
||||
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "Missing env file: $ENV_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$ENV_FILE"
|
||||
set +a
|
||||
|
||||
: "${POSTGRES_USER:?POSTGRES_USER is required}"
|
||||
: "${POSTGRES_DB:?POSTGRES_DB is required}"
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
|
||||
backup_file="$OUT_DIR/projectx-${POSTGRES_DB}-${timestamp}.dump"
|
||||
|
||||
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml up -d --wait postgres
|
||||
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml exec -T postgres \
|
||||
pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc >"$backup_file"
|
||||
|
||||
echo "Backup created: $backup_file"
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
ENV_FILE="${1:-.env.prod}"
|
||||
BACKUP_FILE="${2:-}"
|
||||
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "Missing env file: $ENV_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$BACKUP_FILE" || ! -f "$BACKUP_FILE" ]]; then
|
||||
echo "Usage: $0 <env-file> <backup-file.dump>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$ENV_FILE"
|
||||
set +a
|
||||
|
||||
: "${POSTGRES_USER:?POSTGRES_USER is required}"
|
||||
: "${POSTGRES_DB:?POSTGRES_DB is required}"
|
||||
|
||||
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml up -d --wait postgres
|
||||
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml exec -T postgres \
|
||||
psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$POSTGRES_DB' AND pid <> pg_backend_pid();" >/dev/null
|
||||
|
||||
cat "$BACKUP_FILE" | docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml exec -T postgres \
|
||||
pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB" --clean --if-exists --no-owner --no-privileges
|
||||
|
||||
echo "Restore complete: $BACKUP_FILE -> $POSTGRES_DB"
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
ENV_FILE="${1:-.env.prod}"
|
||||
BACKUP_FILE="${2:-}"
|
||||
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "Missing env file: $ENV_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$BACKUP_FILE" || ! -f "$BACKUP_FILE" ]]; then
|
||||
echo "Usage: $0 <env-file> <backup-file.dump>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$ENV_FILE"
|
||||
set +a
|
||||
|
||||
: "${POSTGRES_USER:?POSTGRES_USER is required}"
|
||||
: "${POSTGRES_DB:?POSTGRES_DB is required}"
|
||||
|
||||
test_db="${POSTGRES_DB}_restore_test_$(date -u +%Y%m%d%H%M%S)"
|
||||
|
||||
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml up -d --wait postgres
|
||||
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml exec -T postgres \
|
||||
psql -U "$POSTGRES_USER" -d postgres -c "CREATE DATABASE \"$test_db\";" >/dev/null
|
||||
|
||||
cleanup() {
|
||||
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml exec -T postgres \
|
||||
psql -U "$POSTGRES_USER" -d postgres -c "DROP DATABASE IF EXISTS \"$test_db\";" >/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
cat "$BACKUP_FILE" | docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml exec -T postgres \
|
||||
pg_restore -U "$POSTGRES_USER" -d "$test_db" --no-owner --no-privileges >/dev/null
|
||||
|
||||
table_count="$(
|
||||
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml exec -T postgres \
|
||||
psql -U "$POSTGRES_USER" -d "$test_db" -Atc "SELECT count(*) FROM information_schema.tables WHERE table_schema='public';"
|
||||
)"
|
||||
|
||||
echo "Restore test succeeded: $BACKUP_FILE -> $test_db (${table_count} public tables)"
|
||||
Reference in New Issue
Block a user