Commit 7825ccae authored by Cédric OLIVIER's avatar Cédric OLIVIER
Browse files

Merge branch 'feat/component' into 'master'

feat: migrate to GitLab CI/CD component

See merge request to-be-continuous/angular!57
parents 2c818dd3 d4e7b324
Loading
Loading
Loading
Loading
+46 −23
Original line number Diff line number Diff line
@@ -4,26 +4,49 @@ This project implements a GitLab CI/CD template to build, test and analyse your

## Usage

In order to include this template in your project, add the following to your `gitlab-ci.yml`:
This template can be used both as a [CI/CD component](https://docs.gitlab.com/ee/ci/components/#use-a-component-in-a-cicd-configuration) 
or using the legacy [`include:project`](https://docs.gitlab.com/ee/ci/yaml/index.html#includeproject) syntax.

### Use as a CI/CD component

Add the following to your `gitlab-ci.yml`:

```yaml
include:
  # 1: include the component
  - component: gitlab.com/to-be-continuous/angular/gitlab-ci-angular@4.7.0
    # 2: set/override component inputs
    inputs:
      cli-image: "registry.hub.docker.com/trion/ng-cli-karma:16.2.9" # ⚠ this is only an example
```

### Use as a CI/CD template (legacy)

Add the following to your `gitlab-ci.yml`:

```yaml
include:
  # 1: include the template
  - project: 'to-be-continuous/angular'
    ref: '4.7.0'
    file: '/templates/gitlab-ci-angular.yml'

variables:
  # 2: set/override template variables
  NG_CLI_IMAGE: "registry.hub.docker.com/trion/ng-cli-karma:16.2.9" # ⚠ this is only an example
```

## Global configuration

The Angular template uses some global configuration used throughout all jobs.

| Name           | Description                                   | Default value                                                             |
| Input / Variable | Description                                   | Default value                                                             |
|----------------|-----------------------------------------------|:--------------------------------------------------------------------------|
| `NG_CLI_IMAGE`        | The Docker image used to run Angular-CLI (ng) <br/>:warning: **set the version required by your project** | `registry.hub.docker.com/trion/ng-cli-karma:latest` |
| `NPM_CONFIG_REGISTRY` | NPM [registry](https://docs.npmjs.com/configuring-your-registry-settings-as-an-npm-enterprise-user)                | _none_ (defaults to `https://registry.npmjs.org`) |
| `NPM_CONFIG_SCOPED_REGISTRIES` | Space separated list of NPM [scoped registries](https://docs.npmjs.com/cli/v8/using-npm/scope#associating-a-scope-with-a-registry) (formatted as `@somescope:https://some.npm.registry/some/repo @anotherscope:https://another.npm.registry/another/repo`) | _none_ |
| `NG_WORKSPACE_DIR`    | Angular workspace directory       | `.` |
| `NG_INSTALL_EXTRA_OPTS`| Extra options to install project dependencies (with [`npm ci`](https://docs.npmjs.com/cli/ci.html/)) | _none_ |
| `cli-image` / `NG_CLI_IMAGE` | The Docker image used to run Angular-CLI (ng) <br/>:warning: **set the version required by your project** | `registry.hub.docker.com/trion/ng-cli-karma:latest` |
| `npm-config-registry` / `NPM_CONFIG_REGISTRY` | NPM [registry](https://docs.npmjs.com/configuring-your-registry-settings-as-an-npm-enterprise-user)                | _none_ (defaults to `https://registry.npmjs.org`) |
| `npm-config-scoped-registries` / `NPM_CONFIG_SCOPED_REGISTRIES` | Space separated list of NPM [scoped registries](https://docs.npmjs.com/cli/v8/using-npm/scope#associating-a-scope-with-a-registry) (formatted as `@somescope:https://some.npm.registry/some/repo @anotherscope:https://another.npm.registry/another/repo`) | _none_ |
| `workspace-dir` / `NG_WORKSPACE_DIR` | Angular workspace directory       | `.` |
| `install-extra-opts` / `NG_INSTALL_EXTRA_OPTS` | Extra options to install project dependencies (with [`npm ci`](https://docs.npmjs.com/cli/ci.html/)) | _none_ |

### Configuring scoped registries

@@ -54,9 +77,9 @@ The Angular template features a job `ng-lint` that performs Angular source code

It is bound to the `build` stage, and uses the following variable:

| Name           | Description                                              | Default value |
| Input / Variable | Description                                              | Default value |
|----------------|----------------------------------------------------------|---------------|
| `NG_LINT_ARGS` | Angular [ng lint](https://angular.io/cli/lint) arguments | `lint`        |
| `lint-args` / `NG_LINT_ARGS` | Angular [ng lint](https://angular.io/cli/lint) arguments | `lint`        |

### `ng-build` job

@@ -67,10 +90,10 @@ for jobs dependency reasons (some jobs such as SONAR analysis have a dependency

Those stage are bound to the `build` stage, and uses the following variable:

| Name            | Description                                                | Default value                                     |
| Input / Variable | Description                                                | Default value                                     |
|-----------------|------------------------------------------------------------|---------------------------------------------------|
| `NG_TEST_ARGS`  | Angular [ng test](https://angular.io/cli/test) arguments   | `test --code-coverage --reporters progress,junit --watch=false --no-progress` |
| `NG_BUILD_ARGS` | Angular [ng build](https://angular.io/cli/build) arguments | `build`                                           |
| `test-args` / `NG_TEST_ARGS` | Angular [ng test](https://angular.io/cli/test) arguments   | `test --code-coverage --reporters progress,junit --watch=false --no-progress` |
| `build-args` / `NG_BUILD_ARGS` | Angular [ng build](https://angular.io/cli/build) arguments | `build`                                           |

The next chapters presents some requirements related to your unit tests (using Karma).

@@ -267,10 +290,10 @@ Additionally, if using **SonarQube**, you may also want to generate [SonarQube g
The Angular template features a job `ng-e2e` that performs **protractor tests**
This stage is bound to the `test` stage and uses the following variables :

| Name                 | Description                                                | Default value                            |
| Input / Variable | Description                                                | Default value                            |
|----------------------|------------------------------------------------------------|------------------------------------------|
| `NG_E2E_ARGS`        | Angular [ng e2e](https://angular.io/cli/e2e) arguments     | `e2e`                                    |
| `NG_E2E_ENABLED`     | set to `true`to enable the e2e tests execution             | *none (disabled by default)*             |
| `e2e-args` / `NG_E2E_ARGS` | Angular [ng e2e](https://angular.io/cli/e2e) arguments     | `e2e`                                    |
| `e2e-enabled` / `NG_E2E_ENABLED` | set to `true`to enable the e2e tests execution             | *none (disabled by default)*             |

Implementation rely on the official [Angular CLI](https://cli.angular.io/) tool (`ng build` and `ng test` commands).

@@ -298,11 +321,11 @@ This job generates a [SBOM](https://cyclonedx.org/) file listing installed packa

It is bound to the `test` stage, and uses the following variables:

| Name                  | Description                            | Default value     |
| Input / Variable | Description                            | Default value     |
| --------------------- | -------------------------------------- | ----------------- |
| `NG_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `NG_SBOM_VERSION` | The version of @cyclonedx/cyclonedx-npm used to emit SBOM | _none_ (uses latest) |
| `NG_SBOM_OPTS` | Options for @cyclonedx/cyclonedx-npm used for SBOM analysis | `--omit dev` |
| `sbom-disabled` / `NG_SBOM_DISABLED` | Set to `true` to disable this job | _none_ |
| `sbom-version` / `NG_SBOM_VERSION` | The version of @cyclonedx/cyclonedx-npm used to emit SBOM | _none_ (uses latest) |
| `sbom-opts` / `NG_SBOM_OPTS` | Options for @cyclonedx/cyclonedx-npm used for SBOM analysis | `--omit dev` |

### `ng-publish` job

@@ -313,11 +336,11 @@ When enabled, it is executed on a Git tag with a semantic version pattern (`v?[0

It uses the following variables:

| Name                       | Description                                                                 | Default value                                                    |
| Input / Variable | Description                                                                 | Default value                                                    |
|----------------------------|-----------------------------------------------------------------------------|------------------------------------------------------------------|
| `NG_PUBLISH_ENABLED`       | Set variable to `true` to enable the publish job                            | _none_ (disabled) |
| `NG_PUBLISH_PROJECTS`      | Space separated list of projects to publish                                 | _none_ (all workspace projects are published) |
| `NG_PUBLISH_ARGS`          | NPM [publish](https://docs.npmjs.com/cli/v6/commands/npm-publish) arguments | _none_ |
| `publish-enabled` / `NG_PUBLISH_ENABLED` | Set variable to `true` to enable the publish job                            | _none_ (disabled) |
| `publish-projects` / `NG_PUBLISH_PROJECTS` | Space separated list of projects to publish                                 | _none_ (all workspace projects are published) |
| `publish-args` / `NG_PUBLISH_ARGS` | NPM [publish](https://docs.npmjs.com/cli/v6/commands/npm-publish) arguments | _none_ |
| `NPM_PUBLISH_REGISTRY`     | npm registry to publish to | uses GitLab project npm packages registry      | _none_ |
| :lock: `NPM_PUBLISH_TOKEN` | NPM publication registry authentication token                               | _none_ |
| :lock: `NPM_PUBLISH_AUTH`  | NPM publication registry basic authentication (base64)                      | _none_ |
+2 −2
Original line number Diff line number Diff line
@@ -27,13 +27,13 @@ if [[ "$curVer" ]]; then
  log_info "Bump version from \\e[33;1m${curVer}\\e[0m to \\e[33;1m${nextVer}\\e[0m (release type: $relType)..."

  # replace in README
  sed -e "s/ref: '$curVer'/ref: '$nextVer'/" README.md > README.md.next
  sed -e "s/ref: *'$curVer'/ref: '$nextVer'/" -e "s/ref: *\"$curVer\”/ref: \”$nextVer\”/" -e "s/component: *\(.*\)@$curVer/component: \1@$nextVer/" README.md > README.md.next
  mv -f README.md.next README.md

  # replace in template and variants
  for tmpl in templates/*.yml
  do
    sed -e "s/\"$curVer\"/\"$nextVer\"/" "$tmpl" > "$tmpl.next"
    sed -e "s/command: *\[\"--service\", \"\(.*\)\", \"$curVer\"\]/command: [\"--service\", \"\1\", \"$nextVer\"]/" "$tmpl" > "$tmpl.next"
    mv -f "$tmpl.next" "$tmpl"
  done
else
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
  "description": "Build, test and analyse your [Angular](https://angular.io/) projects",
  "template_path": "templates/gitlab-ci-angular.yml",
  "kind": "build",
  "prefix": "ng",
  "is_component": true,
  "variables": [
    {
      "name": "NG_CLI_IMAGE",
+4.69 KiB (12.8 KiB)
Loading image diff...
+77 −14
Original line number Diff line number Diff line
@@ -13,6 +13,64 @@
# program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 
# Floor, Boston, MA  02110-1301, USA.
# =========================================================================================
spec:
  inputs:
    cli-image:
      description: The Docker image used to run Angular-CLI (`ng`) - **set the version required by your project**
      default: registry.hub.docker.com/trion/ng-cli-karma:latest
    npm-config-registry:
      description: NPM [registry](https://docs.npmjs.com/configuring-your-registry-settings-as-an-npm-enterprise-user)
      default: ''
    npm-config-scoped-registries:
      description: Space separated list of NPM [scoped registries](https://docs.npmjs.com/cli/v8/using-npm/scope#associating-a-scope-with-a-registry) (formatted as `@somescope:https://some.npm.registry/some/repo @anotherscope:https://another.npm.registry/another/repo`)
      default: ''
    workspace-dir:
      description: Angular workspace directory
      default: .
    install-extra-opts:
      description: Extra options to install project dependencies (with [`npm ci`](https://docs.npmjs.com/cli/ci.html/))
      default: ''
    build-args:
      description: Angular [ng build](https://angular.io/cli/build) arguments
      default: build
    test-args:
      description: Angular [ng test](https://angular.io/cli/test) arguments
      default: test --code-coverage --reporters progress,junit --watch=false --no-progress
    lint-disabled:
      description: Disable Angular lint
      type: boolean
      default: false
    lint-args:
      description: Angular [ng lint](https://angular.io/cli/lint) arguments
      default: lint
    publish-enabled:
      description: Enable Publish
      type: boolean
      default: false
    publish-args:
      description: npm [publish](https://docs.npmjs.com/cli/v6/commands/npm-publish) arguments
      default: ''
    publish-projects:
      description: Space separated list of projects to publish. If no project is specified, all workspace projects are published.
      default: ''
    e2e-enabled:
      description: Enable e2e-test
      type: boolean
      default: false
    e2e-args:
      description: ng [e2e](https://angular.io/cli/e2e) arguments
      default: e2e
    sbom-disabled:
      description: Disable Software Bill of Materials
      type: boolean
      default: false
    sbom-version:
      description: Version of the @cyclonedx/cyclonedx-npm used for SBOM analysis
      default: ''
    sbom-opts:
      description: Options for @cyclonedx/cyclonedx-npm used for SBOM analysis
      default: --omit dev
---
# default workflow rules: Merge Request pipelines
workflow:
  rules:
@@ -56,32 +114,26 @@ workflow:

variables:
  # variabilized tracking image
  TBC_TRACKING_IMAGE: "registry.gitlab.com/to-be-continuous/tools/tracking:master"
  TBC_TRACKING_IMAGE: registry.gitlab.com/to-be-continuous/tools/tracking:master

  # Default ng workspace
  NG_WORKSPACE_DIR: .
  NG_WORKSPACE_DIR: $[[ inputs.workspace-dir ]]

  # Default Docker image for ANGULAR CLI (can be overridden)
  NG_CLI_IMAGE: "registry.hub.docker.com/trion/ng-cli-karma:latest"
  NG_CLI_IMAGE: $[[ inputs.cli-image ]]

  # Angular lint
  NG_LINT_ARGS: "lint"
  NG_LINT_ARGS: $[[ inputs.lint-args ]]

  # Angular test
  NG_TEST_ARGS: >-
    test
    --code-coverage
    --reporters progress,junit
    --watch=false 
    --no-progress
  NG_TEST_ARGS: $[[ inputs.test-args ]]

  NG_E2E_ARGS: >-
    e2e
  NG_E2E_ARGS: $[[ inputs.e2e-args ]]

  # Angular Build
  NG_BUILD_ARGS: "build"
  NG_BUILD_ARGS: $[[ inputs.build-args ]]

  NG_SBOM_OPTS: "--omit dev"
  NG_SBOM_OPTS: $[[ inputs.sbom-opts ]]

  # default production ref name (pattern)
  PROD_REF: '/^(master|main)$/'
@@ -90,6 +142,17 @@ variables:
  # default release tag name (pattern)
  RELEASE_REF: '/^v?[0-9]+\.[0-9]+\.[0-9]+$/'

  NPM_CONFIG_REGISTRY: $[[ inputs.npm-config-registry ]]
  NPM_CONFIG_SCOPED_REGISTRIES: $[[ inputs.npm-config-scoped-registries ]]
  NG_INSTALL_EXTRA_OPTS: $[[ inputs.install-extra-opts ]]
  NG_LINT_DISABLED: $[[ inputs.lint-disabled ]]
  NG_PUBLISH_ENABLED: $[[ inputs.publish-enabled ]]
  NG_PUBLISH_ARGS: $[[ inputs.publish-args ]]
  NG_PUBLISH_PROJECTS: $[[ inputs.publish-projects ]]
  NG_E2E_ENABLED: $[[ inputs.e2e-enabled ]]
  NG_SBOM_DISABLED: $[[ inputs.sbom-disabled ]]
  NG_SBOM_VERSION: $[[ inputs.sbom-version ]]
  
  # ==================================================
  # Variables for publication
  # ==================================================