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