|
| 1 | +name: Check Build and Anchore on PR |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + # Allows you to run this workflow manually from the Actions tab |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + DOCKERFILE: Dockerfile.test-only |
| 10 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 11 | + GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }} |
| 12 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 13 | + PROJECT_KEY: 'pagopa_eng-lollipop-consumer-java-sdk' |
| 14 | + |
| 15 | +jobs: |
| 16 | + pr_scan: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout project sources |
| 24 | + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + - name: Setup Gradle |
| 28 | + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 |
| 29 | + - name: Cache SonarCloud packages |
| 30 | + uses: actions/cache@v1 |
| 31 | + with: |
| 32 | + path: ~/.sonar-project.properties/cache |
| 33 | + key: ${{ runner.os }}-sonar-project.properties |
| 34 | + restore-keys: ${{ runner.os }}-sonar-project.properties |
| 35 | + - name: Make gradlew executable |
| 36 | + run: chmod +x ./gradlew |
| 37 | + - name: Run build with Gradle Wrapper |
| 38 | + run: ./gradlew build testCodeCoverageReport |
| 39 | + - name: Add coverage to PR |
| 40 | + id: jacoco |
| 41 | + uses: madrapps/jacoco-report@7a334255fbce42f385d7567c25d986a9c62e2971 |
| 42 | + with: |
| 43 | + paths: ${{ github.workspace }}/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml |
| 44 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + min-coverage-overall: 40 |
| 46 | + min-coverage-changed-files: 60 |
| 47 | + - name: Build the Docker image |
| 48 | + run: docker build . --file ${{ env.DOCKERFILE }} --tag localbuild/testimage:latest |
| 49 | + - name: Run the Anchore Grype scan action |
| 50 | + uses: anchore/scan-action@d5aa5b6cb9414b0c7771438046ff5bcfa2854ed7 |
| 51 | + id: scan |
| 52 | + with: |
| 53 | + image: "localbuild/testimage:latest" |
| 54 | + fail-build: true |
| 55 | + severity-cutoff: "high" |
| 56 | + - name: Upload Anchore Scan Report |
| 57 | + uses: github/codeql-action/upload-sarif@9885f86fab4879632b7e44514f19148225dfbdcd |
| 58 | + if: always() |
| 59 | + with: |
| 60 | + sarif_file: ${{ steps.scan.outputs.sarif }} |
| 61 | + - name: Run Sonar Scanner on Pull Request |
| 62 | + if: ${{ github.event_name == 'pull_request' }} |
| 63 | + run: ./gradlew sonar --info |
| 64 | + -Dsonar.organization=pagopa |
| 65 | + -Dsonar.projectKey=${{ env.PROJECT_KEY }} |
| 66 | + -Dsonar.coverage.jacoco.xmlReportPaths=**/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml |
| 67 | + -Dsonar.coverage.exclusions="**/config/*","**/*Mock*","**/model/**","**/entity/*","**/*Stub*","**/*Config*,**/*Exception*" |
| 68 | + -Dsonar.cpd.exclusions="**/model/**,**/entity/**,**/simple/internal/**" |
| 69 | + -Dsonar.host.url=https://sonarcloud.io |
| 70 | + -Dsonar.java.libraries="**/*.jar" |
| 71 | + -Dsonar.login=${{ env.SONAR_TOKEN }} |
| 72 | + -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} |
| 73 | + -Dsonar.pullrequest.branch=${{ github.head_ref }} |
| 74 | + -Dsonar.pullrequest.base=${{ github.base_ref }} |
| 75 | + - name: Run Sonar Scanner |
| 76 | + if: ${{ github.event_name != 'pull_request' }} |
| 77 | + run: ./gradlew sonar --info |
| 78 | + -Dsonar.organization=pagopa |
| 79 | + -Dsonar.projectKey=${{ env.PROJECT_KEY }} |
| 80 | + -Dsonar.coverage.jacoco.xmlReportPaths=**/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml |
| 81 | + -Dsonar.coverage.exclusions="**/config/*","**/*Mock*","**/model/**","**/entity/*","**/*Stub*","**/*Config*,**/*Exception*" |
| 82 | + -Dsonar.cpd.exclusions="**/model/**,**/entity/**,**/simple/internal/**" |
| 83 | + -Dsonar.host.url=https://sonarcloud.io |
| 84 | + -Dsonar.java.libraries="**/*.jar" |
| 85 | + -Dsonar.login=${{ env.SONAR_TOKEN }} |
| 86 | + -Dsonar.branch.name=${{ github.head_ref }} |
| 87 | + - name: Publish to Maven Local |
| 88 | + run: ./gradlew publishToMavenLocal |
| 89 | + - name: Build Spring Sample |
| 90 | + working-directory: ./samples/spring |
| 91 | + run: chmod +x ./gradlew && ./gradlew bootJar |
| 92 | + - name: Run Docker compose with .env.dev |
| 93 | + run: docker compose --env-file e2e/.env.dev up -d --build --wait |
| 94 | + - name: Sleep for 30 seconds |
| 95 | + run: sleep 30s |
| 96 | + shell: bash |
| 97 | + - name: Install node modules and execute e2e tests |
| 98 | + working-directory: ./e2e |
| 99 | + run: npm install && npm run execute-test |
| 100 | + - name: Shutdown docker compose |
| 101 | + run: docker compose down |
0 commit comments