diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000000..87ece17604b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,89 @@ +name: CI/CD workflow for Maven Build and SonarQube Scan + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: 17 + + - name: Set JAVA_HOME + run: echo "JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" >> $GITHUB_ENV + + - name: Verify Java Version + run: java -version + + - name: Cache Maven packages + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + + - name: Cache SonarQube packages + uses: actions/cache@v2 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Setup Maven settings + run: | + mkdir -p ~/.m2 + echo ' + + + opendaylight-snapshot + https://nexus.opendaylight.org/content/repositories/opendaylight-snapshot/ + opendaylight-snapshot + + + ' > ~/.m2/settings.xml + + - name: Build with Maven + run: mvn clean install -U --settings ~/.m2/settings.xml + continue-on-error: true + + - name: Archive Surefire Reports + if: always() + uses: actions/upload-artifact@v2 + with: + name: surefire-reports + path: | + **/target/surefire-reports/ + + - name: Install SonarQube Scanner + run: | + sudo apt-get update + sudo apt-get install -y unzip + wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-linux.zip + unzip sonar-scanner-cli-4.6.2.2472-linux.zip + export PATH=$PATH:$(pwd)/sonar-scanner-4.6.2.2472-linux/bin + + - name: Run SonarQube Scan + run: | + sonar-scanner \ + -Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }} \ + -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \ + -Dsonar.login=${{ secrets.SONAR_TOKEN }} + env: + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + continue-on-error: true diff --git a/pom.xml b/pom.xml index 4862fdc24a0..2c75b1b7fad 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,20 @@ true true + + http://localhost:9000 + + + + opendaylight-snapshots + https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ + + true + + + + artifacts diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000000..1cfcdeb1d43 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1 @@ +sonar.projectKey=netconf