|
46 | 46 | SENTRY_RELEASE: web@${{ github.sha }} |
47 | 47 | VITE_SENTRY_DSN: ${{ vars.WEB_SENTRY_DSN }} |
48 | 48 | VITE_SENTRY_RELEASE: web@${{ github.sha }} |
49 | | - |
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 |
52 | | - env: |
53 | | - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
54 | | - PLANETSCALE_SERVICE_TOKEN_NAME: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_NAME }} |
55 | | - PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} |
56 | | - STRIPE_SECRET_KEY: ${{ github.ref_name == 'production' && secrets.STRIPE_SECRET_KEY_PROD || secrets.STRIPE_SECRET_KEY_DEV }} |
57 | | - HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }} |
58 | | - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} |
59 | | - SENTRY_ORG: ${{ vars.SENTRY_ORG }} |
60 | | - SENTRY_PROJECT: ${{ vars.WEB_SENTRY_PROJECT }} |
61 | | - SENTRY_RELEASE: web@${{ github.sha }} |
62 | | - VITE_SENTRY_DSN: ${{ vars.WEB_SENTRY_DSN }} |
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 | | - if deploy_response="$(pscale deploy-request create "$database" "$branch" --org "$organization" --into production --format json 2>/tmp/deploy-request-error)"; then |
106 | | - : |
107 | | - elif deploy_response="$(pscale deploy-request create "$database" "$branch" --org "$organization" --deploy-to production --format json 2>>/tmp/deploy-request-error)"; then |
108 | | - : |
109 | | - else |
110 | | - cat /tmp/deploy-request-error |
111 | | - exit 1 |
112 | | - fi |
113 | | - deploy_number="$(echo "$deploy_response" | jq -r '.number')" |
114 | | -
|
115 | | - if [ -z "$deploy_number" ] || [ "$deploy_number" = "null" ]; then |
116 | | - echo "Could not read deploy request number" |
117 | | - exit 1 |
118 | | - fi |
119 | | -
|
120 | | - pscale deploy-request review "$database" "$deploy_number" --org "$organization" --approve || true |
121 | | - pscale deploy-request deploy "$database" "$deploy_number" --org "$organization" |
122 | | - env: |
123 | | - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
124 | | - PLANETSCALE_SERVICE_TOKEN_NAME: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_NAME }} |
125 | | - PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_NAME }} |
126 | | - PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} |
127 | | - STRIPE_SECRET_KEY: ${{ github.ref_name == 'production' && secrets.STRIPE_SECRET_KEY_PROD || secrets.STRIPE_SECRET_KEY_DEV }} |
128 | | - HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }} |
129 | | - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} |
130 | | - SENTRY_ORG: ${{ vars.SENTRY_ORG }} |
131 | | - SENTRY_PROJECT: ${{ vars.WEB_SENTRY_PROJECT }} |
132 | | - SENTRY_RELEASE: web@${{ github.sha }} |
133 | | - VITE_SENTRY_DSN: ${{ vars.WEB_SENTRY_DSN }} |
134 | | - VITE_SENTRY_RELEASE: web@${{ github.sha }} |
0 commit comments