UNPKG

19.5 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
8
9```bash
10npm i -D @d-cat/tag-cli
11```
12
13## Usage
14Set of commands used to create, test or deploy tags/ tag managers / tag-templates.
15
16### bundle-tag-manager
17The `bundle-tag-manager` command bundles tag `artifacts` to eventually transpile and deploy a Tag Manager.
18
19![bundle-tag-manager](https://www.plantuml.com/plantuml/png/PP4nRuD038Nt-nLFx205MBf46IfbQQTaYpeud8Ee21Tn9b9LyTzxLYyj5zY-Ppy_czjveL6cQsykhhSy8ZkuAsFVoHkTiH_TTClmRH2QkWir0g6sJh5AiKnnOsRpDpkEVULRxxuUqyd7ECs9dKVsSkY4DokbN2dLIgdD38F_s2ErUAU1MXxrc5DW_w5xDRsRhCRY97Pu2LyXlnLBGcVoZCms93aFzzpoNTruf0M7uiBx6Rp0h7wz74MnHGmBN3vnzSJrakEIAgMxBG5vlatILzNuPysE1niU-GS0)
20
21```bash
22Options:
23 --version Show version number [boolean]
24 --help Show help [boolean]
25 --accessToken, --token The GitLab personal accesstoken with owner rights.
26 --groupId, --id The GitLab Group ID that should be analyzed.
27 --dirName, --dir The unique dir name where to store the artifacts.
28 --branchName, --branch The current branch.
29 --jobToken, --j GitLabs built-in job token: $CI_JOB_TOKEN. This token is generated for each job.
30 --environment --e Environment string to indicate to what GCP bucket we deploy.
31```
32
33#### Example
34
35```bash
36npx tag-cli bundle-tag-manager
37```
38
39### create-tag-manager
40The `create-tag-manager` creates a Tag Manager boilerplate.
41
42```bash
43Options:
44 --version Show version number [boolean]
45 --help Show help [boolean]
46```
47
48#### Example
49
50```bash
51npx tag-cli create-tag-manager
52```
53#### Dockerizing TMS
54Each TMS build is dockerized in the pipeline and publisht to GitLab's private registery: registry.gitlab.com/[GITLAB_GROUP]/[TAG_REPO].
55
56##### Test TMS build locally
57Create a `.env` file with the following vars:
58
59```bash
60ENVIRONMENT=development # or production
61GROUP_ID=[GITLAB_GROUP_ID]
62DIR_NAME=tdn2010
63BRANCH_NAME=master # or development
64JOB_TOKEN=12345 # random string
65ACCESS_TOKEN=[YOUR_ACCESS_TOKEN]
66```
67
68```bash
69docker-compose up
70```
71
72### create-new-tag
73Command to create a tag boilerplate.
74
75```bash
76Options:
77 --version Show version number [boolean]
78 --help Show help [boolean]
79```
80
81```bash
82npx tag-cli create-new-tag
83```
84
85#### Dockerizing tags
86Each tag is dockerized in the pipeline and publisht to GitLab's private registery: `registry.gitlab.com/[GITLAB_GROUP]/[TAG_REPO]`.
87
88#### Test local tag
89There are 2 options to test your tag locally:
90* `npm run dev`: this will start a dev environment pointing to localhost:1234
91* `docker-compose up`: this will start a dev environment pointing to localhost:1234
92
93### update-dependents
94If not using npm 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 all arguments are mandatory, however you could be using environment variables.
95
96```bash
97# flags
98Options:
99 --version Show version number [boolean]
100 --help Show help [boolean]
101 --accessToken, --token The GitLab personal accesstoken with owner rights.
102 --projectId, --d The current project ID, equal to: $CI_PROJECT_ID.
103 --projectPath, --p The relative path to the project's repository in GitLab. This equals GitLab's built-in variable: $CI_PROJECT_PATH.
104 --key, --k SSH Key linked to your personal GitLab account.
105 --user, -u Git username linked to your personal GitLab account.
106 --email, -e Git email linked to your personal GitLab account.
107 --jobToken, --j GitLabs built-in job token: $CI_JOB_TOKEN. This token is generated for each job.
108
109```
110
111![update-dependents](https://www.plantuml.com/plantuml/png/dT4x3iCW40JGtgT0z3Wo7-WYxX5Hh6pa8X1PoVh-yG7C8hOU7iE8-4FuubdBTC3wXZqB6JUr0ZuGTeMv7WKmgqLEz04jwTnqSjihS9qBV2SFLy7hTbeIIZt5RQRJk34COnd6fSOWIwDXunacj1wdavZd1beQHOPXBCCusj1ev5izmmJQnFpPpbh-)
112
113```bash
114ACCESS_TOKEN=myAccesToken
115DIR_NAME=foo
116PROJECT_ID=1210
117SSH_KEY=key
118GIT_EMAIL=myEmail
119
120npx tag-cli update-dependents --user myGitName
121```
122
123#### Troubleshooting
124
125`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.
126
127### deploy-tag-template
128The `deploy-tag-template` command deploys a given tag template at NPM, including incrementing versioning based on your commit through [commitizen](http://commitizen.github.io/cz-cli/) / [commitlint](https://commitlint.js.org/#/).
129
130```bash
131Options:
132 --version Show version number [boolean]
133 --help Show help [boolean]
134 --accessToken, --token The GitLab personal accesstoken with owner rights.
135 --branchName, --branch The current branch.
136 --projectPath, --p The relative path to the project's repository in GitLab. This equals GitLab's built-in variable: $CI_PROJECT_PATH.
137 --key, --k SSH Key linked to your personal GitLab account.
138 --user, -u Git username linked to your personal GitLab account.
139 --email, -e Git email linked to your personal GitLab account.
140 --oAuthToken, --oauth NPM Registery authentication file.
141```
142
143```bash
144npx tag-cli update-dependents
145```
146
147#### Troubleshooting
148
149`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.
150
151### publish-tag
152The `publish-tag` command publishes an tags artifact.
153
154```bash
155Options:
156 --version Show version number [boolean]
157 --help Show help [boolean]
158 --jobToken, -j The GitLab's built-in job token: $CI_JOB_TOKEN. This token
159 is generated for each job.
160 --token, -t GitLab's personal access token with admin rights.
161 --tagManagerId, -i GitLab's Tag Manager project ID.
162 --key, -k SSH Key linked to your personal GitLab account.
163 --user, -u Git username linked to your personal GitLab account.
164 --email, -e Git email linked to your personal GitLab account.
165 --incrementVersion Boolean that indicates if standard-version should invoke.
166```
167
168```bash
169npx tag-cli publish-tag
170```
171
172### test-tag
173The `test-tag` command is part of the tags pipeline and run both the unit tests as uploading a code coverage report to [Codecov](https://codecov.io/).
174
175```bash
176Options:
177 --version Show version number [boolean]
178 --help Show help [boolean]
179 --codecov, -c Your Codecov token to publish code coverage report. # CODE_COV_TOKEN
180 --branchName, --n The current branch name, equal to: $CI_COMMIT_REF_NAME. # BRANCH_NAME
181```
182
183```bash
184npx tag-cli test-tag
185```
186
187### lint-tag
188The `lint-tag` command runs the [TypeScript linter](https://palantir.github.io/tslint/), as described in the tslint.json.
189
190```bash
191Options:
192 --version Show version number [boolean]
193 --help Show help [boolean]
194 --branchName, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
195```
196
197```bash
198npx tag-cli lint-tag
199```
200
201### type-tag
202The `type-tag` command runs the [TypeScript transpiler](http://www.typescriptlang.org/), including declarations as described in the tsconfig.json.
203
204```bash
205Options:
206 --version Show version number [boolean]
207 --help Show help [boolean]
208 --branchName, --n The current branch name, equal to: $CI_COMMIT_REF_NAME. # or pass BRANCH_NAME as environment var
209```
210
211```bash
212npx tag-cli lint-tag --branchName development
213```
214
215### deploy-test-instance
216The `deploy-test-instance` command deploys a build version of the Tag Manager on a private test 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.
217
218```bash
219Options:
220 --version Show version number [boolean]
221 --help Show help [boolean]
222 --accessToken, --token The GitLab personal accesstoken with owner rights.
223 --groupId, --id The GitLab Group ID that should be analyzed
224 --branchName, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
225 --jobToken, --j The GitLab's built-in job token: $CI_JOB_TOKEN. This token is generated for each job.
226```
227
228```bash
229npx tag-cli deploy-test-instance
230```
231
232### deploy-tag-manager
233The deploy tag manager commands deploys the build tag manager to a GCP bucket and a GitLab test page.
234
235```bash
236Options:
237 --version Show version number [boolean]
238 --help Show help [boolean]
239 --bucketName, -b Name of the Google Cloud Bucket.
240 --keyFileName, -k Google Cloud authentication JSON key.
241 --groupName, -i The namespace of the GitLab Group, equal to: $CI_PROJECT_NAMESPACE.
242 --branchName, -n The current branch name, equal to: $CI_COMMIT_REF_NAME.
243 --nodeEmail, -gm Gmail email address, that can function as transporter. More info at: https://nodemailer.com/usage/using-gmail/.
244 --nodePass, -pass Password of the gmail account that functions as transporter.
245 --receivers, -list String array of receivers.
246```
247
248```bash
249npx tag-cli deploy-tag-manager
250```
251
252## GitLab Configurations
253
254### Setup of a Tag Manager
255
256The `create-tag-manager` creates a Tag Manager boilerplate.
257
258> It's recommended to not modify the generated files.
259
260```bash
261mkdir tag-manager
262cd tag-manager
263npm init --y
264npm i -D @d-cat/tag-cli
265npx tag-cli create-tag-manager
266```
267
268### GitLab configuration
269
270Make sure you did all necessary steps to [start with GitLab](https://docs.gitlab.com/ee/gitlab-basics/).
271
272- Create a new GitLab (sub)group with name as Container ID: (i.e. 8030);
273- Create a new project, called Tag Manager;
274- Create CI/CD variables.
275
276#### CI/CD variables to create in GitLab
277
278Before you run the pipeline and the tag manager can be deployed, make sure you [create the necessary CI/CD variables](https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables) in your GitLab project.
279
280| CI/CD variable | Type | Description |
281| ----------------------- | :------: | :--------------------------------------------------------------------------------------------------------- |
282| `PERSONAL_ACCESS_TOKEN` | variable | Your personal access token, that has owner rights of the tags group. |
283| `CONTAINER_ID` | variable | Group ID that should be queried for tags. |
284| `GCLOUD_SERVICE_KEY` | file | Your [authentication file](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud. |
285| `SSH_KEY` | file | Your SSH key to clone and push repo's of GitLab. |
286| `GIT_USER_EMAIL` | variable | Your git email: `git config user.email`. |
287| `GIT_USER_NAME` | variable | Your git user name: `git config user.name`. |
288
289## Troubleshooting
290- `Publishing tag TypeError: Cannot read property 'map' of undefined`: make sure your `tag-cli.json` has an string array of both `branchesToImportInTagManager` and `branchesToRunInPipeline`.
291- `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`.
292 When having other issues, please contact [D-CAT](https://data.ziggo.nl/).
293- `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.
294
295
296### Setup of a Tag
297Steps to create a tag.
298
299```bash
300mkdir my-tag
301cd my-tag
302npm init
303npm i -D @d-cat/tag-cli
304npx tag-cli create-new-tag
305```
306
307#### tag-cli.json
308
309The `create-new-tag` command will create a file called `tag-cli.json`. This file contains all settings to indicate it's behavior. The `tag-cli.json` file includes both `pipeline` as `tag manager` settings.
310
311##### Pipeline settings
312
313This are settings that indicates how a tag should behave.
314
315| Prop | Type | Desc |
316| ------------- |:-------------:| :-----|
317| `isPipelineActive` | Boolean | Boolean that indicates if the tags pipeline should run.|
318| `pipelineBranches` | String[] | String array of branches that should trigger the Tag's pipeline. |
319| `isImportInTagManager` | Boolean | Boolean to indicate if the tag should be imported in the tag manager. |
320| `tagManagerBranches` | String[] | String array of tag branches that should be included in a tag manager bundle. |
321| `isActive` | Boolean | Boolean that indicates if the tag is active. |
322| `isTrigger` | Boolean | Boolean that indicates if the tag should trigger the Tag Managers pipeline after a publish. |
323
324##### Tag Manager settings
325
326This are settings that determine how the tag should behave inside the Tag Manager.
327
328| Prop | Type | Desc |
329| ------------- |:-------------:| :-----|
330| `firingAmount` | Number | Amount a tag should be invoked when all business rules apply. |
331| `priority` | Number | Priority of tag. 1 is highest priority. |
332| `id` | String | UUID. |
333| `urls` | IUrl[] | Object Array that contains 2 props: `url` (RegExp) and `reverse` (boolean). |
334| `triggers` | ITrigger[] | Boolean that indicates if the tag is active. |
335
336###### `ITrigger`
337
338| Options | Type | Required Description |
339| --------- | :-----: | :------ |:---- |
340| `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. |
341| `id` | String | true | Uniquely generated ID. Using the CLI this will generate an ID using [uuid/v1](https://www.npmjs.com/package/uuid). |
342| `name` | String | false | Depending on the type, the name key has a different function. |
343| `value` | String | false | Depending on the type, the value key has a different function. |
344| `reverse` | Boolean | false | Reverse the match on either value or name. |
345| `element` | String | false | `window`, `document` both as string or an element ID. |
346
347#### GitLab configuration
348
349Make sure you did all necessary steps to [start with GitLab](https://docs.gitlab.com/ee/gitlab-basics/).
350
351- Create a new project inside a GitLab group.
352- Create CI/CD variables
353- Push branches to GitLab
354
355##### CI/CD variables to create in GitLab
356
357Before you run the pipeline and the tag manager can be deployed, make sure you [create the necessary CI/CD variables](https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables) in your GitLab project.
358
359| CI/CD variable | Type | Description |
360| ----------------------- | :------: | :----- |
361| `PERSONAL_ACCESS_TOKEN` | variable | Your personal access token, that has owner rights of the tags group. |
362| `TAG_MANAGER_ID` | variable | Gitlab Project ID of the Tag Manager. |
363| `GCLOUD_SERVICE_KEY` | file | Your [authentication file](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud. |
364| `SSH_KEY` | file | Your SSH key to clone and push repo's of GitLab. |
365| `GIT_USER_EMAIL` | variable | Your git email: `git config user.email`. |
366| `GIT_USER_NAME` | variable | Your git user name: `git config user.name`. |
367| `CODECOV_TOKEN` | variable | Your Codecov token to publish code coverage reports. |
368
369#### Troubleshooting
370> If the pipeline isn't running after the initial commit, trigger the pipeline manually.
\No newline at end of file