|
1 | 1 | # Kamal deployment workflow |
2 | | -# Deploys to production after all tests pass on push to main |
| 2 | +# Deploys to production after CI workflow passes on main branch |
3 | 3 |
|
4 | 4 | name: Deploy |
5 | 5 |
|
6 | 6 | on: |
7 | | - push: |
| 7 | + workflow_run: |
| 8 | + workflows: [CI] |
| 9 | + types: [completed] |
8 | 10 | branches: [main] |
9 | 11 | workflow_dispatch: # Allow manual deployment |
10 | 12 |
|
11 | 13 | jobs: |
12 | | - # Run all tests before deploying |
13 | | - cache-npm: |
14 | | - name: Cache NPM libraries |
15 | | - runs-on: ubuntu-latest |
16 | | - steps: |
17 | | - - name: Checkout repository |
18 | | - uses: actions/checkout@v4 |
19 | | - |
20 | | - - name: Setup Node.js |
21 | | - uses: actions/setup-node@v4 |
22 | | - with: |
23 | | - node-version: '24.x' |
24 | | - |
25 | | - - name: Restore NPM cache |
26 | | - uses: actions/cache@v4 |
27 | | - id: cache |
28 | | - with: |
29 | | - path: ~/.npm |
30 | | - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
31 | | - restore-keys: | |
32 | | - ${{ runner.os }}-node- |
33 | | -
|
34 | | - - name: Install locked dependencies |
35 | | - if: steps.cache.outputs.cache-hit != 'true' |
36 | | - run: npm ci |
37 | | - |
38 | | - lint: |
39 | | - name: ESLint |
40 | | - runs-on: ubuntu-latest |
41 | | - needs: cache-npm |
42 | | - steps: |
43 | | - - name: Checkout repository |
44 | | - uses: actions/checkout@v4 |
45 | | - |
46 | | - - name: Setup Node.js |
47 | | - uses: actions/setup-node@v4 |
48 | | - with: |
49 | | - node-version: '24.x' |
50 | | - |
51 | | - - name: Restore NPM cache |
52 | | - uses: actions/cache@v4 |
53 | | - with: |
54 | | - path: ~/.npm |
55 | | - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
56 | | - restore-keys: | |
57 | | - ${{ runner.os }}-node- |
58 | | -
|
59 | | - - name: Install locked dependencies |
60 | | - run: npm ci |
61 | | - |
62 | | - - name: Generate Prisma Client |
63 | | - run: npx prisma generate |
64 | | - |
65 | | - - name: Build CSS assets from Tailwind CSS |
66 | | - run: npm run build:css |
67 | | - |
68 | | - - name: Lint files |
69 | | - run: npm run lint |
70 | | - env: |
71 | | - CI: true |
72 | | - |
73 | | - type-check: |
74 | | - name: Type check |
75 | | - runs-on: ubuntu-latest |
76 | | - needs: cache-npm |
77 | | - steps: |
78 | | - - name: Checkout repository |
79 | | - uses: actions/checkout@v4 |
80 | | - |
81 | | - - name: Setup Node.js |
82 | | - uses: actions/setup-node@v4 |
83 | | - with: |
84 | | - node-version: '24.x' |
85 | | - |
86 | | - - name: Restore NPM cache |
87 | | - uses: actions/cache@v4 |
88 | | - with: |
89 | | - path: ~/.npm |
90 | | - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
91 | | - restore-keys: | |
92 | | - ${{ runner.os }}-node- |
93 | | -
|
94 | | - - name: Install locked dependencies |
95 | | - run: npm ci |
96 | | - |
97 | | - - name: Generate Prisma Client |
98 | | - run: npx prisma generate |
99 | | - |
100 | | - - name: Type check |
101 | | - run: npm run type-check |
102 | | - env: |
103 | | - CI: true |
104 | | - |
105 | | - unit-test: |
106 | | - name: Unit and integration test |
107 | | - runs-on: ubuntu-latest |
108 | | - needs: cache-npm |
109 | | - steps: |
110 | | - - name: Checkout repository |
111 | | - uses: actions/checkout@v4 |
112 | | - |
113 | | - - name: Setup Node.js |
114 | | - uses: actions/setup-node@v4 |
115 | | - with: |
116 | | - node-version: '24.x' |
117 | | - |
118 | | - - name: Restore NPM cache |
119 | | - uses: actions/cache@v4 |
120 | | - with: |
121 | | - path: ~/.npm |
122 | | - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
123 | | - restore-keys: | |
124 | | - ${{ runner.os }}-node- |
125 | | -
|
126 | | - - name: Install locked dependencies |
127 | | - run: npm ci |
128 | | - |
129 | | - - name: Run unit and integration tests |
130 | | - run: npm t |
131 | | - env: |
132 | | - CI: true |
133 | | - |
134 | | - e2e-test: |
135 | | - name: End-to-end test |
136 | | - runs-on: ubuntu-latest |
137 | | - needs: cache-npm |
138 | | - steps: |
139 | | - - name: Checkout repository |
140 | | - uses: actions/checkout@v4 |
141 | | - |
142 | | - - name: Setup Node.js |
143 | | - uses: actions/setup-node@v4 |
144 | | - with: |
145 | | - node-version: '24.x' |
146 | | - |
147 | | - - name: Restore NPM cache |
148 | | - uses: actions/cache@v4 |
149 | | - with: |
150 | | - path: ~/.npm |
151 | | - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/playwright.config.ts') }} |
152 | | - restore-keys: | |
153 | | - ${{ runner.os }}-node- |
154 | | -
|
155 | | - - name: Install locked dependencies |
156 | | - run: npm ci |
157 | | - |
158 | | - - name: Restore cached Playwright dependencies |
159 | | - id: cache-playwright |
160 | | - uses: actions/cache@v4 |
161 | | - with: |
162 | | - path: ~/.cache/ms-playwright |
163 | | - key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/playwright.config.ts') }} |
164 | | - restore-keys: | |
165 | | - ${{ runner.os }}-playwright- |
166 | | -
|
167 | | - - name: Install Playwright browsers with dependencies |
168 | | - if: steps.cache-playwright.outputs.cache-hit != 'true' |
169 | | - run: npx playwright install --with-deps |
170 | | - |
171 | | - - name: Install Playwright system dependencies (on cache hit) |
172 | | - if: steps.cache-playwright.outputs.cache-hit == 'true' |
173 | | - run: npx playwright install-deps |
174 | | - |
175 | | - - name: Run end-to-end tests |
176 | | - run: npm run test:e2e:run |
177 | | - env: |
178 | | - CI: true |
179 | | - SESSION_SECRET: test-session-secret |
180 | | - MAGIC_LINK_SECRET: test-magic-link-secret |
181 | | - MAILGUN_SENDING_KEY: nothing |
182 | | - MAILGUN_DOMAIN: nothing |
183 | | - |
184 | 14 | deploy: |
185 | 15 | name: Deploy to production |
186 | 16 | runs-on: ubuntu-latest |
187 | | - needs: [lint, type-check, unit-test, e2e-test] |
188 | | - environment: production |
189 | | - # Only run on push to main (not on PRs) |
190 | | - if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' |
| 17 | + environment: Production |
| 18 | + # Only run if CI passed (or manual trigger) |
| 19 | + if: > |
| 20 | + github.event_name == 'workflow_dispatch' || |
| 21 | + (github.event.workflow_run.conclusion == 'success' && |
| 22 | + github.event.workflow_run.head_branch == 'main') |
191 | 23 |
|
192 | 24 | steps: |
193 | 25 | - name: Checkout repository |
|
0 commit comments