Commit 7c47553c authored by Mathis Goichon's avatar Mathis Goichon
Browse files

docs: update ReadMe to fit with template generalization

parent d1ab6f83
Loading
Loading
Loading
Loading
+37 −35
Original line number Diff line number Diff line
# GitLab CI template for Node.js

This project implements a generic GitLab CI template for projects based on [Node.js](https://nodejs.org/)].
This project implements a generic GitLab CI template for projects based on [Node.js](https://nodejs.org/).

More precisely, it can be used by all frameworks based on **npm** or **yarn** package managers

It provides several features, usable in different modes (by configuration).

@@ -20,9 +22,10 @@ include:
The Node.js template uses some global configuration used throughout all jobs.

| Name               | description                                                                                      | default value     |
|------------------------|-------------------------------------------------------------------------------------------------------|-------------------|
|--------------------|--------------------------------------------------------------------------------------------------|-------------------|
| `NODE_IMAGE`       | The Docker image used to run Node.js <br/>:warning: **set the version required by your project** | `node:lts-alpine` |
| `NPM_CONFIG_REGISTRY`  | NPM [registry](https://docs.npmjs.com/configuring-your-registry-settings-as-an-npm-enterprise-user)   | _none_            |
| `NODE_MANAGER`     | The package manager used by your project (npm or yarn)<br/>**If undefined, automatic detection** | _none_            |
| `CONFIG_REGISTRY`  | npm [registry](https://docs.npmjs.com/cli/v8/using-npm/registry)                                 | _none_            |
| `NODE_PROJECT_DIR` | Node project root directory                                                                      | `.`               |
| `NODE_SOURCE_DIR`  | Sources directory                                                                                | `src`             |

@@ -35,9 +38,9 @@ The Node template features a job `node-lint` that performs Node.js source code *
It is bound to the `test` stage, and uses the following variable:

| Name                     | description                                                                                                                                                                                                                | default value                 |
|--------------------------|------------------------------------------------------------------------------------------------------|-------------------------------|
|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|
| `NODE_LINT_ENABLED`      | Set to `true` to enable lint analysis                                                                                                                                                                                      | _none_ (disabled)             |
| `NODE_LINT_ARGS`         | NPM [run-script](https://docs.npmjs.com/cli/run-script.html) arguments to execute the lint analysis  | `run lint`                    |
| `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 | `run lint`                    |
| `NODE_LINT_REPORT_PATH`  | Variable to define lint analysis report path                                                                                                                                                                               | `reports/eslint-report.json`  |

### `node-build` job
@@ -50,15 +53,13 @@ for jobs dependency reasons (some jobs such as SONAR analysis have a dependency
This job is bound to the `build` stage, and uses the following variables:

| Name                          | description                                                                                                                                                       | default value                   |
|-------------------------------|---------------------------------------------------------------|---------------------------------|
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|
| `NODE_BUILD_DISABLED`         | Set to `true` to disable build                                                                                                                                    | _none_ (enabled)                |
| `NODE_BUILD_DIR`              | Variable to define build directory                                                                                                                                | `dist`                          |
| `NODE_BUILD_ARGS`             | NPM [build](https://docs.npmjs.com/cli/build.html) arguments  | `run build --prod`              |
| `NODE_TEST_ARGS`              | NPM [test](https://docs.npmjs.com/cli/test.html) arguments    | `test -- --coverage --bail`     |
| `NODE_BUILD_ARGS`             | npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments <br/> yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments  | `run build --prod`              |
| `NODE_TEST_ARGS`              | npm [test](https://docs.npmjs.com/cli/v8/commands/npm-test) arguments <br/> yarn [test](https://classic.yarnpkg.com/en/docs/cli/test) arguments                   | `test -- --coverage --bail`     |
| `NODE_UNIT_TEST_REPORT_PATH`  | The unit test report file path (JUnit format)                                                                                                                     | `reports/unit_test_report.xml`  |

Implementation rely on the official [NPM CLI](https://docs.npmjs.com/cli-documentation/cli) tool (`npm build` and `npm test` commands).

#### Unit testing with Jest

If you're using [Jest](https://jestjs.io/) as unit testing framework, you'll have to make the following configuration in
@@ -234,26 +235,27 @@ More info:

### `node-audit` job

The Node template features a job `node-audit` that performs [npm audit](https://docs.npmjs.com/cli/audit) to find vulnerabilities (security).
The Node template features a job `node-audit` that performs an audit ([npm audit](https://docs.npmjs.com/cli/v8/commands/npm-audit) or [yarn audit](https://classic.yarnpkg.com/en/docs/cli/audit)) to find vulnerabilities (security).

It is bound to the `test` stage. By default `npm audit` provide a long json report. 
It is bound to the `test` stage.


| Name                   | description                                                                                                                                           | default value                    |
|------------------------|----------------------------------------------------------------------------------------------|------------------------------------------|
|------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
| `NODE_AUDIT_DISABLED`  | Set to `true` to disable npm audit                                                                                                                    | _none_ (enabled)                 |
| `NODE_AUDIT_ARGS`      | NPM [audit](https://docs.npmjs.com/cli/audit) arguments                                      | `--audit-level=low`                      |
| `NODE_AUDIT_JSON_PATH` | NPM [audit](https://docs.npmjs.com/cli/audit) JSON report path                               | `reports/npm-audit-report.json`          |
| `NODE_AUDIT_ARGS`      | npm [audit](https://docs.npmjs.com/cli/v8/commands/npm-audit) arguments <br/> yarn [audit](https://classic.yarnpkg.com/en/docs/cli/audit) arguments   | `--audit-level=low`              |
| `NODE_AUDIT_JSON_PATH` | JSON audit report path                                                                                                                                | `reports/npm-audit-report.json`  |

### `node-npm-outdated` job

The Node template features a job `node-outdated` that performs [npm outdated](https://docs.npmjs.com/cli/outdated) to find dependencies that might be updated.
The Node template features a job `node-outdated` that performs outdated analysis ([npm outdated](https://docs.npmjs.com/cli/v8/commands/npm-outdated) or [yarn outdated](https://classic.yarnpkg.com/lang/en/docs/cli/outdated/)) to find dependencies that might be updated.

It is bound to the `test` stage. By default `npm outdated` provide a long json report. 
It is bound to the `test` stage.

| Name                      | description                                                                                                                                                           | default value                      |
|---------------------------|--------------------------------------------------------------------------------------------------|---------------------------------------------|
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
| `NODE_OUTDATED_DISABLED`  | Set to `true` to disable npm outdated                                                                                                                                 | _none_ (enabled)                   |
| `NODE_OUTDATED_ARGS`      | NPM [outdated](https://docs.npmjs.com/cli/outdated) arguments                                    | `--long`                                    |
| `NODE_OUTDATED_JSON_PATH` | NPM [outdated](https://docs.npmjs.com/cli/outdated) JSON report path                             | `reports/npm-outdated-report.json`          |
| `NODE_OUTDATED_SILENT`    | Set to `false` to enable job fails when dependencies are not up to date                                                                                               | `true`                             |
| `NODE_OUTDATED_ARGS`      | npm [outdated](https://docs.npmjs.com/cli/v8/commands/npm-outdated) arguments <br/> yarn [outdated](https://classic.yarnpkg.com/lang/en/docs/cli/outdated/) arguments | `--long`                           |
| `NODE_OUTDATED_JSON_PATH` | JSON outdated report path                                                                                                                                             | `reports/npm-outdated-report.json` |