#! /bin/bash
# ==================================================================
# Copyright (c) 2023 Eclipse Foundation.
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
#
# SPDX-License-Identifier: EPL-2.0
# ==================================================================

# Create temp folder
mkdir -p tmp
cd tmp

# Create array of project names
projects[0]="eclipsefdn-api-common"
projects[1]="eclipsefdn-committer-paperwork-api"
projects[2]="eclipsefdn-cve-api"
projects[3]="eclipsefdn-downloads-api"
projects[4]="eclipsefdn-foundationdb-api"
projects[5]="eclipsefdn-mailing-lists-api"
projects[6]="eclipsefdn-media-link-api"
projects[7]="eclipsefdn-profile-api"
projects[8]="eclipsefdn-project-adopters"
projects[9]="eclipsefdn-uss-api"
projects[10]="eclipsefdn-working-groups-api"
projects[11]="eclipsefdn-hellosign-api"
projects[12]="eclipse-openvsx-api"
projects[13]="geoip-rest-api"
projects[14]="git-eca-rest-api"

# Clone each project, pulling all new changes in case it already exists
# Generates test resources, runs tests, and runs sonar scan
for i in "${projects[@]}"; do
    git clone git@gitlab.eclipse.org:eclipsefdn/it/api/$i.git
    (cd $i && git pull && mvn clean && make compile-test-resources)
    mvn -f ./$i test sonar:sonar -Dsonar.host.url=$SONAR_HOST -Dsonar.login=$SONAR_TOKEN
done
