version: '3' tasks: auth: desc: "Authenticates with Pantheon" silent: true cmds: - if [ -z "$TERMINUS_MACHINE_TOKEN" ]; then echo "❌ TERMINUS_MACHINE_TOKEN is not set. Add it to ~/.ddev/global_config.yaml (web-environment) or your project .env file."; exit 1; fi - echo "⚡ Authorizing with Pantheon..." - terminus auth:login --machine-token="$TERMINUS_MACHINE_TOKEN" >/dev/null 2>&1 || { echo "❌ Authentication failed. Check TERMINUS_MACHINE_TOKEN in ~/.ddev/global_config.yaml or your project .env file."; exit 1; } - echo "✅ Authentication successful." fetch-db: desc: "Fetches a database from Pantheon" silent: true env: DB_DIR: '{{default "/var/www/html/files/db" .DB_DIR}}' ENVIRONMENT: '{{default "live" .ENVIRONMENT}}' PANTHEON_SITE_ID: '{{.PANTHEON_SITE_ID}}' cmds: - if [ -z "$PANTHEON_SITE_ID" ]; then echo "❌ PANTHEON_SITE_ID is not set. Please add it to your .env file."; exit 1; fi - mkdir -p $DB_DIR - rm -f $DB_DIR/db.sql.gz $DB_DIR/db.sql - task: auth - echo "⚡ Fetching database from Pantheon..." - | TMPFILE=$(mktemp) terminus backup:get "${PANTHEON_SITE_ID}.${ENVIRONMENT}" --element=db --to=$DB_DIR/db.sql.gz 2>"$TMPFILE" || { echo "❌ Database fetch failed." echo "Details: $(cat "$TMPFILE")" rm -f "$TMPFILE" exit 1 } rm -f "$TMPFILE" - echo "✅ Database fetch complete." prepare-multidev: desc: "Creates or wipes a Pantheon multidev and optionally clones content from another environment" cmds: - | echo "{{.site}}" | grep -qE '^[a-zA-Z0-9_-]+$' || { echo "ERROR: site must contain only alphanumeric characters, underscores, and hyphens."; exit 1; } echo "{{default "dev" .clone_from}}" | grep -qE '^[a-zA-Z0-9._-]+$' || { echo "ERROR: clone_from must contain only alphanumeric characters, periods, underscores, and hyphens."; exit 1; } - | # Abort on the first failing terminus command so the failure is # attributable, instead of being masked by a later command's exit code. set -e SITE="{{.site}}" MULTIDEV="{{.multidev}}" CLONE_FROM="{{default "dev" .clone_from}}" SKIP_WIPE="{{default "false" .skip_wipe}}" RUN_INSTALLER="{{default "false" .run_installer}}" if terminus env:info "$SITE.$MULTIDEV" > /dev/null 2>&1; then echo "ℹ️ Multidev $SITE.$MULTIDEV already exists." if [ "$SKIP_WIPE" != "true" ]; then echo "⚡ Wiping $SITE.$MULTIDEV..." terminus env:wipe "$SITE.$MULTIDEV" --yes fi else echo "⚡ Creating multidev $SITE.$MULTIDEV from $SITE.$CLONE_FROM..." if [ "$SKIP_WIPE" != "true" ]; then terminus multidev:create "$SITE.$CLONE_FROM" "$MULTIDEV" --no-db --no-files --yes else terminus multidev:create "$SITE.$CLONE_FROM" "$MULTIDEV" --yes fi ACTUAL_NAME=$(terminus multidev:list --format json "$SITE" | jq -r --arg name "$MULTIDEV" '.[] | select(.id | startswith($name[:11])) | .id') echo "MULTIDEV_NAME=$ACTUAL_NAME" fi if [ "$SKIP_WIPE" != "true" ] && [ "$RUN_INSTALLER" != "true" ]; then echo "⚡ Cloning content from $SITE.$CLONE_FROM to $SITE.$MULTIDEV..." terminus env:clone-content "$SITE.$CLONE_FROM" "$MULTIDEV" --yes fi echo "✅ prepare-multidev complete for $SITE.$MULTIDEV." drupal-update: desc: "Waits for Pantheon sync then runs Drupal updates or site installer" cmds: - | # Abort on the first failing terminus command so the failure is attributable. set -e SITE="{{.site}}" ENVIRONMENT="{{.environment}}" SKIP_WAIT="{{default "false" .skip_workflow_wait}}" RUN_INSTALLER="{{default "false" .run_installer}}" TIMEOUT="{{default "600" .timeout}}" if [ "$SKIP_WAIT" != "true" ]; then echo "⚡ Waiting for Pantheon sync on $SITE.$ENVIRONMENT (max ${TIMEOUT}s)..." terminus workflow:wait --max "$TIMEOUT" "$SITE.$ENVIRONMENT" fi terminus aliases --only "$SITE" --yes if [ "$RUN_INSTALLER" = "true" ]; then ./vendor/bin/drush "@$SITE.$ENVIRONMENT" --yes site:install --existing-config elif ./vendor/bin/task -l | grep '* update: '; then ./vendor/bin/task update "site=@$SITE.$ENVIRONMENT" else ./vendor/bin/task drupal:update "site=@$SITE.$ENVIRONMENT" fi lock-env: desc: "Enables HTTP Basic Auth on a Pantheon environment (no-op if credentials are not set)" cmds: - | if [ -n "{{.username}}" ] && [ -n "{{.password}}" ]; then terminus lock:enable "{{.site}}.{{.environment}}" "{{.username}}" "{{.password}}" fi