Hotfix/java25 (#473) #525
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Description | |
| # =========== | |
| # This workflow is triggered each time | |
| # commits are pushed to GitHub or a pull request is opened. | |
| # It launches jobs in parallel with every Java and Sonarqube version | |
| # we want to support | |
| --- | |
| name: Java CI | |
| on: [push, pull_request] | |
| env: | |
| JAVA_BUILD_VERSION: "21" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-22.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| java: [ '21', '22', '23', '24', '25', '26' ] | |
| sonarqube: ['25.6.0.109173-community', '26.3.0.120487-community', 'community'] | |
| name: Tests with JAVA ${{ matrix.java }} and SONARQUBE ${{ matrix.sonarqube }} | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup java for build | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'adopt' | |
| java-version: ${{ env.JAVA_BUILD_VERSION }} | |
| - name: Cache Maven packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-m2 | |
| - name: Cache node_modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} | |
| restore-keys: ${{ runner.os }}-yarn- | |
| - name: Build with Maven | |
| run: mvn -B clean package | |
| - name: Setup java for execution | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'adopt' | |
| java-version: ${{ matrix.java }} | |
| - name: Test cnes-report Sonarqube ${{ matrix.sonarqube }} | |
| env: | |
| SONARQUBE_VERSION: ${{ matrix.sonarqube }} | |
| run: | | |
| version=$(cat pom.xml | grep "<version>.*</version>" | head -1 |awk -F'[><]' '{print $3}'); | |
| echo "Starting docker"; | |
| docker run --name sonarqube_${SONARQUBE_VERSION} -d -p 9000:9000 sonarqube:${SONARQUBE_VERSION}; | |
| echo "Inject plugin"; | |
| docker cp target/sonar-cnes-report-${version}.jar sonarqube_${SONARQUBE_VERSION}:/opt/sonarqube/extensions/plugins/; | |
| docker restart sonarqube_${SONARQUBE_VERSION}; | |
| echo "Waiting up to 5 minutes for SonarQube..."; | |
| counter=0; | |
| limit=300; | |
| status_sonar=$(curl -s "http://localhost:9000/api/system/status" | grep "\"status\":\"UP\"" > /dev/null; echo $?); | |
| while [[ 0 -ne $status_sonar && $counter -le $limit ]]; do | |
| sleep 1; | |
| counter=$(( $counter + 1 )); | |
| status_sonar=$(curl -s "http://localhost:9000/api/system/status" | grep "\"status\":\"UP\"" > /dev/null; echo $?); | |
| done; | |
| echo "SonarQube is $([[ 0 -eq $status_sonar ]] && echo "up" || echo "down"), after $counter tries"; | |
| token_sonarqube=$(curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "name=admin_token" -u admin:admin http://localhost:9000/api/user_tokens/generate | jq -r '.token'); | |
| mvn sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.token=${token_sonarqube} -Dsonar.organization=default-organization; | |
| echo "Waiting for the SonarQube Compute Engine task to be completed..."; | |
| ce=$(grep ceTaskUrl= target/sonar/report-task.txt); | |
| ceTaskUrl=${ce:10}; | |
| continue=true; | |
| while [ $continue = true ]; do | |
| status=$(curl -s -u admin:admin ${ceTaskUrl} | jq -r '.task.status'); | |
| if [ $status = SUCCESS ] | |
| then | |
| continue=false; | |
| elif [ $status = FAILED ] || [ $status = CANCELED ] | |
| then | |
| exit 1; | |
| else | |
| sleep 1; | |
| fi | |
| done; | |
| java -jar target/sonar-cnes-report-${version}.jar -t ${token_sonarqube} -p fr.cnes.sonar:cnesreport -s http://localhost:9000 > logs.txt 2>&1; | |
| cat logs.txt | |
| if grep -q -i "error" "logs.txt"; then | |
| echo "WARNING: Cnes report send an error in logs but exited normally" | |
| exit 1; | |
| fi | |
| url_cnesreport="http://localhost:9000/api/cnesreport/report?key=fr.cnes.sonar%3Acnesreport&author=github-actions&token=${token_sonarqube}"; | |
| curl -u admin:admin ${url_cnesreport} -O -J; | |
| code-analysis: | |
| runs-on: ubuntu-22.04 | |
| name: SonarCloud Code Analysis | |
| # It's not possible to launch an analysis on external pull requests | |
| if: ${{ github.repository_owner == 'cnescatlab' }} | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
| - name: Setup java | |
| uses: actions/setup-java@v2 | |
| with: | |
| distribution: 'adopt' | |
| java-version: ${{ env.JAVA_BUILD_VERSION }} | |
| - name: Cache Maven packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-m2 | |
| - name: Cache node_modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} | |
| restore-keys: ${{ runner.os }}-yarn- | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Build and analyze | |
| env: | |
| # Needed to get some information about the pull request, if any | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # SonarCloud access token should be generated from https://sonarcloud.io/account/security/ | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.token=$SONAR_TOKEN |