somleng/somleng-adhearsion

View on GitHub
.github/workflows/integration_tests.yml

Summary

Maintainability
Test Coverage
name: Integration Tests
on:
  workflow_call:
    inputs:
      context:
        required: true
        type: string
    secrets:
      signalwire_token:
        required: true

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest

    env:
      PGHOST: localhost
      PGUSER: postgres
      CI: true

    services:
      postgres:
        image: postgres:14
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: ""
          POSTGRES_HOST_AUTH_METHOD: trust
        ports:
          - 5432:5432
        # needed because the postgres container does not provide a healthcheck
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      # Login to AWS to avoid rate limit
      - name: Configure AWS credentials
        id: aws-login
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
          role-skip-session-tagging: true
          role-duration-seconds: 3600
          aws-region: ap-southeast-1

      - name: Login to AWS Public ECR
        uses: docker/login-action@v3
        with:
          registry: public.ecr.aws
        env:
          AWS_REGION: us-east-1

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build Switch App
        uses: docker/build-push-action@v5
        with:
          push: false
          load: true
          context: components/app
          tags: switch-app:latest
          cache-from: type=gha,scope=integration-tests-switch-app
          cache-to: type=gha,mode=max,scope=integration-tests-switch-app

      - name: Build FreeSWITCH
        uses: docker/build-push-action@v5
        with:
          push: false
          load: true
          context: components/freeswitch
          build-args:
            signalwire_token=${{ secrets.signalwire_token }}
          tags: freeswitch:latest
          cache-from: type=gha,scope=integration-tests-freeswitch
          cache-to: type=gha,mode=max,scope=integration-tests-freeswitch

      - name: Build FreeSWITCH Event Logger
        uses: docker/build-push-action@v5
        with:
          push: false
          load: true
          context: components/freeswitch_event_logger
          tags: freeswitch_event_logger:latest
          cache-from: type=gha,scope=integration-tests-freeswitch-event-logger
          cache-to: type=gha,mode=max,scope=integration-tests-freeswitch-event-logger

      - name: Build Public Gateway
        uses: docker/build-push-action@v5
        with:
          push: false
          load: true
          context: components/gateway
          target: public_gateway
          tags: public_gateway:latest
          cache-from: type=gha,scope=integration-tests-public-gateway
          cache-to: type=gha,mode=max,scope=integration-tests-public-gateway

      - name: Build Client Gateway
        uses: docker/build-push-action@v5
        with:
          push: false
          load: true
          context: components/gateway
          target: client_gateway
          tags: client_gateway:latest
          cache-from: type=gha,scope=integration-tests-client-gateway
          cache-to: type=gha,mode=max,scope=integration-tests-client-gateway

      - name: Build Media Proxy
        uses: docker/build-push-action@v5
        with:
          push: false
          load: true
          context: components/media_proxy
          tags: media_proxy:latest
          cache-from: type=gha,scope=integration-tests-media-proxy
          cache-to: type=gha,mode=max,scope=integration-tests-media-proxy

      - name: Build Gateway Bootstrap
        uses: docker/build-push-action@v5
        with:
          push: false
          load: true
          context: components/gateway
          target: bootstrap
          tags: gateway:bootstrap
          cache-from: type=gha,scope=integration-tests-gateway-bootstrap
          cache-to: type=gha,mode=max,scope=integration-tests-gateway-bootstrap

      - name: Build Testing
        uses: docker/build-push-action@v5
        with:
          push: false
          load: true
          context: components/testing
          tags: testing:latest
          cache-from: type=gha,scope=integration-tests-testing
          cache-to: type=gha,mode=max,scope=integration-tests-testing

      - name: Run docker compose
        run: |
          docker compose run -e DATABASE_NAME=opensips_${{ inputs.context }}_test gateway-bootstrap create_db ${{ inputs.context }}
          docker compose up --wait -d ${{ inputs.context }} media_proxy freeswitch freeswitch_event_logger switch-app redis testing

      - name: Run ${{ inputs.context }} Tests
        run: |
          docker compose exec testing ./tests.sh ./tests/${{ inputs.context }}