crosscode script: deploy, status, install, adopt (Events 2.2.0, plan §4-5)
One script for installing, updating and moving church installs, replacing hope-events' scripts/deploy.sh and install.sh: - deploy <church> [events] / --every-church, with --version, --main, --check and --allow-local-changes: checks every product first (files changed by hand, Node, release requirements from WHATS-NEW.md headings), then each product in order with backup, checkout, install, migrate, build, PM2 reload and a /health version check; a failure rolls that product back and stops. - status [<church>]: checked-out and latest release, /health, and the old folder kept after adopt. - install <church> --products events --domain <address>: a new church under /var/www/sites/<church>, writing church.env. - adopt <church> --events-dir <old> builds the monorepo checkout next to the running install and switches PM2 over; adopt --undo goes back to it. Product hooks live in scripts/products/events.sh. shellcheck (lint:scripts) and 47 bats tests (test:scripts) are part of npm run check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bats
|
||||
# adopt's helpers that don't need a server: rewriting the PM2 config, and finding the install's
|
||||
# own data files. Run with `npm run test:scripts`.
|
||||
|
||||
setup() {
|
||||
# shellcheck source=../lib/common.sh
|
||||
source "$BATS_TEST_DIRNAME/../lib/common.sh"
|
||||
# shellcheck source=../lib/adopt.sh
|
||||
source "$BATS_TEST_DIRNAME/../lib/adopt.sh"
|
||||
TMP="$BATS_TEST_TMPDIR"
|
||||
}
|
||||
|
||||
@test "rewrite_ecosystem points absolute paths at the new app folder" {
|
||||
run rewrite_ecosystem /var/www/hope-events /var/www/sites/hope/events/apps/events <<'EOF'
|
||||
module.exports = { apps: [
|
||||
{ name: 'hope-events-backend', cwd: '/var/www/hope-events/backend', script: 'src/index.js' },
|
||||
{ name: 'hope-events-frontend', cwd: "/var/www/hope-events/frontend", script: 'npm', args: 'start -- -p 3000' },
|
||||
{ name: 'x', cwd: `/var/www/hope-events`, out_file: '/var/www/hope-events2/log' },
|
||||
] };
|
||||
EOF
|
||||
[[ "$output" == *"cwd: '/var/www/sites/hope/events/apps/events/backend'"* ]]
|
||||
[[ "$output" == *'cwd: "/var/www/sites/hope/events/apps/events/frontend"'* ]]
|
||||
[[ "$output" == *'cwd: `/var/www/sites/hope/events/apps/events`'* ]]
|
||||
# A different folder that only starts the same isn't touched.
|
||||
[[ "$output" == *"'/var/www/hope-events2/log'"* ]]
|
||||
[[ "$output" == *"name: 'hope-events-backend'"* ]]
|
||||
}
|
||||
|
||||
@test "rewrite_ecosystem leaves __dirname configs alone" {
|
||||
input="$(cat "$BATS_TEST_DIRNAME/../../apps/events/ecosystem.config.example.js")"
|
||||
run rewrite_ecosystem /var/www/hope-events /var/www/sites/hope/events/apps/events <<< "$input"
|
||||
[ "$output" = "$input" ]
|
||||
}
|
||||
|
||||
@test "rewrite_ecosystem copes with dots and other characters in paths" {
|
||||
run rewrite_ecosystem /opt/hope.events /srv/a\&b <<'EOF'
|
||||
cwd: '/opt/hope.events/backend', other: '/opt/hopexevents/backend'
|
||||
EOF
|
||||
[ "$output" = "cwd: '/srv/a&b/backend', other: '/opt/hopexevents/backend'" ]
|
||||
}
|
||||
|
||||
@test "ignored_files_in lists the install's own data files, not tracked ones" {
|
||||
git init -q "$TMP/old"
|
||||
cd "$TMP/old"
|
||||
mkdir -p backend/data
|
||||
printf 'backend/data/banner.json\n' > .gitignore
|
||||
echo '{}' > backend/data/defaults.json
|
||||
git add . && git -c user.name=t -c user.email=t@t commit -q -m one
|
||||
echo '{}' > backend/data/banner.json
|
||||
run ignored_files_in "$TMP/old" backend/data
|
||||
[ "$output" = "backend/data/banner.json" ]
|
||||
}
|
||||
Reference in New Issue
Block a user