name: Deploy on: push: branches: [master] env: LANG: C.UTF-8 LD_LIBRARY_PATH: '/usr/local/lib:$LD_LIBRARY_PATH' # GitHub Actions runners have 2 cores for Linux CABAL_JOBS: 2 GHC_VERSION: 9.12.2 jobs: test: name: Test runs-on: ubuntu-latest services: postgres: image: timescale/timescaledb-ha:pg16-all env: POSTGRES_PASSWORD: postgres POSTGRES_DB: monoscope options: >- --health-cmd="pg_isready -U postgres" --health-interval=10s --health-timeout=5s --health-retries=5 ports: - 5432:5432 strategy: fail-fast: false matrix: test: [doctests, unit-tests, integration-tests] steps: - uses: actions/checkout@v4 # Free up disk space - name: Free Disk Space run: | echo "Disk space before cleanup:" df -h sudo rm -rf /usr/share/dotnet sudo rm -rf /usr/local/lib/android sudo rm -rf /opt/ghc sudo rm -rf /opt/hostedtoolcache/CodeQL sudo docker image prune --all --force echo "Disk space after cleanup:" df -h # Install and cache system dependencies - name: Install system dependencies uses: awalsh128/cache-apt-pkgs-action@latest with: packages: libssl-dev librdkafka-dev libgrpc-dev protobuf-compiler libsnappy-dev libpq-dev libldap2-dev libsasl2-dev liblz4-dev libzstd-dev pkg-config version: 1.0 - name: Set OpenSSL environment variables run: | echo "OPENSSL_INCLUDE_DIR=$(pkg-config --variable=includedir openssl)" >> $GITHUB_ENV echo "OPENSSL_LIB_DIR=$(pkg-config --variable=libdir openssl)" >> $GITHUB_ENV - uses: haskell-actions/setup@v2 with: ghc-version: ${{ env.GHC_VERSION }} cabal-version: 'latest' # Cache Haskell dependencies - name: Cache Haskell dependencies uses: actions/cache@v4 with: path: | ~/.cabal/store dist-newstyle/build dist-newstyle/cache key: ${{ runner.os }}-${{ matrix.test }}-${{ hashFiles('**/*.cabal', '**/cabal.project*') }} restore-keys: | ${{ runner.os }}-${{ matrix.test }}- ${{ runner.os }}- - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' - name: Generate required static files run: | # Create directories if they don't exist mkdir -p static/public/assets/css mkdir -p static/public/assets/web-components/dist/js mkdir -p static/public/assets/web-components/dist/css # Install dependencies and build Tailwind CSS npm install npx tailwindcss -i ./static/public/assets/css/tailwind.css -o ./static/public/assets/css/tailwind.min.css --minify # Build web components cd web-components npm install NODE_ENV=production npx vite build --mode production --sourcemap false cd .. - name: Update cabal index run: cabal update - name: Configure project run: cabal configure --enable-tests --enable-benchmarks --ghc-options="-O0 -j8" - name: Build dependencies run: cabal build --only-dependencies all -j4 - name: Build ${{ matrix.test }} run: cabal build ${{ matrix.test }} -j4 - name: Run ${{ matrix.test }} env: USE_EXTERNAL_DB: true run: | echo "::group::Running ${{ matrix.test }}" cabal test ${{ matrix.test }} --ghc-options="-O0 -j8" --test-show-details=direct echo "::endgroup::" build-and-deploy: name: Build and Deploy Docker Image runs-on: ubuntu-latest if: always() permissions: contents: 'read' id-token: 'write' steps: - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GH_TOKEN }} - name: Build and push Docker Image uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: true tags: | ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest cache-from: | type=gha type=registry,ref=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:buildcache cache-to: | type=gha,mode=max type=registry,ref=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:buildcache,mode=max platforms: linux/amd64 provenance: false build-args: | BUILDKIT_INLINE_CACHE=1 - name: Deploy Image to CapRrover uses: caprover/deploy-from-github@v1.1.2 with: server: '${{ secrets.CAPTAINROVER_SERVER }}' app: '${{ secrets.CAPTAINROVER_APP_NAME }}' token: '${{ secrets.CAPTAINROVER_APP_TOKEN }}' image: 'ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}'