stages:
  - test

default:
  services:
    - name: dnhsoft/mysql-utf8:5.7-mb4
      alias: mysql
  before_script:
    - |
        curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
        -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
        -d "{\"state\": \"pending\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
    - set +e

variables:
  REPO_NAME: qore
  POSTGRES_PASSWORD: omq
  TZ: 'Europe/Prague'
  PGTZ: 'Europe/Prague'
  TDSVER: "7.3"
  MYSQL_DATABASE: omq
  MYSQL_ROOT_PASSWORD: omq
  QORE_DB_CONNSTR_MYSQL: 'mysql:root/omq@omq(UTF8)%mysql'

test-ubuntu-amd64:
  stage: test
  image: $CI_REGISTRY/infrastructure/qore-test-base/qore-test-base:develop
  tags:
    - amd64
  variables:
    QORE_DB_CONNSTR_FREETDS: 'freetds:test/test@rippy'
  script:
    - |
        if test/docker_test/test-ubuntu.sh; then
          curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
            -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
            -d "{\"state\": \"success\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
          exit 0
        else
          curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
            -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
            -d "{\"state\": \"failure\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
          exit 1
        fi

test-ubuntu-arm64:
  stage: test
  image: $CI_REGISTRY/infrastructure/qore-test-base/qore-test-base:develop-arm64
  tags:
    - arm64
  variables:
    QORE_DB_CONNSTR_FREETDS: 'freetds:test/test@rippy'
  script:
    - |
        if test/docker_test/test-ubuntu.sh; then
          curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
            -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
            -d "{\"state\": \"success\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
          exit 0
        else
          curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
            -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
            -d "{\"state\": \"failure\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
          exit 1
        fi

test-alpine-amd64:
  stage: test
  image: $CI_REGISTRY/infrastructure/qore-test-base/qore-test-base:develop-alpine
  tags:
    - amd64
  variables:
    QORE_DB_CONNSTR_FREETDS: 'freetds:test/test@rippy'
  script:
    - |
        if test/docker_test/test-alpine.sh; then
          curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
            -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
            -d "{\"state\": \"success\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
          exit 0
        else
          curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
            -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
            -d "{\"state\": \"failure\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
          exit 1
        fi

test-alpine-arm64:
  stage: test
  image: $CI_REGISTRY/infrastructure/qore-test-base/qore-test-base:develop-alpine-arm64
  tags:
    - arm64
  variables:
    QORE_DB_CONNSTR_FREETDS: 'freetds:test/test@rippy'
  script:
    - |
        if test/docker_test/test-alpine.sh; then
          curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
            -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
            -d "{\"state\": \"success\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
          exit 0
        else
          curl "https://api.github.com/repos/qorelanguage/${REPO_NAME}/statuses/${CI_COMMIT_SHA}" \
            -X POST -u omusil24:${GITHUB_ACCESS_TOKEN} -H "Content-Type: application/json" \
            -d "{\"state\": \"failure\", \"context\": \"${REPO_NAME}\", \"description\": \"Gitlab CI\", \"target_url\": \"${CI_JOB_URL}\"}"
          exit 1
        fi
