Skip to content

Commit

Permalink
feat: Sonarcloud (#24)
Browse files Browse the repository at this point in the history
* feat: added sonarcloud scan

* feat: added mask to include test files
  • Loading branch information
pomykaczi authored Mar 21, 2024
1 parent 494260f commit 16bbd98
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions .github/workflows/sonarcloud-report.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .projen/files.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 61 additions & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { awscdk, javascript } from 'projen';
import { awscdk, javascript, TextFile } from 'projen';
import { WorkflowSteps } from 'projen/lib/github';
import { JobPermission } from 'projen/lib/github/workflows-model';

const project = new awscdk.AwsCdkConstructLibrary({
projenrcTs: true,
Expand Down Expand Up @@ -52,8 +54,66 @@ const project = new awscdk.AwsCdkConstructLibrary({
'/examples/**/cdk.out',
'/examples/**/.git',
'TODO.md',
'.scannerwork/',
],

});

/**
* Sonarcloud report workflow
*/
const sonarCloudReportWorkflow = project.github?.addWorkflow('sonarcloud-report');
sonarCloudReportWorkflow?.on({
push: { branches: ['main', 'beta'] },
pullRequest: {
types: ['opened', 'synchronize', 'reopened'],
},
});
sonarCloudReportWorkflow?.addJob('sonarcloud-report', {
runsOn: ['ubuntu-latest'],
tools: {
node: {
version: project.minNodeVersion!,
},
},
permissions: {
contents: JobPermission.READ,
},
steps: [
WorkflowSteps.checkout({
with: {
fetchDepth: 0,
},
}),
...project.renderWorkflowSetup(),
{
name: 'Run tests',
run: 'npm run test',
},
{
name: 'SonarCloud Scan',
uses: 'SonarSource/sonarcloud-github-action@v2',
env: {
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}',
SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}',
},
},
],
});

/**
* Sonarcloud properties file
*/
new TextFile(project, 'sonar-project.properties', {
lines: [
'sonar.host.url=https://sonarcloud.io',
`sonar.projectKey=${project.name.replace('@', '').replace('/', '_')}`,
`sonar.organization=${project.name.replace('@', '').split('/')[0]}`,
'sonar.javascript.lcov.reportPaths=./coverage/lcov.info',
'sonar.sources=./src',
'sonar.tests=./test',
'sonar.test.inclusions=**/*.test.*',
],
});

project.synth();
7 changes: 7 additions & 0 deletions sonar-project.properties

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16bbd98

Please sign in to comment.