|
| 1 | +name: 🚀 Deploy |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + - dev |
| 7 | + pull_request: {} |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +permissions: |
| 14 | + actions: write |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + lint: |
| 19 | + name: ⬣ ESLint |
| 20 | + runs-on: ubuntu-22.04 |
| 21 | + steps: |
| 22 | + - name: ⬇️ Checkout repo |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: ⎔ Setup node |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: 22 |
| 29 | + |
| 30 | + - name: 📥 Download deps |
| 31 | + uses: bahmutov/npm-install@v1 |
| 32 | + |
| 33 | + - name: 🏄 Copy test env vars |
| 34 | + run: cp .env.example .env |
| 35 | + |
| 36 | + - name: 🛠 Setup Database |
| 37 | + run: npx prisma migrate deploy && npx prisma generate --sql |
| 38 | + |
| 39 | + - name: 🔬 Lint |
| 40 | + run: npm run lint |
| 41 | + |
| 42 | + typecheck: |
| 43 | + name: ʦ TypeScript |
| 44 | + runs-on: ubuntu-22.04 |
| 45 | + steps: |
| 46 | + - name: ⬇️ Checkout repo |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: ⎔ Setup node |
| 50 | + uses: actions/setup-node@v4 |
| 51 | + with: |
| 52 | + node-version: 22 |
| 53 | + |
| 54 | + - name: 📥 Download deps |
| 55 | + uses: bahmutov/npm-install@v1 |
| 56 | + |
| 57 | + - name: 🏗 Build |
| 58 | + run: npm run build |
| 59 | + |
| 60 | + - name: 🏄 Copy test env vars |
| 61 | + run: cp .env.example .env |
| 62 | + |
| 63 | + - name: 🛠 Setup Database |
| 64 | + run: npx prisma migrate deploy && npx prisma generate --sql |
| 65 | + |
| 66 | + - name: 🔎 Type check |
| 67 | + run: npm run typecheck --if-present |
| 68 | + |
| 69 | + vitest: |
| 70 | + name: ⚡ Vitest |
| 71 | + runs-on: ubuntu-22.04 |
| 72 | + steps: |
| 73 | + - name: ⬇️ Checkout repo |
| 74 | + uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: ⎔ Setup node |
| 77 | + uses: actions/setup-node@v4 |
| 78 | + with: |
| 79 | + node-version: 22 |
| 80 | + |
| 81 | + - name: 📥 Download deps |
| 82 | + uses: bahmutov/npm-install@v1 |
| 83 | + |
| 84 | + - name: 🏄 Copy test env vars |
| 85 | + run: cp .env.example .env |
| 86 | + |
| 87 | + - name: 🛠 Setup Database |
| 88 | + run: npx prisma migrate deploy && npx prisma generate --sql |
| 89 | + |
| 90 | + - name: ⚡ Run vitest |
| 91 | + run: npm run test -- --coverage |
| 92 | + |
| 93 | + playwright: |
| 94 | + name: 🎭 Playwright |
| 95 | + runs-on: ubuntu-22.04 |
| 96 | + timeout-minutes: 60 |
| 97 | + steps: |
| 98 | + - name: ⬇️ Checkout repo |
| 99 | + uses: actions/checkout@v4 |
| 100 | + |
| 101 | + - name: 🏄 Copy test env vars |
| 102 | + run: cp .env.example .env |
| 103 | + |
| 104 | + - name: ⎔ Setup node |
| 105 | + uses: actions/setup-node@v4 |
| 106 | + with: |
| 107 | + node-version: 22 |
| 108 | + |
| 109 | + - name: 📥 Download deps |
| 110 | + uses: bahmutov/npm-install@v1 |
| 111 | + |
| 112 | + - name: 📥 Install Playwright Browsers |
| 113 | + run: npm run test:e2e:install |
| 114 | + |
| 115 | + - name: 🛠 Setup Database |
| 116 | + run: npx prisma migrate deploy && npx prisma generate --sql |
| 117 | + |
| 118 | + - name: 🏦 Cache Database |
| 119 | + id: db-cache |
| 120 | + uses: actions/cache@v4 |
| 121 | + with: |
| 122 | + path: prisma/data.db |
| 123 | + key: |
| 124 | + db-cache-schema_${{ hashFiles('./prisma/schema.prisma') |
| 125 | + }}-migrations_${{ hashFiles('./prisma/migrations/*/migration.sql') |
| 126 | + }} |
| 127 | + |
| 128 | + - name: 🌱 Seed Database |
| 129 | + if: steps.db-cache.outputs.cache-hit != 'true' |
| 130 | + run: npx prisma migrate reset --force |
| 131 | + |
| 132 | + - name: 🏗 Build |
| 133 | + run: npm run build |
| 134 | + |
| 135 | + - name: 🎭 Playwright tests |
| 136 | + run: npx playwright test |
| 137 | + |
| 138 | + - name: 📊 Upload report |
| 139 | + uses: actions/upload-artifact@v4 |
| 140 | + if: always() |
| 141 | + with: |
| 142 | + name: playwright-report |
| 143 | + path: playwright-report/ |
| 144 | + retention-days: 30 |
| 145 | + |
| 146 | + container: |
| 147 | + name: 📦 Prepare Container |
| 148 | + runs-on: ubuntu-24.04 |
| 149 | + # only prepare container on pushes |
| 150 | + if: ${{ github.event_name == 'push' }} |
| 151 | + steps: |
| 152 | + - name: ⬇️ Checkout repo |
| 153 | + uses: actions/checkout@v4 |
| 154 | + with: |
| 155 | + fetch-depth: 50 |
| 156 | + |
| 157 | + - name: 👀 Read app name |
| 158 | + uses: SebRollen/toml-action@v1.2.0 |
| 159 | + id: app_name |
| 160 | + with: |
| 161 | + file: 'fly.toml' |
| 162 | + field: 'app' |
| 163 | + |
| 164 | + - name: 🎈 Setup Fly |
| 165 | + uses: superfly/flyctl-actions/setup-flyctl@1.5 |
| 166 | + |
| 167 | + - name: 📦 Build Staging Container |
| 168 | + if: ${{ github.ref == 'refs/heads/dev' }} |
| 169 | + run: | |
| 170 | + flyctl deploy \ |
| 171 | + --build-only \ |
| 172 | + --push \ |
| 173 | + --image-label ${{ github.sha }} \ |
| 174 | + --build-arg COMMIT_SHA=${{ github.sha }} \ |
| 175 | + --app ${{ steps.app_name.outputs.value }}-staging |
| 176 | + env: |
| 177 | + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
| 178 | + |
| 179 | + - name: 📦 Build Production Container |
| 180 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 181 | + run: | |
| 182 | + flyctl deploy \ |
| 183 | + --build-only \ |
| 184 | + --push \ |
| 185 | + --image-label ${{ github.sha }} \ |
| 186 | + --build-arg COMMIT_SHA=${{ github.sha }} \ |
| 187 | + --build-secret SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \ |
| 188 | + --app ${{ steps.app_name.outputs.value }} |
| 189 | + env: |
| 190 | + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
| 191 | + |
| 192 | + deploy: |
| 193 | + name: 🚀 Deploy |
| 194 | + runs-on: ubuntu-24.04 |
| 195 | + needs: [lint, typecheck, vitest, playwright, container] |
| 196 | + # only deploy on pushes |
| 197 | + if: ${{ github.event_name == 'push' }} |
| 198 | + steps: |
| 199 | + - name: ⬇️ Checkout repo |
| 200 | + uses: actions/checkout@v4 |
| 201 | + with: |
| 202 | + fetch-depth: '50' |
| 203 | + |
| 204 | + - name: 👀 Read app name |
| 205 | + uses: SebRollen/toml-action@v1.2.0 |
| 206 | + id: app_name |
| 207 | + with: |
| 208 | + file: 'fly.toml' |
| 209 | + field: 'app' |
| 210 | + |
| 211 | + - name: 🎈 Setup Fly |
| 212 | + uses: superfly/flyctl-actions/setup-flyctl@1.5 |
| 213 | + |
| 214 | + - name: 🚀 Deploy Staging |
| 215 | + if: ${{ github.ref == 'refs/heads/dev' }} |
| 216 | + run: | |
| 217 | + flyctl deploy \ |
| 218 | + --image "registry.fly.io/${{ steps.app_name.outputs.value }}-staging:${{ github.sha }}" \ |
| 219 | + --app ${{ steps.app_name.outputs.value }}-staging |
| 220 | + env: |
| 221 | + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
| 222 | + |
| 223 | + - name: 🚀 Deploy Production |
| 224 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 225 | + run: | |
| 226 | + flyctl deploy \ |
| 227 | + --image "registry.fly.io/${{ steps.app_name.outputs.value }}:${{ github.sha }}" |
| 228 | + env: |
| 229 | + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
0 commit comments