name: E2E Tests

on:
  pull_request: 
  push:
    branches-ignore:
      - 'hotfix-*'   # excludes hotfix branches
      - 'release'

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      CI_PIPELINE_ID: ${{github.run_number}}
    steps:
      # Docker compose needs a lot of space to build images, so we need to free up some space first in the GitHub Actions runner
      - name: Free Disk Space (Ubuntu)
        uses: jlumbroso/free-disk-space@main
        with:
          # this might remove tools that are actually needed,
          # if set to "true" but frees about 6 GB
          tool-cache: false
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          docker-images: true
          swap-storage: true
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 18.3.0
      - run: npm run prerun && bash ./Tests/Scripts/enable-billing-env-var.sh
      - run: npm run dev
      - name: Sleep for 2 minutes to wait for server to start
        run: sleep 120
      - name: Wait for server to start
        run:  bash ./Tests/Scripts/status-check.sh http://localhost
      - name: Run E2E Tests. Run docker container e2e in docker compose file
        run: export $(grep -v '^#' config.env | xargs) && docker-compose -f docker-compose.dev.yml up --exit-code-from e2e --abort-on-container-exit e2e || (docker-compose -f docker-compose.dev.yml logs && exit 1)
      - name: Upload test results
        uses: actions/upload-artifact@v4
        # Run this on failure
        if: failure()
        with:
          # Name of the artifact to upload.
          # Optional. Default is 'artifact'
          name: test-results
      
          # A file, directory or wildcard pattern that describes what to upload
          # Required.
          path: |
            ./E2E
      
        
          # Duration after which artifact will expire in days. 0 means using default retention.
          # Minimum 1 day.
          # Maximum 90 days unless changed from the repository settings page.
          # Optional. Defaults to repository settings.
          retention-days: 7