#!/usr/bin/env sh
set -eu

assert_contains() {
  file="$1"
  pattern="$2"
  if ! grep -Fq "$pattern" "$file"; then
    echo "missing pattern in $file: $pattern" >&2
    exit 1
  fi
}

for workflow in \
  ".gitea/workflows/staging_code_pull.yml" \
  ".gitea/workflows/staging_release.yml"
do
  assert_contains "$workflow" "APP_ENV=stage"
  assert_contains "$workflow" "BACKEND_LOG_LEVEL=debug"
  assert_contains "$workflow" "CLIENT_LOG_DEBUG=true"
  assert_contains "$workflow" 'BACKEND_PUBLIC_URL=${{ vars.BACKEND_URL }}'
done

assert_contains ".gitea/workflows/staging_release.yml" "scp adminfront/seed-tenant.csv"
assert_contains "docker/docker-compose.staging.template.yaml" "SEED_TENANT_CSV_PATH=/app/seed-tenant.csv"
assert_contains "docker/docker-compose.staging.template.yaml" "./adminfront/seed-tenant.csv:/app/seed-tenant.csv:ro"
assert_contains "docker/staging_pull_compose.template.yaml" "SEED_TENANT_CSV_PATH=/app/seed-tenant.csv"
assert_contains "docker/staging_pull_compose.template.yaml" "./adminfront/seed-tenant.csv:/app/seed-tenant.csv:ro"

echo "staging workflow env checks passed"
