Repository navigation
90 lines (78 loc) · 3.06 KB
/
Copy pathteardown_examples_pr_stack.yml
File metadata and controls
90 lines (78 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Teardown Examples PR stack
on:
pull_request:
paths: ['examples/*/**']
types: [closed]
concurrency:
group: examples-pr-${{ github.event.number }}
jobs:
example-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.create-example-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Create example matrix
id: create-example-matrix
run: node scripts/ci/example-matrix.mjs teardown
teardown-pr-stack:
name: Teardown Examples PR stack
needs: example-matrix
environment: Pull request
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.example-matrix.outputs.matrix) }}
env:
DEPLOY_ENV: ${{ github.event_name == 'push' && 'production' || format('pr-{0}', github.event.number) }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_DEFAULT_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_DEFAULT_ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
NEON_API_KEY: ${{ secrets.NEON_API_KEY }}
NEON_PROJECT_ID: ${{ secrets.NEON_PROJECT_ID }}
ELECTRIC_API: ${{ secrets.ELECTRIC_API }}
ELECTRIC_ADMIN_API: ${{ secrets.ELECTRIC_ADMIN_API }}
ELECTRIC_TEAM_ID: ${{ secrets.ELECTRIC_TEAM_ID }}
ELECTRIC_ADMIN_API_AUTH_TOKEN: ${{ secrets.ELECTRIC_ADMIN_API_AUTH_TOKEN }}
BETTER_AUTH_SECRET: ${{ secrets.BETTER_AUTH_SECRET }}
# HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }} TODO
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.tool-versions'
cache: 'pnpm'
- name: Install dependencies
run: |
if [ -f "${{ matrix.example.path }}/package.json" ]; then
pnpm --filter "$(jq -r .name "${{ matrix.example.path }}/package.json")..." --filter @electric-examples/shared install --frozen-lockfile
else
pnpm install --frozen-lockfile
fi
- name: Cache SST state
uses: actions/cache@v4
with:
path: .sst
key: sst-cache-${{ github.event.number }}-${{ runner.os }}
restore-keys: |
sst-cache-${{ runner.os }}
- name: Remove ${{ matrix.example.name }} example
working-directory: ./${{ matrix.example.path }}
run: |
export PR_NUMBER=${{ github.event.number }}
echo "Removing stage pr-$PR_NUMBER"
# Run the command and capture both stdout and stderr
if ! output=$(pnpm sst remove --stage "pr-$PR_NUMBER" 2>&1); then
# Check if the error is because the stage doesn't exist
if echo "$output" | grep -q "Stage not found"; then
echo "Example was not deployed."
exit 0
fi
# If it's a different error, print it and fail
echo "Error removing stage: $output" >&2
exit 1
fi
echo "Successfully removed stage"
exit 0