Commit 0e44c5c2 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'scopes-registries-auth' into 'master'

Add support for NPM scopes registries authentication

See merge request to-be-continuous/angular!40
parents 9fa7a539 7e4ca313
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -26,6 +26,23 @@ The Angular template uses some global configuration used throughout all jobs.
| `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_ |

### Configuring scoped registries

You may configure [scoped registries](https://docs.npmjs.com/cli/v8/using-npm/scope#associating-a-scope-with-a-registry) with the `$NPM_CONFIG_SCOPED_REGISTRIES` variable.
The value is expected as a (whitespace-separated) list of `@registry_scope:registry_url`.

The Angular template also supports authentication tokens for each, simply by defining `NPM_REGISTRY_<SCOPE>_AUTH` (as project or group secret variables).

:warning: The `<SCOPE>` part is the `registry_scope` transformed in [SCREAMING_SNAKE_CASE](https://en.wikipedia.org/wiki/Snake_case) (uppercase words separated by underscores).

Example: declare the GitLab chart repository from another GitLab project

```yml
variables:
  NPM_CONFIG_SCOPED_REGISTRIES: "@public-repo:https://public.npm.registry/some/repo @priv-repo:https://private.npm.registry/another/repo"
  # NPM_REGISTRY_PRIV_REPO_AUTH set as a project secret variables
```

## Jobs

### `ng-lint` job
+10 −1
Original line number Diff line number Diff line
@@ -445,7 +445,16 @@ stages:
      then
        for scoped_registry in $NPM_CONFIG_SCOPED_REGISTRIES
        do
          npm config set "${scoped_registry%%:*}":registry "${scoped_registry#*:}";
          reg_scope=${scoped_registry%%:*}
          reg_url=${scoped_registry#*:}
          npm config set "${reg_scope}:registry" "${reg_url}"
          reg_scope_ssc=$(echo "$reg_scope" | tr '[:lower:]' '[:upper:]' | tr -d '@' | tr '[:punct:]' '_')
          reg_auth=$(eval echo "\$NPM_REGISTRY_${reg_scope_ssc}_AUTH")
          if [[ "${reg_auth}" ]]
          then
            reg_url_no_proto=${reg_url#*:}
            npm config set "${reg_url_no_proto}:_authToken" "${reg_auth}"
          fi
        done
      fi
    - configure_gitlab_instance_level_npm_registry_auth