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
|
10 | npm i -D @d-cat/tag-cli
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 | @d-cat/tag-cli is a toolkit to deploy and develop a Tag Manager with Tags using GitLab and Google Cloud Platform.
|
15 |
|
16 | ### create-tag-manager
|
17 | The `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.
|
18 |
|
19 | ```bash
|
20 | Options:
|
21 | --version Show version number [boolean]
|
22 | --help Show help [boolean]
|
23 | ```
|
24 |
|
25 | #### What's included
|
26 | The Tag Manager boilerplate contains everything to:
|
27 | * unit test the build version of the tag manager
|
28 | * e2e test the build version of the tag manager in chrome headless browser
|
29 | * deploy test/prod containers in a GCP bucket
|
30 | * deploy testable open websites with the TMS running on it for functional testing
|
31 | * dockerized TMS to run the TMS locally in isolation
|
32 | * dockerized TMS that registers images in GitLab private registery
|
33 | * stable pipeline file with artifacts enabled both on success as failure
|
34 | * babel/ts for browser compatibility
|
35 |
|
36 | Some 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`.
|
37 |
|
38 | > The roadmap is to replace interpolated files with a configuration (json/yml) file to make it more intuitive.
|
39 |
|
40 | #### Dependencies
|
41 | By 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:
|
42 |
|
43 | ```bash
|
44 | npm i yourpackage@1.0.0
|
45 | ```
|
46 |
|
47 | #### Examples
|
48 | Make sure docker is installed and you've updated your [.env](https://docs.docker.com/compose/environment-variables/) file.
|
49 |
|
50 | ```bash
|
51 | # creating a tag manager boilerplate
|
52 | npx tag-cli create-tag-manager
|
53 |
|
54 | # running a tag manager locally in isolation on localhost:8080
|
55 | docker build -t ${img_name} .
|
56 | docker run --name ${container_name} --rm -p 8080:8080 -ti ${img_name}:latest
|
57 |
|
58 | # running a tag manager locally in isolation with docker-compose
|
59 | docker-compose build bundle
|
60 | docker-compose up bundle
|
61 |
|
62 | # running the full tms pipeline (except deployment in gcp/test sites) locally in isolation
|
63 | docker-compose build deploy
|
64 | docker-compose up deploy
|
65 | ```
|
66 |
|
67 |
|
68 | ### create-new-tag
|
69 | The `create-new-tag` command creates a new Tag boilerplate designed to use with @d-cat/tag-cli within GitLab CI/CD.
|
70 |
|
71 | ```bash
|
72 | Options:
|
73 | --version Show version number [boolean]
|
74 | --help Show help [boolean]
|
75 | ```
|
76 |
|
77 | #### What's included
|
78 | The Tag boilerplate contains all configurations to:
|
79 | * Jest setup
|
80 | * tslint setup
|
81 | * prettier
|
82 | * husky
|
83 | * tag config file (`tag-cli.json`)
|
84 | * dockerized tag environment to run the tag locally in isolation
|
85 | * dockerized TMS that registers images in GitLab private registery
|
86 | * stable pipeline file with artifacts enabled both on success and failure
|
87 | * standard-version to created changelog + semver in the pipeline
|
88 |
|
89 | #### Dependencies
|
90 | By 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:
|
91 |
|
92 | ```bash
|
93 | npm i yourpackage@1.0.0
|
94 | ```
|
95 |
|
96 | #### Examples
|
97 | Make sure docker is installed and you've updated your [.env](https://docs.docker.com/compose/environment-variables/) file.
|
98 |
|
99 | ```bash
|
100 | # creating a tag boilerplate
|
101 | npx tag-cli create-new-tag
|
102 |
|
103 | # running a tag locally in isolation on localhost:1234
|
104 | docker build -t ${img_name} .
|
105 | docker run --name ${tag_name} --rm -p 1234:1234 ${img_name}:latest
|
106 |
|
107 | # running a tag locally in isolation with docker-compose
|
108 | docker-compose build build
|
109 | docker-compose up build
|
110 |
|
111 | # running the full tag pipeline (except uploading artifacts) locally in isolation
|
112 | docker-compose build pipeline
|
113 | docker-compose up pipeline
|
114 | ```
|
115 |
|
116 | ### bundle-tag-manager
|
117 | The `bundle-tag-manager` command bundles tag `artifacts` to eventually transpile and deploy a Tag Manager.
|
118 |
|
119 | ![bundle-tag-manager](https://www.plantuml.com/plantuml/png/PP4nRuD038Nt-nLFx205MBf46IfbQQTaYpeud8Ee21Tn9b9LyTzxLYyj5zY-Ppy_czjveL6cQsykhhSy8ZkuAsFVoHkTiH_TTClmRH2QkWir0g6sJh5AiKnnOsRpDpkEVULRxxuUqyd7ECs9dKVsSkY4DokbN2dLIgdD38F_s2ErUAU1MXxrc5DW_w5xDRsRhCRY97Pu2LyXlnLBGcVoZCms93aFzzpoNTruf0M7uiBx6Rp0h7wz74MnHGmBN3vnzSJrakEIAgMxBG5vlatILzNuPysE1niU-GS0)
|
120 |
|
121 | ```bash
|
122 | Options:
|
123 | --version Show version number [boolean]
|
124 | --help Show help [boolean]
|
125 | --access-token, --token The GitLab personal accesstoken with owner rights.
|
126 | --group-id, --id The GitLab Group ID that should be analyzed.
|
127 | --dir-name, --dir The unique dir name where to store the temporary artifacts.
|
128 | --branch-name, --branch The current branch.
|
129 | --job-token, --j GitLabs built-in job token: $CI_JOB_TOKEN. This token is generated for each job.
|
130 | --environment --e TMS environment, should be either `development` or `production`.
|
131 | ```
|
132 |
|
133 | #### Example
|
134 | Note that all flags are either mandatory or are set as a node environment variable.
|
135 |
|
136 | ```bash
|
137 | npx tag-cli bundle-tag-manager
|
138 | ```
|
139 |
|
140 | ### update-dependents
|
141 | If 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.
|
142 |
|
143 | ```bash
|
144 | # flags
|
145 | Options:
|
146 | --version Show version number [boolean]
|
147 | --help Show help [boolean]
|
148 | --access-token, --token The GitLab personal accesstoken with owner rights.
|
149 | --project-id, --d The current project ID, equal to: $CI_PROJECT_ID.
|
150 | --project-path, --p The relative path to the project's repository in GitLab. This equals GitLab's built-in variable: $CI_PROJECT_PATH.
|
151 | --key, --k SSH Key linked to your personal GitLab account.
|
152 | --user, -u Git username linked to your personal GitLab account.
|
153 | --email, -e Git email linked to your personal GitLab account.
|
154 | --job-token, --j GitLabs built-in job token: $CI_JOB_TOKEN. This token is generated for each job.
|
155 | ```
|
156 |
|
157 | ![update-dependents](https://www.plantuml.com/plantuml/png/dT4x3iCW40JGtgT0z3Wo7-WYxX5Hh6pa8X1PoVh-yG7C8hOU7iE8-4FuubdBTC3wXZqB6JUr0ZuGTeMv7WKmgqLEz04jwTnqSjihS9qBV2SFLy7hTbeIIZt5RQRJk34COnd6fSOWIwDXunacj1wdavZd1beQHOPXBCCusj1ev5izmmJQnFpPpbh-)
|
158 |
|
159 | #### Example
|
160 | Note that all flags are either mandatory or are set as an environment variable:
|
161 |
|
162 | ```bash
|
163 | ACCESS_TOKEN=myAccesToken
|
164 | DIR_NAME=foo
|
165 | PROJECT_ID=1210
|
166 | SSH_KEY=key
|
167 | GIT_EMAIL=myEmail
|
168 | ```
|
169 |
|
170 | ```bash
|
171 | npx tag-cli update-dependents --user myGitName
|
172 | ```
|
173 |
|
174 | #### Troubleshooting
|
175 |
|
176 | `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.
|
177 |
|
178 | ### deploy-tag-template
|
179 | The `deploy-tag-template` command deploys a tag template on a NPM public registery.
|
180 |
|
181 | ```bash
|
182 | Options:
|
183 | --version Show version number [boolean]
|
184 | --help Show help [boolean]
|
185 | --access-token, --token The GitLab personal accesstoken with owner rights.
|
186 | --branch-name, --branch The current branch.
|
187 | --project-path, --p The relative path to the project's repository in GitLab. This equals GitLab's built-in variable: $CI_PROJECT_PATH.
|
188 | --key, --k SSH Key linked to your personal GitLab account.
|
189 | --user, -u Git username linked to your personal GitLab account.
|
190 | --email, -e Git email linked to your personal GitLab account.
|
191 | --o-auth-token, --oauth NPM Registery authentication file.
|
192 | ```
|
193 |
|
194 | #### Examples
|
195 | Note that all flags are either mandatory or are set as an environment variable.
|
196 |
|
197 | ```bash
|
198 | npx tag-cli deploy-tag-template
|
199 | ```
|
200 |
|
201 | ### publish-tag
|
202 | The `publish-tag` command publishes an tags artifact.
|
203 |
|
204 | ```bash
|
205 | Options:
|
206 | --version Show version number [boolean]
|
207 | --help Show help [boolean]
|
208 | --job-token, -j The GitLab's built-in job token: $CI_JOB_TOKEN. This token
|
209 | is generated for each job.
|
210 | --token, -t GitLab's personal access token with admin rights.
|
211 | --tag-manager-id, -i GitLab's Tag Manager project ID.
|
212 | --key, -k SSH Key linked to your personal GitLab account.
|
213 | --user, -u Git username linked to your personal GitLab account.
|
214 | --email, -e Git email linked to your personal GitLab account.
|
215 | --increment-version Boolean that indicates if standard-version should invoke.
|
216 | ```
|
217 |
|
218 | ### Examples
|
219 | Note that all flags are either mandatory or are set as an environment variable.
|
220 |
|
221 | ```bash
|
222 | # incrementing version
|
223 | npx tag-cli publish-tag --increment-version
|
224 |
|
225 | # do not inrement version
|
226 | npx tag-cli publish-tag --no-increment-version
|
227 | ```
|
228 |
|
229 | ### test-tag
|
230 | The `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/).
|
231 |
|
232 | ```bash
|
233 | Options:
|
234 | --version Show version number [boolean]
|
235 | --help Show help [boolean]
|
236 | --codecov, -c Your Codecov token to publish code coverage report.
|
237 | --branch-name, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
|
238 | ```
|
239 |
|
240 | ### Examples
|
241 | Note that all flags are either mandatory or are set as an environment variable.
|
242 |
|
243 | ```bash
|
244 | npx tag-cli test-tag
|
245 | ```
|
246 |
|
247 | ### lint-tag
|
248 | The `lint-tag` command runs the [TypeScript linter](https://palantir.github.io/tslint/), as described in the tslint.json.
|
249 |
|
250 | ```bash
|
251 | Options:
|
252 | --version Show version number [boolean]
|
253 | --help Show help [boolean]
|
254 | --branch-name, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
|
255 | ```
|
256 |
|
257 | ### Examples
|
258 | Note that all flags are either mandatory or are set as an environment variable.
|
259 |
|
260 | ```bash
|
261 | npx tag-cli lint-tag --branch-name $CI_COMMIT_REF_NAME
|
262 | ```
|
263 |
|
264 | ### type-tag
|
265 | The `type-tag` command runs type checks the tag according TypeScript specs.
|
266 |
|
267 | ```bash
|
268 | Options:
|
269 | --version Show version number [boolean]
|
270 | --help Show help [boolean]
|
271 | --branch-name, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
|
272 | ```
|
273 |
|
274 | ### Examples
|
275 | Note that all flags are either mandatory or are set as an environment variable.
|
276 |
|
277 | ```bash
|
278 | npx tag-cli type-tag --branch-name $CI_COMMIT_REF_NAME
|
279 | ```
|
280 |
|
281 | ### deploy-test-instance
|
282 | The `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.
|
283 |
|
284 | ```bash
|
285 | Options:
|
286 | --version Show version number [boolean]
|
287 | --help Show help [boolean]
|
288 | --access-token, --token The GitLab personal accesstoken with owner rights.
|
289 | --group-id, --id The GitLab Group ID that should be analyzed
|
290 | --branch-name, --n The current branch name, equal to: $CI_COMMIT_REF_NAME.
|
291 | --job-token, --j The GitLab's built-in job token: $CI_JOB_TOKEN. This token is generated for each job.
|
292 | ```
|
293 |
|
294 | ### Examples
|
295 | Note that all flags are either mandatory or are set as an environment variable.
|
296 |
|
297 | ```bash
|
298 | npx tag-cli deploy-test-instance
|
299 | ```
|
300 |
|
301 | ### deploy-tag-manager
|
302 | The deploy tag manager commands deploys the build tag manager to a GCP bucket and a GitLab test page.
|
303 |
|
304 | ```bash
|
305 | Options:
|
306 | --version Show version number [boolean]
|
307 | --help Show help [boolean]
|
308 | --bucket-name, -b Name of the Google Cloud Bucket.
|
309 | --key-file-name, -k Google Cloud authentication JSON key.
|
310 | --group-name, -i The namespace of the GitLab Group, equal to: $CI_PROJECT_NAMESPACE.
|
311 | --branch-name, -n The current branch name, equal to: $CI_COMMIT_REF_NAME.
|
312 | --node-email, -gm Gmail email address, that can function as transporter. More info at: https://nodemailer.com/usage/using-gmail/.
|
313 | --node-pass, -pass Password of the gmail account that functions as transporter.
|
314 | --receivers, -list String array of receivers.
|
315 | --is-empty -e Boolean that indicates if an empty container should be deployed. Defaults to false.
|
316 | ```
|
317 |
|
318 | ### Examples
|
319 | Note that all flags are either mandatory or are set as an environment variable.
|
320 |
|
321 | ```bash
|
322 | # deploy empty
|
323 | npx tag-cli deploy-tag-manager --is-empty
|
324 |
|
325 | # deploy non-empty (default)
|
326 | npx tag-cli deploy-tag-manager --no-is-empty
|
327 | ```
|
328 |
|
329 | ## GitLab Configurations
|
330 |
|
331 | ### Setup of a Tag Manager
|
332 |
|
333 | The `create-tag-manager` creates a Tag Manager boilerplate.
|
334 |
|
335 | > It's recommended to not modify the generated files.
|
336 |
|
337 | ```bash
|
338 | mkdir tag-manager
|
339 | cd tag-manager
|
340 | npm init --y
|
341 | npm i -D @d-cat/tag-cli
|
342 | npx tag-cli create-tag-manager
|
343 | ```
|
344 |
|
345 | ### GitLab configuration
|
346 |
|
347 | Make sure you did all necessary steps to [start with GitLab](https://docs.gitlab.com/ee/gitlab-basics/).
|
348 |
|
349 | - Create a new GitLab (sub)group with name as Container ID: (i.e. 8030);
|
350 | - Create a new project, called Tag Manager;
|
351 | - Create CI/CD variables.
|
352 |
|
353 | #### CI/CD variables to create in GitLab
|
354 |
|
355 | Before 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.
|
356 |
|
357 | | CI/CD variable | Type | Description |
|
358 | | ----------------------- | :------: | :--------------------------------------------------------------------------------------------------------- |
|
359 | | `PERSONAL_ACCESS_TOKEN` | variable | Your personal access token, that has owner rights of the tags group. |
|
360 | | `CONTAINER_ID` | variable | Group ID that should be queried for tags. |
|
361 | | `GCLOUD_SERVICE_KEY` | file | Your [authentication file](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud. |
|
362 | | `SSH_KEY` | file | Your SSH key to clone and push repo's of GitLab. |
|
363 | | `GIT_USER_EMAIL` | variable | Your git email: `git config user.email`. |
|
364 | | `GIT_USER_NAME` | variable | Your git user name: `git config user.name`. |
|
365 |
|
366 | ## Troubleshooting
|
367 | - `Publishing tag TypeError: Cannot read property 'map' of undefined`: make sure your `tag-cli.json` has an string array of both `branchesToImportInTagManager` and `branchesToRunInPipeline`.
|
368 | - `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`.
|
369 | When having other issues, please contact [D-CAT](https://data.ziggo.nl/).
|
370 | - `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.
|
371 |
|
372 |
|
373 | ### Setup of a Tag
|
374 | Steps to create a tag.
|
375 |
|
376 | ```bash
|
377 | mkdir my-tag
|
378 | cd my-tag
|
379 | npm init
|
380 | npm i -D @d-cat/tag-cli
|
381 | npx tag-cli create-new-tag
|
382 | ```
|
383 |
|
384 | #### tag-cli.json
|
385 |
|
386 | The `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.
|
387 |
|
388 | ##### Pipeline settings
|
389 |
|
390 | This are settings that indicates how a tag should behave.
|
391 |
|
392 | | Prop | Type | Desc |
|
393 | | ------------- |:-------------:| :-----|
|
394 | | `isPipelineActive` | Boolean | Boolean that indicates if the tags pipeline should run.|
|
395 | | `pipelineBranches` | String[] | String array of branches that should trigger the Tag's pipeline. |
|
396 | | `isImportInTagManager` | Boolean | Boolean to indicate if the tag should be imported in the tag manager. |
|
397 | | `tagManagerBranches` | String[] | String array of tag branches that should be included in a tag manager bundle. |
|
398 | | `isActive` | Boolean | Boolean that indicates if the tag is active. |
|
399 | | `isTrigger` | Boolean | Boolean that indicates if the tag should trigger the Tag Managers pipeline after a publish. |
|
400 |
|
401 | ##### Tag Manager settings
|
402 |
|
403 | This are settings that determine how the tag should behave inside the Tag Manager.
|
404 |
|
405 | | Prop | Type | Desc |
|
406 | | ------------- |:-------------:| :-----|
|
407 | | `firingAmount` | Number | Amount a tag should be invoked when all business rules apply. |
|
408 | | `priority` | Number | Priority of tag. 1 is highest priority. |
|
409 | | `id` | String | UUID. |
|
410 | | `urls` | IUrl[] | Object Array that contains 2 props: `url` (RegExp) and `reverse` (boolean). |
|
411 | | `triggers` | ITrigger[] | Boolean that indicates if the tag is active. |
|
412 |
|
413 | ###### `ITrigger`
|
414 |
|
415 | | Options | Type | Required Description |
|
416 | | --------- | :-----: | :------ |:---- |
|
417 | | `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. |
|
418 | | `id` | String | true | Uniquely generated ID. Using the CLI this will generate an ID using [uuid/v1](https://www.npmjs.com/package/uuid). |
|
419 | | `name` | String | false | Depending on the type, the name key has a different function. |
|
420 | | `value` | String | false | Depending on the type, the value key has a different function. |
|
421 | | `reverse` | Boolean | false | Reverse the match on either value or name. |
|
422 | | `element` | String | false | `window`, `document` both as string or an element ID. |
|
423 |
|
424 | #### GitLab configuration
|
425 |
|
426 | Make sure you did all necessary steps to [start with GitLab](https://docs.gitlab.com/ee/gitlab-basics/).
|
427 |
|
428 | - Create a new project inside a GitLab group.
|
429 | - Create CI/CD variables
|
430 | - Push branches to GitLab
|
431 |
|
432 | ##### CI/CD variables to create in GitLab
|
433 |
|
434 | Before 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.
|
435 |
|
436 | | CI/CD variable | Type | Description |
|
437 | | ----------------------- | :------: | :----- |
|
438 | | `PERSONAL_ACCESS_TOKEN` | variable | Your personal access token, that has owner rights of the tags group. |
|
439 | | `TAG_MANAGER_ID` | variable | Gitlab Project ID of the Tag Manager. |
|
440 | | `GCLOUD_SERVICE_KEY` | file | Your [authentication file](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud. |
|
441 | | `SSH_KEY` | file | Your SSH key to clone and push repo's of GitLab. |
|
442 | | `GIT_USER_EMAIL` | variable | Your git email: `git config user.email`. |
|
443 | | `GIT_USER_NAME` | variable | Your git user name: `git config user.name`. |
|
444 | | `CODECOV_TOKEN` | variable | Your Codecov token to publish code coverage reports. |
|
445 |
|
446 | #### Troubleshooting
|
447 | > If the pipeline isn't running after the initial commit, trigger the pipeline manually. |
\ | No newline at end of file |