name: ๐Ÿš€ Deploy on: push: branches: - main pull_request: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} permissions: contents: read jobs: test: name: ๐Ÿงช Test runs-on: ubuntu-latest timeout-minutes: 20 services: postgres: image: postgres:15 env: POSTGRES_USER: test POSTGRES_PASSWORD: test POSTGRES_DB: brackt_test options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - name: โฌ‡๏ธ Checkout repo uses: https://github.com/actions/checkout@v4 - name: ๐Ÿ“ฅ Install dependencies run: npm ci - name: ๐Ÿงช Run unit tests run: npm run test:run env: DATABASE_URL: postgresql://test:test@postgres:5432/brackt_test NODE_OPTIONS: --max-old-space-size=4096 check: name: สฆ๐Ÿ” Typecheck & Lint runs-on: ubuntu-latest timeout-minutes: 15 steps: - name: โฌ‡๏ธ Checkout repo uses: https://github.com/actions/checkout@v4 - name: ๐Ÿ“ฅ Install dependencies run: npm ci - name: ๐Ÿ” Lint (oxlint) run: npm run lint - name: ๐Ÿ”Ž Type check run: npm run typecheck build: name: ๐Ÿณ Build needs: [test, check] if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }} runs-on: ubuntu-latest timeout-minutes: 30 steps: - name: โฌ‡๏ธ Checkout repo uses: https://github.com/actions/checkout@v4 - name: ๐Ÿณ Set up Docker Buildx uses: https://github.com/docker/setup-buildx-action@v3 - name: ๐Ÿ”“ Login to Container Registry uses: https://github.com/docker/login-action@v3 with: registry: ${{ vars.CONTAINER_REGISTRY }} username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - name: ๐Ÿ—„๏ธ Build and Push to Container Registry uses: https://github.com/docker/build-push-action@v5 with: context: . push: true platforms: linux/amd64 tags: ${{ vars.CONTAINER_REGISTRY }}/brackt:latest cache-from: type=registry,ref=${{ vars.CONTAINER_REGISTRY }}/brackt:buildcache cache-to: type=registry,ref=${{ vars.CONTAINER_REGISTRY }}/brackt:buildcache,mode=max secret-files: | npmrc=./.npmrc deploy: name: ๐Ÿš€ Deploy runs-on: ubuntu-latest timeout-minutes: 10 needs: [build] if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }} steps: - name: ๐Ÿš€ Deploy app to server uses: https://github.com/appleboy/ssh-action@v1.0.3 env: REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} CONTAINER_REGISTRY: ${{ vars.CONTAINER_REGISTRY }} with: host: ${{ secrets.DEPLOY_HOST }} port: ${{ secrets.DEPLOY_PORT }} username: ${{ secrets.DEPLOY_USER }} key: ${{ secrets.DEPLOY_KEY }} envs: REGISTRY_USERNAME,REGISTRY_PASSWORD,CONTAINER_REGISTRY script: | set -e docker login $CONTAINER_REGISTRY -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD cd brackt docker compose pull if ! docker compose up --no-deps migrate; then echo "Migration failed:" docker compose logs migrate exit 1 fi docker compose up -d --remove-orphans