|
47 | 47 | VITE_SENTRY_DSN: ${{ vars.WEB_SENTRY_DSN }} |
48 | 48 | VITE_SENTRY_RELEASE: web@${{ github.sha }} |
49 | 49 |
|
50 | | - - run: bun sst shell --stage=${{ github.ref_name }} -- bun run --cwd packages/stats/core db:ensure-unique-users |
| 50 | + - if: github.ref_name != 'production' |
| 51 | + run: bun sst shell --stage=${{ github.ref_name }} -- bun run --cwd packages/stats/core db:ensure-unique-users |
51 | 52 | env: |
52 | 53 | CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
53 | 54 | PLANETSCALE_SERVICE_TOKEN_NAME: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_NAME }} |
|
60 | 61 | SENTRY_RELEASE: web@${{ github.sha }} |
61 | 62 | VITE_SENTRY_DSN: ${{ vars.WEB_SENTRY_DSN }} |
62 | 63 | VITE_SENTRY_RELEASE: web@${{ github.sha }} |
| 64 | + |
| 65 | + - if: github.ref_name == 'production' |
| 66 | + uses: planetscale/setup-pscale-action@v1 |
| 67 | + |
| 68 | + - if: github.ref_name == 'production' |
| 69 | + run: | |
| 70 | + set -euo pipefail |
| 71 | +
|
| 72 | + database="opencode-stats" |
| 73 | + organization="anomalyco" |
| 74 | + branch="unique-users-${GITHUB_SHA::12}" |
| 75 | + password_id="" |
| 76 | +
|
| 77 | + cleanup() { |
| 78 | + if [ -n "$password_id" ]; then |
| 79 | + pscale password delete "$database" "$branch" "$password_id" --org "$organization" --force >/dev/null 2>&1 || true |
| 80 | + fi |
| 81 | + pscale branch delete "$database" "$branch" --org "$organization" --force >/dev/null 2>&1 || true |
| 82 | + } |
| 83 | +
|
| 84 | + trap cleanup EXIT |
| 85 | +
|
| 86 | + if bun sst shell --stage=production -- bun run --cwd packages/stats/core db:check-unique-users; then |
| 87 | + echo "unique_users columns already exist in production" |
| 88 | + exit 0 |
| 89 | + fi |
| 90 | +
|
| 91 | + pscale branch delete "$database" "$branch" --org "$organization" --force >/dev/null 2>&1 || true |
| 92 | + pscale branch create "$database" "$branch" --org "$organization" --from production --wait |
| 93 | +
|
| 94 | + response="$(pscale password create "$database" "$branch" "unique-users-${GITHUB_RUN_ID}" --org "$organization" --format json)" |
| 95 | + password_id="$(echo "$response" | jq -r '.id')" |
| 96 | +
|
| 97 | + export PLANETSCALE_HOST="$(echo "$response" | jq -r '.access_host_url')" |
| 98 | + export PLANETSCALE_USERNAME="$(echo "$response" | jq -r '.username')" |
| 99 | + export PLANETSCALE_PASSWORD="$(echo "$response" | jq -r '.plain_text')" |
| 100 | + export PLANETSCALE_DATABASE="$database" |
| 101 | +
|
| 102 | + echo "::add-mask::$PLANETSCALE_PASSWORD" |
| 103 | + bun run --cwd packages/stats/core db:ensure-unique-users |
| 104 | +
|
| 105 | + deploy_response="$(pscale deploy-request create "$database" "$branch" --org "$organization" --deploy-to production --format json)" |
| 106 | + deploy_number="$(echo "$deploy_response" | jq -r '.number')" |
| 107 | +
|
| 108 | + if [ -z "$deploy_number" ] || [ "$deploy_number" = "null" ]; then |
| 109 | + echo "Could not read deploy request number" |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | +
|
| 113 | + pscale deploy-request review "$database" "$deploy_number" --org "$organization" --approve || true |
| 114 | + pscale deploy-request deploy "$database" "$deploy_number" --org "$organization" |
| 115 | + env: |
| 116 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 117 | + PLANETSCALE_SERVICE_TOKEN_NAME: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_NAME }} |
| 118 | + PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_NAME }} |
| 119 | + PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} |
| 120 | + STRIPE_SECRET_KEY: ${{ github.ref_name == 'production' && secrets.STRIPE_SECRET_KEY_PROD || secrets.STRIPE_SECRET_KEY_DEV }} |
| 121 | + HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }} |
| 122 | + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} |
| 123 | + SENTRY_ORG: ${{ vars.SENTRY_ORG }} |
| 124 | + SENTRY_PROJECT: ${{ vars.WEB_SENTRY_PROJECT }} |
| 125 | + SENTRY_RELEASE: web@${{ github.sha }} |
| 126 | + VITE_SENTRY_DSN: ${{ vars.WEB_SENTRY_DSN }} |
| 127 | + VITE_SENTRY_RELEASE: web@${{ github.sha }} |
0 commit comments