Skip to content

Commit

Permalink
ci(sage-monorepo): parametrize sonar scanner tool (#2458)
Browse files Browse the repository at this point in the history
* Touch oc web app

* Ignore .nx

* Save before trying Bard suggestion

* Upgrade sonar scanner to support PR

* Simplify command

* Cleanpu

* Set working dir

* Specify PR number to SonarScanner for Gradle

* Remove scanner tool proto

* Sort Ci env vars in alphanum

* Update message
  • Loading branch information
tschaffter authored Jan 25, 2024
1 parent 78cb3b3 commit 19352e8
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 81 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ on:
types: [opened, synchronize, reopened]

env:
HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}

jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout ${{ env.HEAD_REF }} from repository ${{ env.HEAD_REPOSITORY }}
name: Checkout ${{ env.HEAD_REPOSITORY }}:${{ env.HEAD_REF }}
with:
ref: ${{ env.HEAD_REF }}
repository: ${{ env.HEAD_REPOSITORY }}
Expand All @@ -25,10 +24,10 @@ jobs:
- name: Set up the dev container
uses: ./.github/actions/setup-dev-container

- name: Scan scanner prototype for openchallenges-app
run: ./tools/sonar-scanner-for-pr.sh sage-monorepo apps/openchallenges/app ${{github.event.pull_request.number}} "${{env.HEAD_REPOSITORY}}:${{env.HEAD_REF}}"

# - name: Scan the affected projects with Sonar
# run: |
# devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \
# && nx affected --target=sonar"
- name: Scan the affected projects with Sonar
env:
SONAR_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
devcontainer exec --workspace-folder ../sage-monorepo bash -c ". ./dev-env.sh \
&& nx affected --target=sonar"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!.yarn/sdks
!.yarn/versions
.nx-container/
.nx/
.pnpm-store/
.scannerwork/
playwright-report/
Expand Down
66 changes: 50 additions & 16 deletions apps/openchallenges/app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
"sonar": {
"executor": "nx:run-commands",
"options": {
"command": "bash $WORKSPACE_DIR/tools/sonar-scanner.sh {projectName}",
"command": "bash $WORKSPACE_DIR/tools/sonar-scanner.sh --project-key {projectName} --project-dir .",
"cwd": "{projectRoot}"
}
},
"build": {
"executor": "@angular-devkit/build-angular:browser",
"outputs": ["{options.outputPath}"],
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/apps/openchallenges/app/browser/browser",
"index": "apps/openchallenges/app/src/index.html",
"main": "apps/openchallenges/app/src/main.ts",
"polyfills": ["zone.js"],
"polyfills": [
"zone.js"
],
"tsConfig": "apps/openchallenges/app/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
Expand Down Expand Up @@ -119,7 +123,10 @@
"lint": {
"executor": "@nx/linter:eslint",
"options": {
"lintFilePatterns": ["apps/openchallenges/app/**/*.ts", "apps/openchallenges/app/**/*.html"]
"lintFilePatterns": [
"apps/openchallenges/app/**/*.ts",
"apps/openchallenges/app/**/*.html"
]
}
},
"lint-fix": {
Expand All @@ -134,7 +141,9 @@
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/openchallenges/app"],
"outputs": [
"{workspaceRoot}/coverage/apps/openchallenges/app"
],
"options": {
"jestConfig": "apps/openchallenges/app/jest.config.ts",
"passWithNoTests": true
Expand All @@ -145,24 +154,39 @@
"options": {
"context": ".",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/openchallenges-app"],
"tags": ["type=edge,branch=main", "type=raw,value=local", "type=sha"]
"images": [
"ghcr.io/sage-bionetworks/openchallenges-app"
],
"tags": [
"type=edge,branch=main",
"type=raw,value=local",
"type=sha"
]
},
"push": false
},
"dependsOn": ["server"]
"dependsOn": [
"server"
]
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": ".",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/openchallenges-app"],
"tags": ["type=edge,branch=main", "type=sha"]
"images": [
"ghcr.io/sage-bionetworks/openchallenges-app"
],
"tags": [
"type=edge,branch=main",
"type=sha"
]
},
"push": true
},
"dependsOn": ["build-image"]
"dependsOn": [
"build-image"
]
},
"scan-image": {
"executor": "nx:run-commands",
Expand All @@ -172,7 +196,9 @@
}
},
"server": {
"dependsOn": ["build"],
"dependsOn": [
"build"
],
"executor": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/apps/openchallenges/app/browser/server",
Expand Down Expand Up @@ -211,7 +237,9 @@
"prerender": {
"executor": "@nguniversal/builders:prerender",
"options": {
"routes": ["/"]
"routes": [
"/"
]
},
"configurations": {
"development": {
Expand All @@ -233,16 +261,22 @@
},
"e2e": {
"executor": "@nx/playwright:playwright",
"outputs": ["{workspaceRoot}/dist/.playwright/apps/openchallenges/app"],
"outputs": [
"{workspaceRoot}/dist/.playwright/apps/openchallenges/app"
],
"options": {
"config": "apps/openchallenges/app/playwright.config.ts"
}
}
},
"tags": ["type:app", "scope:client", "language:typescript"],
"tags": [
"type:app",
"scope:client",
"language:typescript"
],
"implicitDependencies": [
"openchallenges-styles",
"openchallenges-themes",
"shared-typescript-assets"
]
}
}
1 change: 1 addition & 0 deletions apps/openchallenges/app/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<openchallenges-google-tag-manager *ngIf="useGoogleTagManager" />
<!-- XXX -->
<openchallenges-navbar
class="mat-elevation-z6"
[title]="title"
Expand Down
8 changes: 5 additions & 3 deletions apps/openchallenges/challenge-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies {
implementation "org.springframework.cloud:spring-cloud-sleuth-zipkin:${springCloudVersion}"

implementation "org.sagebionetworks.openchallenges:openchallenges-app-config-data:${openchallengesVersion}"

implementation 'io.micrometer:micrometer-registry-prometheus:1.10.4'
}

Expand Down Expand Up @@ -104,9 +104,11 @@ jacocoTestReport {

sonar {
properties {
property("sonar.projectKey", "${project.name}")
property("sonar.organization", "sage-bionetworks")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.organization", "sage-bionetworks")
property("sonar.projectKey", "${project.name}")
// Include the pull request number (ignored if not set)
property("sonar.pullrequest.key", System.getenv('SONAR_PULL_REQUEST_NUMBER'))
}
}

Expand Down
2 changes: 2 additions & 0 deletions apps/openchallenges/image-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@ sonar {
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.coverage.exclusions", autoGeneratedFiles.join(","))
// property("sonar.log.level", "DEBUG")
// Include the pull request number (ignored if not set)
property("sonar.pullrequest.key", System.getenv('SONAR_PULL_REQUEST_NUMBER'))
}
}
2 changes: 2 additions & 0 deletions apps/openchallenges/organization-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ sonar {
property("sonar.projectKey", "openchallenges-organization-service")
property("sonar.organization", "sage-bionetworks")
property("sonar.host.url", "https://sonarcloud.io")
// Include the pull request number (ignored if not set)
property("sonar.pullrequest.key", System.getenv('SONAR_PULL_REQUEST_NUMBER'))
}
}

Expand Down
47 changes: 36 additions & 11 deletions apps/schematic/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@
"options": {
"context": "apps/schematic/api",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/schematic-api"],
"tags": ["type=edge,branch=main", "type=raw,value=local", "type=sha"]
"images": [
"ghcr.io/sage-bionetworks/schematic-api"
],
"tags": [
"type=edge,branch=main",
"type=raw,value=local",
"type=sha"
]
},
"push": false
}
Expand All @@ -47,12 +53,19 @@
"options": {
"context": "apps/schematic/api",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/schematic-api"],
"tags": ["type=edge,branch=main", "type=sha"]
"images": [
"ghcr.io/sage-bionetworks/schematic-api"
],
"tags": [
"type=edge,branch=main",
"type=sha"
]
},
"push": true
},
"dependsOn": ["build-image"]
"dependsOn": [
"build-image"
]
},
"scan-image": {
"executor": "nx:run-commands",
Expand All @@ -64,11 +77,16 @@
"generate": {
"executor": "nx:run-commands",
"options": {
"commands": ["xargs rm -fr <.openapi-generator/FILES", "openapi-generator-cli generate"],
"commands": [
"xargs rm -fr <.openapi-generator/FILES",
"openapi-generator-cli generate"
],
"cwd": "{projectRoot}",
"parallel": false
},
"dependsOn": ["^build"]
"dependsOn": [
"^build"
]
},
"lint": {
"executor": "nx:run-commands",
Expand Down Expand Up @@ -126,11 +144,18 @@
"sonar": {
"executor": "nx:run-commands",
"options": {
"command": "bash $WORKSPACE_DIR/tools/sonar-scanner.sh {projectName}",
"command": "bash $WORKSPACE_DIR/tools/sonar-scanner.sh --project-key {projectName} --project-dir .",
"cwd": "{projectRoot}"
}
}
},
"tags": ["type:service", "scope:backend", "language:python", "package-manager:poetry"],
"implicitDependencies": ["schematic-api-description"]
}
"tags": [
"type:service",
"scope:backend",
"language:python",
"package-manager:poetry"
],
"implicitDependencies": [
"schematic-api-description"
]
}
26 changes: 0 additions & 26 deletions tools/sonar-scanner-for-pr.sh

This file was deleted.

Loading

0 comments on commit 19352e8

Please sign in to comment.