Skip to content

Commit

Permalink
ci: adding sonar to action (#12)
Browse files Browse the repository at this point in the history
* ci: adding sonar to action

* ci: checked if there is a xml output

* ci: removed sonar.testExecutionReportPaths

* docs: added badges to readme

* refactor: added readonly for some attributes
  • Loading branch information
rH4rtinger authored Oct 10, 2024
1 parent 9e28ab1 commit 06f69a3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 30 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/lint.yml

This file was deleted.

60 changes: 55 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: Build Project

on:
push:
branches: ["main"]
pull_request:

permissions:
pull-requests: read # allows SonarCloud to decorate PRs with analysis results

jobs:
build:
strategy:
Expand All @@ -16,16 +21,61 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Check Node.js version
run: node -v

- name: Check npm versions
run: npm -v

- name: Cache node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ matrix.os }}-node-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
node_modules-${{ matrix.os }}-node-${{ matrix.node-version }}
- name: Run clean install
run: npm ci

- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
if: runner.os != 'Linux'

sonar:
name: Run eslint and sonar scanning
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x

- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-ubuntu-latest-node-22.x-${{ hashFiles('package-lock.json') }}
restore-keys: |
node_modules-ubuntu-latest-node-22.x
- name: Run ESLint
run: npm run lint -- --format json --output-file eslint-results.json || true

- name: Install Mocha reporters
run: npm install -d mocha-multi-reporters mocha-junit-reporter mocha-sonarqube-reporter
- name: create mocha config
run: |
echo '{
"reporterEnabled": "spec, mocha-junit-reporter, mocha-sonarqube-reporter"
}' > config.json
- name: Run tests with coverage
run: xvfb-run -a npm test -- --coverage --coverage-output ./coverage --coverage-reporter lcovonly --reporter mocha-multi-reporters --reporter-options configFile=config.json

- name: Analyze with SonarCloud
uses: SonarSource/sonarcloud-github-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: -Dsonar.projectKey=aditosoftware_vscode-logging
-Dsonar.organization=aditosoftware
-Dsonar.eslint.reportPaths=eslint-results.json
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
2 changes: 1 addition & 1 deletion .vscode-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig({
files: "out/test/**/*.test.js",
version: "insiders",
mocha: {
retries: 3,
retries: 5,
parallel: false,
},
});
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# vscode-logging

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aditosoftware_vscode-logging&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=aditosoftware_vscode-logging)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=aditosoftware_vscode-logging&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=aditosoftware_vscode-logging)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=aditosoftware_vscode-logging&metric=coverage)](https://sonarcloud.io/summary/new_code?id=aditosoftware_vscode-logging)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=aditosoftware_vscode-logging&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=aditosoftware_vscode-logging)

This is used to add a simple and easy to use logging to any VS Code extension.

The key idea is that you do not need to call `vscode.window.showInformationMessage` (or similar methods) and do not need to write any additional logs, because this module will take care of everything.
Expand Down
6 changes: 3 additions & 3 deletions src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class Logger {
* @param outputChannel - the output channel were all the messages should be written to
*/
private constructor(
private logger: winston.Logger,
private outputChannel: vscode.OutputChannel
private readonly logger: winston.Logger,
private readonly outputChannel: vscode.OutputChannel
) {
this.logger = logger;
this.outputChannel = outputChannel;
Expand Down Expand Up @@ -262,7 +262,7 @@ class VSCodeOutputChannelTransport extends TransportStream {
* @param opts - the options for the transport
*/
constructor(
private outputChannel: vscode.OutputChannel,
private readonly outputChannel: vscode.OutputChannel,
opts?: TransportStreamOptions
) {
super(opts);
Expand Down

0 comments on commit 06f69a3

Please sign in to comment.