|
9 | 9 |
|
10 | 10 | jobs: |
11 | 11 | build: |
12 | | - |
| 12 | + name: Maven Build |
13 | 13 | runs-on: ubuntu-latest |
14 | 14 | steps: |
15 | 15 | - name: Git Clone |
16 | | - uses: actions/checkout@v4 |
| 16 | + uses: actions/checkout@v6 |
17 | 17 | - name: Set up JDK 21 |
18 | | - uses: actions/setup-java@v4 |
| 18 | + uses: actions/setup-java@v5 |
19 | 19 | with: |
20 | 20 | distribution: 'temurin' |
21 | 21 | java-version: 21 |
22 | 22 | # generate settings.xml with the correct values |
23 | 23 | server-id: sonatype-central-portal # Value of the distributionManagement/repository/id field of the pom.xml |
24 | | - server-username: MAVEN_USERNAME # env variable for username in deploy |
25 | | - server-password: MAVEN_PASSWORD # env variable for token in deploy |
| 24 | + server-username: MAVEN_CENTRAL_PORTAL_USERNAME # env variable for username in deploy |
| 25 | + server-password: MAVEN_CENTRAL_PORTAL_PASSWORD # env variable for token in deploy |
26 | 26 | - name: Adjust Git Config |
27 | 27 | run: | |
28 | 28 | git config --global user.email "action@github.com" |
29 | 29 | git config --global user.name "GitHub Action" |
30 | | - - name: Build and Analyse Reactor with Maven |
31 | | - if: github.ref != 'refs/heads/master' |
32 | | - run: ./mvnw -B clean install org.sonarsource.scanner.maven:sonar-maven-plugin:5.2.0.4988:sonar -Dsonar.projectKey=Netcentric_aem-classification -Dsonar.organization=netcentric -Dsonar.host.url=https://sonarcloud.io -Dsonar.scanner.skipJreProvisioning=true -Pcoverage-report |
33 | | - env: |
34 | | - # SonarCloud access token should be generated from https://sonarcloud.io/account/security/ |
35 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
36 | | - # Needed to get some information about the pull request, if any |
37 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
38 | | - - name: Build Site for Maven Plugin |
39 | | - if: github.ref != 'refs/heads/master' |
40 | | - run: ./mvnw -B clean site --file aem-classification-maven-plugin/pom.xml |
41 | | - - name: Build, Analyse and Deploy Reactor with Maven |
42 | | - if: github.ref == 'refs/heads/master' |
43 | | - run: ./mvnw -B clean deploy org.sonarsource.scanner.maven:sonar-maven-plugin:5.2.0.4988:sonar -Dsonar.projectKey=Netcentric_aem-classification -Dsonar.organization=netcentric -Dsonar.host.url=https://sonarcloud.io -Dsonar.scanner.skipJreProvisioning=true -Pcoverage-report |
44 | | - env: |
45 | | - MAVEN_USERNAME: ${{ secrets.SONATYPE_CENTRAL_TOKEN_USER }} |
46 | | - MAVEN_PASSWORD: ${{ secrets.SONATYPE_CENTRAL_TOKEN_PASSWORD }} |
47 | | - # SonarCloud access token should be generated from https://sonarcloud.io/account/security/ |
48 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
49 | | - # Needed to get some information about the pull request, if any |
50 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + # sets environment variables to be used in subsequent steps: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable |
| 31 | + - name: Set environment variables |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + if [ "${{github.ref}}" = "refs/heads/master" ] && [ "${{github.event_name}}" = "push" ] && [ "${{github.repository_owner}}" = "Netcentric" ]; then |
| 35 | + echo 'Running on main branch of the canonical repo' |
| 36 | + echo "MVN_ADDITIONAL_OPTS=-DdeployAtEnd=true" >> $GITHUB_ENV |
| 37 | + echo "MVN_GOAL=deploy" >> $GITHUB_ENV |
| 38 | + echo "MAVEN_CENTRAL_PORTAL_USERNAME=${{ secrets.SONATYPE_CENTRAL_TOKEN_USER }}" >> $GITHUB_ENV |
| 39 | + echo "MAVEN_CENTRAL_PORTAL_PASSWORD=${{ secrets.SONATYPE_CENTRAL_TOKEN_PASSWORD }}" >> $GITHUB_ENV |
| 40 | + else |
| 41 | + echo 'Running outside main branch/canonical repo' |
| 42 | + echo "MVN_ADDITIONAL_OPTS=" >> $GITHUB_ENV |
| 43 | + echo "MVN_GOAL=verify" >> $GITHUB_ENV |
| 44 | + fi |
| 45 | + - name: Build |
| 46 | + run: ./mvnw -B ${{ env.MVN_GOAL }} ${{ env.MVN_ADDITIONAL_OPTS }} -Pcoverage-report |
| 47 | + - name: Upload build result for subsequent SonarQube job |
| 48 | + # not supported on forks, https://portal.productboard.com/sonarsource/1-sonarqube-cloud/c/50-sonarcloud-analyzes-external-pull-request |
| 49 | + if: github.repository == 'Netcentric/aem-classification' |
| 50 | + uses: actions/upload-artifact@v4 |
| 51 | + with: |
| 52 | + name: compiled-classes-and-coverage |
| 53 | + # compare with https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/java/#java-analysis-and-bytecode |
| 54 | + path: | |
| 55 | + **/target/**/*.class |
| 56 | + **/target/site/jacoco*/*.xml |
51 | 57 | - name: Build Site for Maven Plugin |
52 | 58 | if: github.ref == 'refs/heads/master' |
53 | | - run: ./mvnw -B clean site --file aem-classification-maven-plugin/pom.xml |
| 59 | + run: ./mvnw -B site --file aem-classification-maven-plugin/pom.xml |
54 | 60 | - name: Upload Site for Maven Plugin |
55 | 61 | if: github.ref == 'refs/heads/master' |
56 | | - uses: actions/upload-pages-artifact@v3 |
| 62 | + uses: actions/upload-pages-artifact@v4 |
57 | 63 | with: |
58 | 64 | path: aem-classification-maven-plugin/target/site/ |
| 65 | + # execute analysis in a separate job for better visualization and usage of matrix builds |
| 66 | + # https://docs.sonarsource.com/sonarcloud/advanced-setup/ci-based-analysis/sonarscanner-for-maven/#invoking-the-goal |
| 67 | + sonarqube: |
| 68 | + name: SonarQube Analysis |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: build |
| 71 | + # not supported on forks, https://portal.productboard.com/sonarsource/1-sonarqube-cloud/c/50-sonarcloud-analyzes-external-pull-request |
| 72 | + if: github.repository == 'Netcentric/aem-classification' |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + with: |
| 76 | + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis |
| 77 | + - name: Set up JDK 21 |
| 78 | + uses: actions/setup-java@v5 |
| 79 | + with: |
| 80 | + java-version: 21 |
| 81 | + distribution: temurin |
| 82 | + cache: maven |
| 83 | + - name: Download compiled classes |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + name: compiled-classes-and-coverage |
| 87 | + - name: Cache SonarQube packages |
| 88 | + uses: actions/cache@v4 |
| 89 | + with: |
| 90 | + path: ~/.sonar/cache |
| 91 | + key: ${{ runner.os }}-sonar |
| 92 | + restore-keys: ${{ runner.os }}-sonar |
| 93 | + - name: Analyze with SonarQube |
| 94 | + env: |
| 95 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
| 96 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 97 | + run: ./mvnw -B org.sonarsource.scanner.maven:sonar-maven-plugin:5.5.0.6356:sonar -Dsonar.projectKey=Netcentric_aem-classification -Dsonar.organization=netcentric -Dsonar.host.url=https://sonarcloud.io -Dsonar.scanner.skipJreProvisioning=true |
59 | 98 | deploy: |
| 99 | + name: Deploy to GH Pages |
60 | 100 | if: github.ref == 'refs/heads/master' |
61 | 101 | # Add a dependency to the build job |
62 | 102 | needs: build |
|
0 commit comments