Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ on:
push:
branches:
- '**'
workflow_call:
secrets:
SONAR_HOST_URL:
description: "Sonar host"
required: true
SONAR_TOKEN:
description: "SonarQube token"
required: true
workflow_dispatch:

jobs:
build:
Expand All @@ -17,4 +26,20 @@ jobs:

- run: npm i
- run: npm run build
- run: npm test

- name: Test
run: npm test

- name: Store reporting artifacts for Sonar
uses: actions/upload-artifact@v3
with:
name: sonar-report-artifacts
path: |
coverage/lcov.info

report:
needs: [build]
uses: ./.github/workflows/sonar.yml
secrets:
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
47 changes: 47 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: sonar

on:
workflow_call:
secrets:
SONAR_HOST_URL:
description: "Sonar host"
required: true
SONAR_TOKEN:
description: "SonarQube token"
required: true

env:
LANG: "en_US.UTF-8"
LANGUAGE: "en_US:en"
LC_ALL: "en_US.UTF-8"

jobs:
sonarqube:
name: Sonar analysis
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download reporting artifacts for Sonar
uses: actions/download-artifact@v3
with:
name: sonar-report-artifacts

- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
with:
args:
-Dsonar.verbose=true
# TODO: pass in the latest release tag name
# -Dsonar.projectVersion=${{ xxx }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- name: Remove reporting artifacts for Sonar
uses: geekyeggo/delete-artifact@v2
with:
name: sonar-report-artifacts
failOnError: false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.scannerwork/
coverage/
test-report.xml
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"jscodeshift": "jscodeshift",
"prepare": "npm run build",
"release": "npm run prepare && npx changeset publish",
"test": "jest src",
"test": "jest src --coverage",
"test:watch": "jest --watch src",
"changeset": "npx changeset"
},
Expand Down Expand Up @@ -54,4 +54,4 @@
"tsup": "^6.5.0",
"typescript": "^4.9.4"
}
}
}
23 changes: 23 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Must be unique in a given SonarQube instance
sonar.projectKey=opticks

# This is the name and version displayed in the SonarQube UI.
sonar.projectName=Opticks - Toggle Library
sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file.
sonar.sources=src
sonar.tests=src

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

sonar.exclusions=**/*.test.*

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to exclude mocks as well to correctly reflect the code coverage.

Maybe smth like

Suggested change
sonar.exclusions=**/*.test.*
sonar.exclusions=**/*.test.*,src/mocks/*,

sonar.test.inclusions=**/*.test.tsx,**/*.test.ts

sonar.javascript.coveragePlugin=lcov

# Downloading the artifact does not recreate the directory structure
# so we must consume the lcov.info from the root
# Running locally? use coverage/lcov.info instead
sonar.javascript.lcov.reportPaths=lcov.info