UNPKG

30.7 kBMarkdownView Raw
1# [@d-cat/tag-cli](https://www.npmjs.com/package/@d-cat/tag-cli)
2
3[![npm](https://img.shields.io/npm/v/@d-cat/tag-cli?color=brightgreen)](https://www.npmjs.com/package/@d-cat/tag-cli) [![node](https://img.shields.io/node/v/@d-cat/tag-cli?color=brightgreen)](<(https://www.npmjs.com/package/@d-cat/tag-cli)>) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![codecov](https://codecov.io/gl/d-cat:templates:ci-cd/tag-cli/branch/master/graph/badge.svg?token=l7O5FqoJsT)](https://codecov.io/gl/d-cat:templates:ci-cd/tag-cli)
4
5> [@d-cat/tag-cli](https://www.npmjs.com/package/@d-cat/tag-cli) is a [VZ](https://vodafoneziggo.com) CLI package that should be used to configure containers and tags when using [@d-cat/tag-manager](https://www.npmjs.com/package/@d-cat/tag-manager).
6
7- [Install](#install)
8- [Usage](#usage)
9 * [Tag Manager commands](#tag-manager-commands)
10 + [`create-tag-manager`](#create-tag-manager)
11 - [What's included](#what-s-included)
12 - [Update depedencies](#update-depedencies)
13 - [Examples](#examples)
14 - [GitLab configuration](#gitlab-configuration)
15 * [CI/CD variables to create in GitLab](#cicd-variables-to-create-in-gitlab)
16 + [`bundle-tag-manager`](#bundle-tag-manager)
17 - [Example](#example)
18 - [Test the bundle](#test-the-bundle)
19 + [`deploy-test-instance`](#deploy-test-instance)
20 - [Examples](#examples-1)
21 + [`deploy-tag-manager`](#deploy-tag-manager)
22 - [Examples](#examples-2)
23 * [Tag Template Commands](#tag-template-commands)
24 + [`deploy-tag-template`](#deploy-tag-template)
25 - [Examples](#examples-3)
26 + [`update-dependents`](#update-dependents)
27 - [Example](#example-1)
28 * [Tag commands](#tag-commands)
29 + [`create-new-tag`](#create-new-tag)
30 - [What's included](#what-s-included-1)
31 - [Dependencies](#dependencies)
32 - [Examples](#examples-4)
33 - [Configuring a tag](#configuring-a-tag)
34 * [Pipeline settings](#pipeline-settings)
35 * [Tag Manager settings](#tag-manager-settings)
36 + [`ITrigger`](#itrigger)
37 - [GitLab configuration](#gitlab-configuration-1)
38 * [CI/CD variables to create in GitLab](#cicd-variables-to-create-in-gitlab-1)
39 * [Troubleshooting](#troubleshooting)
40 + [`test-tag`](#test-tag)
41 - [Examples](#examples-5)
42 + [`lint-tag`](#lint-tag)
43 - [Examples](#examples-6)
44 + [`type-tag`](#type-tag)
45 - [Examples](#examples-7)
46 + [`publish-tag`](#publish-tag)
47 - [Examples](#examples-8)
48 * [Troubleshooting](#troubleshooting-1)
49
50
51## Install
52
53```bash
54npm i -D @d-cat/tag-cli
55```
56
57# Usage
58@d-cat/tag-cli is a toolkit to deploy and develop a Tag Manager with Tags using GitLab and Google Cloud Platform.
59___
60
61## Tag Manager commands
62---
63A D-CAT Tag Manager is a collective name for all layers that work together to generate and deploy a working JavaScript bundle of multiple GitLab repositories of a single GitLab Group in a defined Google Cloud Storage Bucket. To effectuate this, we depend on the following:
64
65* [@d-cat/tag-manager](https://www.npmjs.com/package/@d-cat/tag-manager);
66* [@d-cat/tag-cli](https://www.npmjs.com/package/@d-cat/tag-cli);
67* [@d-cat/ddm-core](https://www.npmjs.com/package/@d-cat/ddm-core)
68* [GitLab Group](https://docs.gitlab.com/ee/user/group/);
69* [GitLab Group API](https://docs.gitlab.com/ee/api/groups.html);
70* GitLab Tag Manager Repository in a GitLab Group;
71* More than 0 GitLab Tag Repositories (generated through @d-cat/tag-cli) in a GitLab Group;
72
73![bundle-tag-manager](https://www.plantuml.com/plantuml/png/PP4nRuD038Nt-nLFx205MBf46IfbQQTaYpeud8Ee21Tn9b9LyTzxLYyj5zY-Ppy_czjveL6cQsykhhSy8ZkuAsFVoHkTiH_TTClmRH2QkWir0g6sJh5AiKnnOsRpDpkEVULRxxuUqyd7ECs9dKVsSkY4DokbN2dLIgdD38F_s2ErUAU1MXxrc5DW_w5xDRsRhCRY97Pu2LyXlnLBGcVoZCms93aFzzpoNTruf0M7uiBx6Rp0h7wz74MnHGmBN3vnzSJrakEIAgMxBG5vlatILzNuPysE1niU-GS0)
74
75---
76
77### `create-tag-manager`
78The `create-tag-manager` creates a Tag Manager boilerplate designed to use with @d-cat/tag-cli within GitLab CI/CD. Please make sure you update the e2e and unit tests to suite your needs and match the TMS you want to deploy.
79
80```bash
81Options:
82 --version Show version number [boolean]
83 --help Show help [boolean]
84```
85
86#### What's included
87The Tag Manager boilerplate contains everything to:
88* unit test the build version of the tag manager
89* e2e test the build version of the tag manager in chrome headless browser
90* deploy test/prod containers in a GCP bucket
91* deploy testable open websites with the TMS running on it for functional testing
92* dockerized TMS to run the TMS locally in isolation
93* dockerized TMS that registers images in GitLab private registery
94* stable pipeline file with artifacts enabled both on success as failure
95* babel/ts for browser compatibility
96
97Some parts of the generated boilerplate can look weird as the pipeline will interpolate varialbes/files/libs and build the full version when running `npx tag-cli bundle-tag-manager`.
98
99> The roadmap is to replace interpolated files with a configuration (json/yml) file to make it more intuitive.
100
101#### Update depedencies
102By default dependencies are fixed in the package-lock.json and package.json files. Updating a package manually will break the pipeline as it runs `npm ci`, thus you have to update both package.json as package-lock.json:
103
104```bash
105npm i yourpackage@1.0.0
106```
107
108#### Examples
109Make sure docker is installed and you've updated your [.env](https://docs.docker.com/compose/environment-variables/) file.
110
111```bash
112# create a new tag folder
113mkdir myTag
114
115cd myTag
116
117# creating a tag manager boilerplate
118npx tag-cli create-tag-manager
119
120# running a tag manager locally in isolation on localhost:8080
121docker build -t ${img_name} .
122docker run --name ${container_name} --rm -p 8080:8080 -ti ${img_name}:latest
123
124# running a tag manager locally in isolation with docker-compose
125docker-compose build bundle
126docker-compose up bundle
127
128# running the full tms pipeline (except deployment in gcp/test sites) locally in isolation
129docker-compose build deploy
130docker-compose up deploy
131```
132
133#### GitLab configuration
134Make sure you did all necessary steps to [start with GitLab](https://docs.gitlab.com/ee/gitlab-basics/).
135
136- Create a new GitLab (sub)group with name as Container ID: (i.e. 9999);
137- Create a new project, called Tag Manager;
138- Create CI/CD variables.
139
140##### CI/CD variables to create in GitLab
141
142Before you run the pipeline, make sure you [create the necessary CI/CD variables](https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables) in the GitLab TMS Group.
143
144| CI/CD variable | Type | Description |
145| ----------------------- | :------: | :--------------------------------------------------------------------------------------------------------- |
146| `PERSONAL_ACCESS_TOKEN` | variable | Your personal access token, that has owner rights of the tags group. |
147| `CONTAINER_ID` | variable | Group ID that should be queried for tags. |
148| `GCLOUD_SERVICE_KEY` | file | Your [authentication file](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud. |
149| `SSH_KEY` | file | Your SSH key to clone and push repo's of GitLab. |
150| `GIT_USER_EMAIL` | variable | Your git email: `git config user.email`. |
151| `GIT_USER_NAME` | variable | Your git user name: `git config user.name`. |
152
153---
154
155### `bundle-tag-manager`
156The `bundle-tag-manager` command bundles all tag `artifacts` to eventually transpile and deploy a Tag Manager.
157
158```bash
159Options:
160 --version Show version number [boolean]
161 --help Show help [boolean]
162 --access-token, --token The GitLab personal accesstoken with owner rights.
163 --group-id, --id The GitLab Group ID that should be analyzed.
164 --dir-name, --dir The unique dir name where to store the temporary artifacts.
165 --branch-name, --branch The current branch.
166 --job-token, --j Unique token linked to a pipeline built. Previously this was a job token but due to security issues we recommend using the $CI_PIPELINE_ID.
167 --environment --e TMS environment, should be either `development` or `production`.
168```
169
170#### Example
171Note that all flags are either mandatory or are set as a node environment variable.
172
173```bash
174# the environment variable should be used to trigger
175# the tag managers pipeline from another pipeline or API
176# more at: https://docs.gitlab.com/ee/ci/triggers/#making-use-of-trigger-variables
177
178# gitlab variables to set as env variables
179ACCESS_TOKEN=$MY_PERSONAL_ACCESS_TOKEN
180GROUP_ID=$GITLAB_GROUP_ID
181
182# build a dev bundle
183# variables used are built-in gitlab env variables
184# note that we use ci_pipeline_id as job_token
185# this token is only used for e2e testing
186npx tag-cli bundle-tag-manager --dir-name lib --branch-name $CI_COMMIT_REF_NAME --job-token $CI_PIPELINE_ID --environment $ENV_VAR_FROM_ANOTHER_PIPELINE
187```
188
189#### Test the bundle
190Instead of running the pipeline from a shared runner in GitLab, you could also go for 2 other options to verify if the built is correct.
191
192* [install a GitLab runner](https://docs.gitlab.com/runner/install/) locally and execute the `bundle` job from a Tag Manager project
193* use Docker within a Tag Manager project:
194
195```bash
196docker build -t $MY_TMS_IMG .
197
198# serve the container on localhost:8080
199docker run --name $MY_CONTAINER_NAME --rm -p 8080:8080 -ti $MY_TMS_IMG:latest
200
201# using docker-compose to only build the build job
202docker-compose build build
203
204# serve the container on localhost:8080
205docker-compose up build
206```
207---
208
209### `deploy-test-instance`
210The `deploy-test-instance` command deploys a build version of the Tag Manager on a private or public website at `https://instances.gitlab.io/[tagmanager_id]/[branchName]`. It can take up to 10 minutes before your test instance is deployed, starting from your push.
211
212Note that his commands looks up the `tdn` folder in the root directory of the repo and searches for the build file of the Tag Manager, typically something like `tdn9999.js`. The corresponding deploy url would be `https://instances.gitlab.io/9999`. The command is meant to run it right after a bundle stage.
213
214> Note that you need access to the instances.gitlab.io group before you can publish to it.
215
216```bash
217Options:
218 --version Show version number [boolean]
219 --help Show help [boolean]
220 --access-token, --token The GitLab personal accesstoken with owner rights.
221 --group-id, --id The GitLab Group ID that should be analyzed
222 --branch-name, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
223 --job-token, --j The GitLab's built-in job token: $CI_JOB_TOKEN. This token is generated for each job.
224```
225
226#### Examples
227```bash
228# Personal access token that's needed to authenticate
229ACCESS_TOKEN=$PERSONAL_ACCESS_TOKEN
230
231# Job Token generated by GitLab so we can see in the
232# TMS interface that we triggered the pipeline of the instances group
233JOB_TOKEN=$CI_JOB_TOKEN
234
235# The Group ID in which the TMS project is placed
236GROUP_ID=$TMS_GROUP_ID
237
238npx tag-cli deploy-test-instance --branch-name $CI_COMMIT_REF_NAME
239```
240---
241
242### `deploy-tag-manager`
243The deploy tag manager commands deploys the build tag manager to a Google Cloud Bucket and optionally sends a success email to a list of receivers.
244
245```bash
246Options:
247 --version Show version number [boolean]
248 --help Show help [boolean]
249 --bucket-name, -b Name of the Google Cloud Bucket.
250 --key-file-name, -k Google Cloud authentication JSON key.
251 --group-name, -i The namespace of the GitLab Group, equal to: $CI_PROJECT_NAMESPACE.
252 --branch-name, -n The current branch name, equal to: $CI_COMMIT_REF_NAME.
253 --node-email, -gm Gmail email address, that can function as transporter. More info at: https://nodemailer.com/usage/using-gmail/.
254 --node-pass, -pass Password of the gmail account that functions as transporter.
255 --receivers, -list String array of receivers.
256 --is-empty -e Boolean that indicates if an empty container should be deployed. Defaults to false.
257```
258
259#### Examples
260Note that all flags are either mandatory or are set as an environment variable.
261
262```bash
263# The bucket name of the Google Cloud Bucket
264BUCKET_NAME=$MY_GCP_BUCKET_NAME
265
266# The Key file is your GCP IAM json.
267# make sure it has write rights to the
268# correct bucket only
269KEY_FILE=$MY_KEY_FILE
270
271# The namespace of the gitlab group,
272# we use this to determine wether the TMS id
273# equals the namespace to prevent unexpected overrides
274# of a production container
275# so a GitLab Group called 9999
276# must contain a TMS repo with tdn9999.ts entrypoint.
277GROUP_NAME=$CI_PROJECT_NAMESPACE
278
279# GitLab branch var
280BRANCH_NAME=$CI_COMMIT_REF_NAME
281
282# gmail where we send the mail from
283NODE_EMAIL=$EMAIL_ADDRESS_OF_SENDER
284
285# gmail pass
286NODE_PASS=$EMAIL_PASS
287
288# string with spaces of receiver mails
289RECEIVERS=foo.bar@gmail.com
290
291# You can deploy both an empty TMS (for initial release)
292# or a non-empty.
293
294# deploy empty TMS
295npx tag-cli deploy-tag-manager --is-empty
296
297# deploy non-empty (default)
298npx tag-cli deploy-tag-manager --no-is-empty
299```
300___
301
302## Tag Template Commands
303---
304
305A Tag Template functions as the backbone of a tag. It's a NPM package. It contains critical logic of handling tags logic and returns a class with a set of methods that we can use, inherit and override. Typically a Tag Template contains the following:
306
307* it accepts an initializer object;
308* it notifies the dataLayer that a Tag Template has been initialized;
309* it's a class;
310* it returns a render method;
311* it's an NPM package, starting with: @d-cat/tag-template-;
312* it publishes according NPM semver.
313
314![tag-or-tag-template](https://unpkg.com/@d-cat/tag-cli/assets/tag-or-tag-template.png)
315
316---
317
318### `deploy-tag-template`
319The `deploy-tag-template` command deploys a tag template on a NPM registery of choice. The package version is incremented based on the commits done through i.e. [commitizen](https://www.npmjs.com/package/commitizen). Standard-version is used to publish either a major, minor or patch according to [NPM's semver](https://docs.npmjs.com/misc/semver). A CHANGELOG.md is added or updatet within the repo. Please note that you should only use version 1.0.0 on a stable release. Using version 0.* will behave differently using NPM's semver.
320
321```bash
322Options:
323 --version Show version number [boolean]
324 --help Show help [boolean]
325 --access-token, --token The GitLab personal accesstoken with owner rights.
326 --branch-name, --branch The current branch.
327 --dist-dir, --d The destination directoy, when publishing a flat package. Default to `lib`.
328 --is-flat-package Deploy package as flat-package (i.e. using lerna).
329 --project-path, --p The relative path to the project's repository in GitLab. This equals GitLab's built-in variable: $CI_PROJECT_PATH.
330 --key, --k SSH Key linked to your personal GitLab account.
331 --user, -u Git username linked to your personal GitLab account.
332 --email, -e Git email linked to your personal GitLab account.
333 --o-auth-token, --oauth NPM Registery authentication file.
334```
335
336#### Examples
337Note that all flags are either mandatory or are set as an environment variable.
338
339```bash
340# Personal access token generated within gitlab
341ACCESS_TOKEN=$MY_PERSONAL_ACCESS_TOKEN
342
343# SSH key is used to increment the version of the npm package
344# based on the commits done, according to commitizen.
345# standard-version is used to update a major, minor or patch and use
346# NPM's semver.
347KEY=$SSH_KEY
348
349# your git user + email for authentication
350GIT_USER=$GIT_USER_VAR
351GIT_EMAIL=$GIT_EMAIL_VAR
352
353# deploy a flat package to a npm registery
354# dist dir is set to dist, thus the build is placed in dist
355# defined in your package.json
356npx tag-cli deploy-tag-template --is-flat-package --dist-dir dist --branch-name $CI_COMMIT_REF_NAME --project-path $CI_PROJECT_PATH
357
358# deploy a standard npm package
359npx tag-cli deploy-tag-template --no-is-flat-package --branch-name $CI_COMMIT_REF_NAME --project-path $CI_PROJECT_PATH
360```
361
362---
363
364### `update-dependents`
365If not using [npm semver](https://docs.npmjs.com/misc/semver), you can use `update-dependents` to keep track of dependencies. The `update-dependents` command updates and triggers the first `1000` [default branches](https://docs.gitlab.com/ee/user/project/repository/branches/#default-branch) of all GitLab projects that either use the current package as dependency or as devDependency, using the [GitLab API](https://docs.gitlab.com/ce/api/projects.html#list-all-projects). Please note when using `npm ci` this will not impact the package-lock.json and thus you have to update that one manually.
366
367```bash
368# flags
369Options:
370 --version Show version number [boolean]
371 --help Show help [boolean]
372 --access-token, --token The GitLab personal accesstoken with owner rights.
373 --dir-name, --dir The dir name.
374 --project-id, --d The current project ID, equal to: $CI_PROJECT_ID.
375 --key, --k SSH Key linked to your personal GitLab account.
376 --user, -u Git username linked to your personal GitLab account.
377 --email, -e Git email linked to your personal GitLab account.
378```
379
380![update-dependents](https://www.plantuml.com/plantuml/png/dT4x3iCW40JGtgT0z3Wo7-WYxX5Hh6pa8X1PoVh-yG7C8hOU7iE8-4FuubdBTC3wXZqB6JUr0ZuGTeMv7WKmgqLEz04jwTnqSjihS9qBV2SFLy7hTbeIIZt5RQRJk34COnd6fSOWIwDXunacj1wdavZd1beQHOPXBCCusj1ev5izmmJQnFpPpbh-)
381
382#### Example
383Note that all flags are either mandatory or are set as an environment variable:
384
385```bash
386ACCESS_TOKEN=myAccesToken
387DIR_NAME=foo
388PROJECT_ID=1210
389SSH_KEY=key
390GIT_EMAIL=myEmail
391```
392
393```bash
394npx tag-cli update-dependents --user myGitName
395```
396___
397
398## Tag commands
399-------------------
400A Tag is used to initialize a [Tag Template](#tag-template-commands) or to handle a Google Tag Manager's data object. A tag should never contain complex logic. Use a tag template instead. A Tag is easy to read and easy to debug. There should be no complexity in a tag. The following is applicable for a Tag:
401
402* it exports a default function without arguments;
403* it initializes a tag template;
404* it contains a `publish-tag` job;
405* it contains no complexity.
406
407### `create-new-tag`
408The `create-new-tag` command creates a new Tag boilerplate designed to use with @d-cat/tag-cli within GitLab CI/CD.
409
410```bash
411Options:
412 --version Show version number [boolean]
413 --help Show help [boolean]
414```
415
416#### What's included
417The Tag boilerplate contains all configurations to:
418* Jest setup
419* tslint setup
420* prettier
421* husky
422* tag config file (`tag-cli.json`)
423* dockerized tag environment to run the tag locally in isolation
424* dockerized TMS that registers images in GitLab private registery
425* stable pipeline file with artifacts enabled both on success and failure
426* standard-version to created changelog + semver in the pipeline
427
428#### Dependencies
429By default dependencies are fixed in the package-lock.json and package.json files. Updating a package manually will break the pipeline as it runs `npm ci`, thus you have to update both package.json as package-lock.json:
430
431```bash
432npm i yourpackage@1.0.0
433```
434
435#### Examples
436Make sure docker is installed and you've updated your [.env](https://docs.docker.com/compose/environment-variables/) file.
437
438```bash
439# creating a tag boilerplate
440npx tag-cli create-new-tag
441
442# running a tag locally in isolation on localhost:1234
443docker build -t ${img_name} .
444docker run --name ${tag_name} --rm -p 1234:1234 ${img_name}:latest
445
446# running a tag locally in isolation with docker-compose
447docker-compose build build
448docker-compose up build
449
450# running the full tag pipeline (except uploading artifacts) locally in isolation
451docker-compose build pipeline
452docker-compose up pipeline
453```
454
455#### Configuring a tag
456The `create-new-tag` command will create a file called `tag-cli.json`. This file contains all configurations. The `tag-cli.json` file includes both `pipeline` as `tag manager` settings.
457
458##### Pipeline settings
459This are settings that indicates how a tag should behave inside a pipeline.
460
461| Prop | Type | Desc |
462| ------------- |:-------------:| :-----|
463| `isPipelineActive` | Boolean | Boolean that indicates if the tags pipeline should run.|
464| `pipelineBranches` | String[] | String array of branches that should trigger the Tag's pipeline. |
465| `isImportInTagManager` | Boolean | Boolean to indicate if the tag should be imported in the tag manager. |
466| `tagManagerBranches` | String[] | String array of tag branches that should be included in a tag manager bundle. |
467| `isActive` | Boolean | Boolean that indicates if the tag is active. |
468| `isTrigger` | Boolean | Boolean that indicates if the tag should trigger the Tag Managers pipeline after a publish. |
469
470##### Tag Manager settings
471This are settings that determine how the tag should behave inside the Tag Manager.
472
473| Prop | Type | Desc |
474| ------------- |:-------------:| :-----|
475| `firingAmount` | Number | Amount a tag should be invoked when all business rules apply. |
476| `priority` | Number | Priority of tag. 1 is highest priority. |
477| `id` | String | UUID. |
478| `urls` | IUrl[] | Object Array that contains 2 props: `url` (RegExp) and `reverse` (boolean). |
479| `triggers` | ITrigger[] | Boolean that indicates if the tag is active. |
480
481###### `ITrigger`
482
483| Options | Type | Required Description |
484| --------- | :-----: | :------ |:---- |
485| `type` | String | true | Type of the trigger, this must be one of the following: `instantly`, `datalayer`, `event`, `domEvent`, `persisted`. Note that when using `instantly`, this means the other triggers automatically are ignored, thus the tag will execute immediately. |
486| `id` | String | true | Uniquely generated ID. Using the CLI this will generate an ID using [uuid/v1](https://www.npmjs.com/package/uuid). |
487| `name` | String | false | Depending on the type, the name key has a different function. |
488| `value` | String | false | Depending on the type, the value key has a different function. |
489| `reverse` | Boolean | false | Reverse the match on either value or name. |
490| `element` | String | false | `window`, `document` both as string or an element ID. |
491
492#### GitLab configuration
493Make sure you did all necessary steps to [start with GitLab](https://docs.gitlab.com/ee/gitlab-basics/).
494
495
496##### CI/CD variables to create in GitLab
497Before you run the pipeline, make sure you [create the necessary CI/CD variables](https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables) in your GitLab Tag project.
498
499| CI/CD variable | Type | Description |
500| ----------------------- | :------: | :----- |
501| `PERSONAL_ACCESS_TOKEN` | variable | Your personal access token, that has owner rights of the tags group. |
502| `TAG_MANAGER_ID` | variable | Gitlab Project ID of the Tag Manager. |
503| `GCLOUD_SERVICE_KEY` | file | Your [authentication file](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud. |
504| `SSH_KEY` | file | Your SSH key to clone and push repo's of GitLab. |
505| `GIT_USER_EMAIL` | variable | Your git email: `git config user.email`. |
506| `GIT_USER_NAME` | variable | Your git user name: `git config user.name`. |
507| `CODECOV_TOKEN` | variable | Your Codecov token to publish code coverage reports. |
508
509##### Troubleshooting
510> If the pipeline isn't running after the initial commit, trigger the pipeline manually.
511
512---
513
514### `test-tag`
515The `test-tag` command runs the test script as defined in your package.json and uploads a codecoverage report to [Codecov](https://codecov.io/).
516
517```bash
518Options:
519 --version Show version number [boolean]
520 --help Show help [boolean]
521 --codecov, -c Your Codecov token to publish code coverage report.
522 --branch-name, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
523```
524
525#### Examples
526Note that all flags are either mandatory or are set as an environment variable.
527
528```bash
529# secret codecov token generated in the codecov interface
530CODE_COV_TOKEN=$MY_CODE_COV_TOKEN
531
532# run tests + upload report to codecov
533npx tag-cli test-tag --branch-name $CI_COMMIT_REF_NAME
534```
535
536---
537
538### `lint-tag`
539The `lint-tag` command runs the [TypeScript linter](https://palantir.github.io/tslint/).
540
541```bash
542Options:
543 --version Show version number [boolean]
544 --help Show help [boolean]
545 --branch-name, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
546```
547
548#### Examples
549
550```bash
551npx tag-cli lint-tag --branch-name $CI_COMMIT_REF_NAME
552```
553
554---
555
556### `type-tag`
557The `type-tag` command runs type checks the tag according TypeScript specs.
558
559```bash
560Options:
561 --version Show version number [boolean]
562 --help Show help [boolean]
563 --branch-name, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
564```
565
566#### Examples
567
568```bash
569npx tag-cli type-tag --branch-name $CI_COMMIT_REF_NAME
570```
571
572---
573
574### `publish-tag`
575The `publish-tag` command publishes tag artifacts in GitLab, increments the tag version and additionally triggers the Tag Managers pipeline to deploy a new version. The artifacts you publised can be fetched using [GitLab's API](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#downloading-the-latest-artifacts). Both incrementing the version as triggering the Tag Managers API are optional. However, triggering the Tag Managers pipeline is configured in the `tag-cli.json`.
576
577```bash
578Options:
579 --version Show version number [boolean]
580 --help Show help [boolean]
581 --job-token, -j The GitLab's built-in job token: $CI_JOB_TOKEN. This token
582 is generated for each job.
583 --access-token, -t GitLab's personal access token with admin rights.
584 --tag-manager-id, -i GitLab's Tag Manager project ID.
585 --key, -k SSH Key linked to your personal GitLab account.
586 --user, -u Git username linked to your personal GitLab account.
587 --email, -e Git email linked to your personal GitLab account.
588 --increment-version Boolean that indicates if standard-version should invoke.
589```
590
591#### Examples
592Note that all flags are either mandatory or are set as an environment variable.
593
594```bash
595# Personal access token generated within gitlab
596ACCESS_TOKEN=$MY_PERSONAL_ACCESS_TOKEN
597
598# SSH key is used to increment the version of the npm package
599# based on the commits done, according to commitizen.
600# standard-version is used to update a major, minor or patch and use
601# NPM's semver.
602KEY=$SSH_KEY
603
604# your git user + email for authentication
605GIT_USER=$GIT_USER_VAR
606GIT_EMAIL=$GIT_EMAIL_VAR
607
608# we need the job token to trigger the tag managers pipeline
609# using the job token will show the tag managers pipeline
610# to be triggered in GitLabs interface, and in the TMS
611# project it shows our tag defined as the triggerer
612JOB_TOKEN=$CI_JOB_TOKEN
613
614# set a gitlab variable where the project id
615# of the tag manager is saved
616TAG_MANAGER_ID=$TAG_MANAGER_PROJECT_ID
617
618# incrementing version
619npx tag-cli publish-tag --increment-version
620
621# do not increment version
622npx tag-cli publish-tag --no-increment-version
623```
624
625---
626## Troubleshooting
627- `Publishing tag TypeError: Cannot read property 'map' of undefined`: make sure your `tag-cli.json` has an string array of both `branchesToImportInTagManager` and `branchesToRunInPipeline`.
628- `Publishing tag This tag didn't triggered the pipeline.`: Make sure the branch that triggered the pipeline equals a branch that is whitelisted in your `tag-cli.json`.
629- `GitLab API: Fetching projects. Unexpected response received from GitLab: [object Object], or the amount of received projects meets the maximum of 1000. Received: undefined` : Retry the pipeline, as the GitLab API didn't returned a correct response. It has probably something to do with a connection lost / timeout.
\No newline at end of file