resources:
- repo: self
  fetchDepth: 1

jobs:
- job: linux_clang
  displayName: linux-clang
  condition: succeeded()
  pool: Hosted Ubuntu 1604
  steps:
  - bash: |
       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

       sudo apt-get update &&
       sudo apt-get -y install git gcc make libssl-dev libcurl4-openssl-dev libexpat-dev tcl tk gettext git-email zlib1g-dev apache2-bin &&

       export CC=clang || exit 1

       ci/install-dependencies.sh || exit 1
       ci/run-build-and-tests.sh || {
           ci/print-test-failures.sh
           exit 1
       }

       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
    displayName: 'ci/run-build-and-tests.sh'
    env:
      GITFILESHAREPWD: $(gitfileshare.pwd)
  - task: PublishTestResults@2
    displayName: 'Publish Test Results **/TEST-*.xml'
    inputs:
      mergeTestResults: true
      testRunTitle: 'linux-clang'
      platform: Linux
      publishRunAttachments: false
    condition: succeededOrFailed()
  - task: PublishBuildArtifacts@1
    displayName: 'Publish trash directories of failed tests'
    condition: failed()
    inputs:
      PathtoPublish: t/failed-test-artifacts
      ArtifactName: failed-test-artifacts

- job: linux_gcc
  displayName: linux-gcc
  condition: succeeded()
  pool: Hosted Ubuntu 1604
  steps:
  - bash: |
       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

       sudo add-apt-repository ppa:ubuntu-toolchain-r/test &&
       sudo apt-get update &&
       sudo apt-get -y install git gcc make libssl-dev libcurl4-openssl-dev libexpat-dev tcl tk gettext git-email zlib1g-dev apache2 language-pack-is git-svn gcc-8 || exit 1

       ci/install-dependencies.sh || exit 1
       ci/run-build-and-tests.sh || {
           ci/print-test-failures.sh
           exit 1
       }

       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
    displayName: 'ci/run-build-and-tests.sh'
    env:
      GITFILESHAREPWD: $(gitfileshare.pwd)
  - task: PublishTestResults@2
    displayName: 'Publish Test Results **/TEST-*.xml'
    inputs:
      mergeTestResults: true
      testRunTitle: 'linux-gcc'
      platform: Linux
      publishRunAttachments: false
    condition: succeededOrFailed()
  - task: PublishBuildArtifacts@1
    displayName: 'Publish trash directories of failed tests'
    condition: failed()
    inputs:
      PathtoPublish: t/failed-test-artifacts
      ArtifactName: failed-test-artifacts

- job: osx_clang
  displayName: osx-clang
  condition: succeeded()
  pool: Hosted macOS
  steps:
  - bash: |
       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

       export CC=clang

       ci/install-dependencies.sh || exit 1
       ci/run-build-and-tests.sh || {
           ci/print-test-failures.sh
           exit 1
       }

       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || umount "$HOME/test-cache" || exit 1
    displayName: 'ci/run-build-and-tests.sh'
    env:
      GITFILESHAREPWD: $(gitfileshare.pwd)
  - task: PublishTestResults@2
    displayName: 'Publish Test Results **/TEST-*.xml'
    inputs:
      mergeTestResults: true
      testRunTitle: 'osx-clang'
      platform: macOS
      publishRunAttachments: false
    condition: succeededOrFailed()
  - task: PublishBuildArtifacts@1
    displayName: 'Publish trash directories of failed tests'
    condition: failed()
    inputs:
      PathtoPublish: t/failed-test-artifacts
      ArtifactName: failed-test-artifacts

- job: osx_gcc
  displayName: osx-gcc
  condition: succeeded()
  pool: Hosted macOS
  steps:
  - bash: |
       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

       ci/install-dependencies.sh || exit 1
       ci/run-build-and-tests.sh || {
           ci/print-test-failures.sh
           exit 1
       }

       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || umount "$HOME/test-cache" || exit 1
    displayName: 'ci/run-build-and-tests.sh'
    env:
      GITFILESHAREPWD: $(gitfileshare.pwd)
  - task: PublishTestResults@2
    displayName: 'Publish Test Results **/TEST-*.xml'
    inputs:
      mergeTestResults: true
      testRunTitle: 'osx-gcc'
      platform: macOS
      publishRunAttachments: false
    condition: succeededOrFailed()
  - task: PublishBuildArtifacts@1
    displayName: 'Publish trash directories of failed tests'
    condition: failed()
    inputs:
      PathtoPublish: t/failed-test-artifacts
      ArtifactName: failed-test-artifacts

- job: gettext_poison
  displayName: GETTEXT_POISON
  condition: succeeded()
  pool: Hosted Ubuntu 1604
  steps:
  - bash: |
       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

       sudo apt-get update &&
       sudo apt-get -y install git gcc make libssl-dev libcurl4-openssl-dev libexpat-dev tcl tk gettext git-email zlib1g-dev &&

       export jobname=GETTEXT_POISON || exit 1

       ci/run-build-and-tests.sh || {
           ci/print-test-failures.sh
           exit 1
       }

       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
    displayName: 'ci/run-build-and-tests.sh'
    env:
      GITFILESHAREPWD: $(gitfileshare.pwd)
  - task: PublishTestResults@2
    displayName: 'Publish Test Results **/TEST-*.xml'
    inputs:
      mergeTestResults: true
      testRunTitle: 'gettext-poison'
      platform: Linux
      publishRunAttachments: false
    condition: succeededOrFailed()
  - task: PublishBuildArtifacts@1
    displayName: 'Publish trash directories of failed tests'
    condition: failed()
    inputs:
      PathtoPublish: t/failed-test-artifacts
      ArtifactName: failed-test-artifacts

- job: linux32
  displayName: Linux32
  condition: succeeded()
  pool: Hosted Ubuntu 1604
  steps:
  - bash: |
       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

       res=0
       sudo AGENT_OS="$AGENT_OS" BUILD_BUILDNUMBER="$BUILD_BUILDNUMBER" BUILD_REPOSITORY_URI="$BUILD_REPOSITORY_URI" BUILD_SOURCEBRANCH="$BUILD_SOURCEBRANCH" BUILD_SOURCEVERSION="$BUILD_SOURCEVERSION" SYSTEM_PHASENAME="$SYSTEM_PHASENAME" SYSTEM_TASKDEFINITIONSURI="$SYSTEM_TASKDEFINITIONSURI" SYSTEM_TEAMPROJECT="$SYSTEM_TEAMPROJECT" CC=$CC MAKEFLAGS="$MAKEFLAGS" bash -lxc ci/run-linux32-docker.sh || res=1

       sudo chmod a+r t/out/TEST-*.xml
       test ! -d t/failed-test-artifacts || sudo chmod a+r t/failed-test-artifacts

       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || res=1
       exit $res
    displayName: 'ci/run-linux32-docker.sh'
    env:
      GITFILESHAREPWD: $(gitfileshare.pwd)
  - task: PublishTestResults@2
    displayName: 'Publish Test Results **/TEST-*.xml'
    inputs:
      mergeTestResults: true
      testRunTitle: 'linux32'
      platform: Linux
      publishRunAttachments: false
    condition: succeededOrFailed()
  - task: PublishBuildArtifacts@1
    displayName: 'Publish trash directories of failed tests'
    condition: failed()
    inputs:
      PathtoPublish: t/failed-test-artifacts
      ArtifactName: failed-test-artifacts

- job: static_analysis
  displayName: StaticAnalysis
  condition: succeeded()
  pool: Hosted Ubuntu 1604
  steps:
  - bash: |
       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

       sudo apt-get update &&
       sudo apt-get install -y coccinelle &&

       export jobname=StaticAnalysis &&

       ci/run-static-analysis.sh || exit 1

       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
    displayName: 'ci/run-static-analysis.sh'
    env:
      GITFILESHAREPWD: $(gitfileshare.pwd)

- job: documentation
  displayName: Documentation
  condition: succeeded()
  pool: Hosted Ubuntu 1604
  steps:
  - bash: |
       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1

       sudo apt-get update &&
       sudo apt-get install -y asciidoc xmlto asciidoctor &&

       export ALREADY_HAVE_ASCIIDOCTOR=yes. &&
       export jobname=Documentation &&

       ci/test-documentation.sh || exit 1

       test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || exit 1
    displayName: 'ci/test-documentation.sh'
    env:
      GITFILESHAREPWD: $(gitfileshare.pwd)
