|
| 1 | +name: 🚀 Deploy |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + - dev |
| 7 | + pull_request: {} |
| 8 | + |
| 9 | +permissions: |
| 10 | + actions: write |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + lint: |
| 15 | + name: ⬣ ESLint |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: 🛑 Cancel Previous Runs |
| 19 | + |
| 20 | + |
| 21 | + - name: ⬇️ Checkout repo |
| 22 | + uses: actions/checkout@v3 |
| 23 | + |
| 24 | + - name: ⎔ Setup node |
| 25 | + uses: actions/setup-node@v3 |
| 26 | + with: |
| 27 | + node-version: 16 |
| 28 | + |
| 29 | + - name: 📥 Download deps |
| 30 | + uses: bahmutov/npm-install@v1 |
| 31 | + with: |
| 32 | + useLockFile: false |
| 33 | + |
| 34 | + - name: 🔬 Lint |
| 35 | + run: npm run lint |
| 36 | + |
| 37 | + typecheck: |
| 38 | + name: ʦ TypeScript |
| 39 | + runs-on: ubuntu-latest |
| 40 | + steps: |
| 41 | + - name: 🛑 Cancel Previous Runs |
| 42 | + |
| 43 | + |
| 44 | + - name: ⬇️ Checkout repo |
| 45 | + uses: actions/checkout@v3 |
| 46 | + |
| 47 | + - name: ⎔ Setup node |
| 48 | + uses: actions/setup-node@v3 |
| 49 | + with: |
| 50 | + node-version: 16 |
| 51 | + |
| 52 | + - name: 📥 Download deps |
| 53 | + uses: bahmutov/npm-install@v1 |
| 54 | + with: |
| 55 | + useLockFile: false |
| 56 | + |
| 57 | + - name: 🔎 Type check |
| 58 | + run: npm run typecheck --if-present |
| 59 | + |
| 60 | + vitest: |
| 61 | + name: ⚡ Vitest |
| 62 | + runs-on: ubuntu-latest |
| 63 | + steps: |
| 64 | + - name: 🛑 Cancel Previous Runs |
| 65 | + |
| 66 | + |
| 67 | + - name: ⬇️ Checkout repo |
| 68 | + uses: actions/checkout@v3 |
| 69 | + |
| 70 | + - name: ⎔ Setup node |
| 71 | + uses: actions/setup-node@v3 |
| 72 | + with: |
| 73 | + node-version: 16 |
| 74 | + |
| 75 | + - name: 📥 Download deps |
| 76 | + uses: bahmutov/npm-install@v1 |
| 77 | + with: |
| 78 | + useLockFile: false |
| 79 | + |
| 80 | + - name: ⚡ Run vitest |
| 81 | + run: npm run test -- --coverage |
| 82 | + |
| 83 | + cypress: |
| 84 | + name: ⚫️ Cypress |
| 85 | + runs-on: ubuntu-latest |
| 86 | + steps: |
| 87 | + - name: 🛑 Cancel Previous Runs |
| 88 | + |
| 89 | + |
| 90 | + - name: ⬇️ Checkout repo |
| 91 | + uses: actions/checkout@v3 |
| 92 | + |
| 93 | + - name: 🏄 Copy test env vars |
| 94 | + run: cp .env.example .env |
| 95 | + |
| 96 | + - name: ⎔ Setup node |
| 97 | + uses: actions/setup-node@v3 |
| 98 | + with: |
| 99 | + node-version: 16 |
| 100 | + |
| 101 | + - name: 📥 Download deps |
| 102 | + uses: bahmutov/npm-install@v1 |
| 103 | + with: |
| 104 | + useLockFile: false |
| 105 | + |
| 106 | + - name: 🛠 Setup Database |
| 107 | + run: npx prisma migrate reset --force |
| 108 | + |
| 109 | + - name: ⚙️ Build |
| 110 | + run: npm run build |
| 111 | + |
| 112 | + - name: 🌳 Cypress run |
| 113 | + uses: cypress-io/github-action@v4 |
| 114 | + with: |
| 115 | + start: npm run start:mocks |
| 116 | + wait-on: "http://localhost:8811" |
| 117 | + env: |
| 118 | + PORT: "8811" |
| 119 | + |
| 120 | + build: |
| 121 | + name: 🐳 Build |
| 122 | + # only build/deploy main branch on pushes |
| 123 | + if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }} |
| 124 | + runs-on: ubuntu-latest |
| 125 | + steps: |
| 126 | + - name: 🛑 Cancel Previous Runs |
| 127 | + |
| 128 | + |
| 129 | + - name: ⬇️ Checkout repo |
| 130 | + uses: actions/checkout@v3 |
| 131 | + |
| 132 | + - name: 👀 Read app name |
| 133 | + |
| 134 | + id: app_name |
| 135 | + with: |
| 136 | + file: "fly.toml" |
| 137 | + field: "app" |
| 138 | + |
| 139 | + - name: 🐳 Set up Docker Buildx |
| 140 | + uses: docker/setup-buildx-action@v2 |
| 141 | + |
| 142 | + # Setup cache |
| 143 | + - name: ⚡️ Cache Docker layers |
| 144 | + uses: actions/cache@v3 |
| 145 | + with: |
| 146 | + path: /tmp/.buildx-cache |
| 147 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 148 | + restore-keys: | |
| 149 | + ${{ runner.os }}-buildx- |
| 150 | +
|
| 151 | + - name: 🔑 Fly Registry Auth |
| 152 | + uses: docker/login-action@v2 |
| 153 | + with: |
| 154 | + registry: registry.fly.io |
| 155 | + username: x |
| 156 | + password: ${{ secrets.FLY_API_TOKEN }} |
| 157 | + |
| 158 | + - name: 🐳 Docker build |
| 159 | + uses: docker/build-push-action@v3 |
| 160 | + with: |
| 161 | + context: . |
| 162 | + push: true |
| 163 | + tags: registry.fly.io/${{ steps.app_name.outputs.value }}:${{ github.ref_name }}-${{ github.sha }} |
| 164 | + build-args: | |
| 165 | + COMMIT_SHA=${{ github.sha }} |
| 166 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 167 | + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new |
| 168 | + |
| 169 | + # This ugly bit is necessary if you don't want your cache to grow forever |
| 170 | + # till it hits GitHub's limit of 5GB. |
| 171 | + # Temp fix |
| 172 | + # https://github.com/docker/build-push-action/issues/252 |
| 173 | + # https://github.com/moby/buildkit/issues/1896 |
| 174 | + - name: 🚚 Move cache |
| 175 | + run: | |
| 176 | + rm -rf /tmp/.buildx-cache |
| 177 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 178 | +
|
| 179 | + deploy: |
| 180 | + name: 🚀 Deploy |
| 181 | + runs-on: ubuntu-latest |
| 182 | + needs: [lint, typecheck, vitest, cypress, build] |
| 183 | + # only build/deploy main branch on pushes |
| 184 | + if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }} |
| 185 | + |
| 186 | + steps: |
| 187 | + - name: 🛑 Cancel Previous Runs |
| 188 | + |
| 189 | + |
| 190 | + - name: ⬇️ Checkout repo |
| 191 | + uses: actions/checkout@v3 |
| 192 | + |
| 193 | + - name: 👀 Read app name |
| 194 | + |
| 195 | + id: app_name |
| 196 | + with: |
| 197 | + file: "fly.toml" |
| 198 | + field: "app" |
| 199 | + |
| 200 | + - name: 🚀 Deploy Staging |
| 201 | + if: ${{ github.ref == 'refs/heads/dev' }} |
| 202 | + |
| 203 | + with: |
| 204 | + args: "deploy --app ${{ steps.app_name.outputs.value }}-staging --image registry.fly.io/${{ steps.app_name.outputs.value }}:${{ github.ref_name }}-${{ github.sha }}" |
| 205 | + env: |
| 206 | + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
| 207 | + |
| 208 | + - name: 🚀 Deploy Production |
| 209 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 210 | + |
| 211 | + with: |
| 212 | + args: "deploy --image registry.fly.io/${{ steps.app_name.outputs.value }}:${{ github.ref_name }}-${{ github.sha }}" |
| 213 | + env: |
| 214 | + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
0 commit comments