|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + pull_request: |
| 7 | + branches: [main, master] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint-and-test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v3 |
| 15 | + |
| 16 | + - name: Setup Node.js |
| 17 | + uses: actions/setup-node@v3 |
| 18 | + with: |
| 19 | + node-version: '18' |
| 20 | + cache: 'npm' |
| 21 | + |
| 22 | + - name: Install dependencies |
| 23 | + run: npm ci |
| 24 | + |
| 25 | + - name: Run linter |
| 26 | + run: npm run lint |
| 27 | + |
| 28 | + - name: Type check |
| 29 | + run: npm run typecheck |
| 30 | + |
| 31 | + - name: Build |
| 32 | + run: npm run build |
| 33 | + |
| 34 | + build-docker: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + needs: lint-and-test |
| 37 | + if: github.event_name == 'push' |
| 38 | + |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v3 |
| 41 | + |
| 42 | + - name: Set up Docker Buildx |
| 43 | + uses: docker/setup-buildx-action@v2 |
| 44 | + |
| 45 | + - name: Login to Docker Hub |
| 46 | + uses: docker/login-action@v2 |
| 47 | + with: |
| 48 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 49 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 50 | + |
| 51 | + - name: Build and push |
| 52 | + uses: docker/build-push-action@v4 |
| 53 | + with: |
| 54 | + context: . |
| 55 | + push: true |
| 56 | + tags: | |
| 57 | + ${{ secrets.DOCKER_USERNAME }}/watch-room-server:latest |
| 58 | + ${{ secrets.DOCKER_USERNAME }}/watch-room-server:${{ github.sha }} |
| 59 | + cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/watch-room-server:buildcache |
| 60 | + cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/watch-room-server:buildcache,mode=max |
| 61 | + |
| 62 | + deploy-fly: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: lint-and-test |
| 65 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 66 | + |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v3 |
| 69 | + |
| 70 | + - name: Setup Fly |
| 71 | + uses: superfly/flyctl-actions/setup-flyctl@master |
| 72 | + |
| 73 | + - name: Deploy to Fly.io |
| 74 | + run: flyctl deploy --remote-only |
| 75 | + env: |
| 76 | + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
0 commit comments