Skip to content
Snippets Groups Projects
Commit 907ab09c authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'feat/gitlab-lint-report' into 'master'

feat(lint): enforce GitLab integration

See merge request to-be-continuous/node!78
parents 5143a947 44cc3c30
Branches
Tags
No related merge requests found
...@@ -90,7 +90,8 @@ variables: ...@@ -90,7 +90,8 @@ variables:
### `node-lint` job ### `node-lint` job
The Node template features a job `node-lint` that performs Node.js source code **lint**. This job is **disabled by default**. It can be activated by setting `NODE_LINT_ENABLED` The Node template features a `node-lint` job that performs a code analysis with [ESLint](https://eslint.org/).
This job is **disabled by default**. It can be activated by setting `NODE_LINT_ENABLED`.
It is bound to the `build` stage, and uses the following variable: It is bound to the `build` stage, and uses the following variable:
...@@ -99,7 +100,18 @@ It is bound to the `build` stage, and uses the following variable: ...@@ -99,7 +100,18 @@ It is bound to the `build` stage, and uses the following variable:
| `lint-enabled` / `NODE_LINT_ENABLED` | Set to `true` to enable lint analysis | _none_ (disabled) | | `lint-enabled` / `NODE_LINT_ENABLED` | Set to `true` to enable lint analysis | _none_ (disabled) |
| `lint-args` / `NODE_LINT_ARGS` | npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments to execute the lint analysis <br/> yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments to execute the lint analysis <br/> pnpm [run script](https://pnpm.io/cli/run) arguments to execute the lint analysis | `run lint` | | `lint-args` / `NODE_LINT_ARGS` | npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments to execute the lint analysis <br/> yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments to execute the lint analysis <br/> pnpm [run script](https://pnpm.io/cli/run) arguments to execute the lint analysis | `run lint` |
The job generates a lint report that you will find here: `NODE_PROJECT_DIR/reports/node-lint.xslint.json`. In addition to a textual report in the console, this job produces the following reports, kept for one day:
| Report | Format | Usage |
|-------------------------------------------------------|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| `$NODE_PROJECT_DIR/reports/node-lint.gitlab.json` | [GitLab](https://docs.gitlab.com/ee/ci/testing/code_quality.html#eslint) | [GitLab integration](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportscodequality) |
| `$NODE_PROJECT_DIR/reports/node-lint.xslint.json` | JSON ESLint | [SonarQube integration](https://docs.sonarqube.org/latest/analysis/external-issues/) |
| Report | Format | Usage |
| ------------------------------------------------- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$NODE_PROJECT_DIR/reports/npm-audit.native.json` | [JSON](https://docs.npmjs.com/cli/v9/commands/npm-audit#json) | [DefectDojo integration](https://documentation.defectdojo.com/integrations/parsers/#npm-audit)<br/>_This report is generated only if DefectDojo template is detected, if needed, you can force it with `$DEFECTDOJO_NPMAUDIT_REPORTS`_ |
### `node-build` job ### `node-build` job
......
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
{ {
"id": "node-lint", "id": "node-lint",
"name": "node lint", "name": "node lint",
"description": "node lint analysis", "description": "code analysis with [ESLint](https://eslint.org/)",
"enable_with": "NODE_LINT_ENABLED", "enable_with": "NODE_LINT_ENABLED",
"variables": [ "variables": [
{ {
......
...@@ -539,16 +539,6 @@ stages: ...@@ -539,16 +539,6 @@ stages:
fi fi
} }
function sonar_lint_report() {
if [[ "$SONAR_HOST_URL" ]] || [[ "$SONAR_URL" ]]
then
mkdir -p -m 777 reports
# generate eslint report in json for SonarQube
# shellcheck disable=SC2086
$NODE_MANAGER $NODE_LINT_ARGS -- --format=json --output-file=reports/node-lint.xslint.json
fi
}
function configure_publish() { function configure_publish() {
# get package scope+name, and target registry url # get package scope+name, and target registry url
pkg_fullname=$(node -pe "require('./package.json').name") pkg_fullname=$(node -pe "require('./package.json').name")
...@@ -689,16 +679,35 @@ node-lint: ...@@ -689,16 +679,35 @@ node-lint:
extends: .node-base extends: .node-base
stage: build stage: build
script: script:
# generate lint report for sonar - mkdir -p -m 777 reports
- sonar_lint_report || true # maybe generate ESLint report for SonarQube
# display lint result for console - |
- $NODE_MANAGER $NODE_LINT_ARGS if [[ "$SONAR_HOST_URL" ]] || [[ "$SONAR_URL" ]]
then
# generate eslint report for SonarQube
# shellcheck disable=SC2086
log_info "SonarQube detedted: producing ESLint JSON report..."
$NODE_MANAGER $NODE_LINT_ARGS -- --format=json --output-file=reports/node-lint.xslint.json || true
fi
# maybe add eslint-formatter-gitlab
- |
if ! $NODE_MANAGER list | grep eslint-formatter-gitlab > /dev/null
then
log_info "Adding eslint-formatter-gitlab to produce ESLint GitLab report..."
$NODE_MANAGER add eslint-formatter-gitlab
fi
# run ESLint with console output and GitLab report
# shellcheck disable=SC2086
- ESLINT_CODE_QUALITY_REPORT=reports/node-lint.gitlab.json $NODE_MANAGER $NODE_LINT_ARGS -- --format=gitlab
artifacts: artifacts:
when: always # store artifact even if test Failed when: always # store artifact even if test Failed
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
paths:
- $NODE_PROJECT_DIR/reports/node-lint.xslint.json
expire_in: 1 day expire_in: 1 day
paths:
- $NODE_PROJECT_DIR/reports/node-lint.*
reports:
codequality:
- $NODE_PROJECT_DIR/reports/node-lint.gitlab.json
rules: rules:
# exclude if $NODE_LINT_ENABLED unset # exclude if $NODE_LINT_ENABLED unset
- if: '$NODE_LINT_ENABLED != "true"' - if: '$NODE_LINT_ENABLED != "true"'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment