@seniorsistemas/exclusion-process-component 0.0.1-c049d10c-e93a-4d63-9c2a-b17bca40c324 → 0.6.0-44030ff3-2eeb-49f7-8927-0920cc01a805

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/.editorconfig +19 -0
  2. package/.gitlab-ci.yml +74 -0
  3. package/.prettierrc +8 -0
  4. package/.senior-ci-extensions.sh +21 -0
  5. package/.vscode/settings.json +6 -0
  6. package/CHANGELOG.md +22 -0
  7. package/README.md +16 -0
  8. package/angular.json +144 -0
  9. package/archive.tar.gz +0 -0
  10. package/e2e/app.e2e-spec.ts +14 -0
  11. package/e2e/app.po.ts +11 -0
  12. package/e2e/tsconfig.e2e.json +14 -0
  13. package/karma.conf.js +53 -0
  14. package/lib/.browserslistrc +5 -0
  15. package/lib/package.json +19 -0
  16. package/{enums/enum-exclusion-process-status.d.ts → lib/src/enums/enum-exclusion-process-status.ts} +1 -1
  17. package/lib/src/exclusion-details/exclusion-details.component.html +84 -0
  18. package/lib/src/exclusion-details/exclusion-details.component.scss +47 -0
  19. package/lib/src/exclusion-details/exclusion-details.component.spec.ts +171 -0
  20. package/lib/src/exclusion-details/exclusion-details.component.ts +235 -0
  21. package/lib/src/exclusion-details/exclusion-details.module.ts +23 -0
  22. package/{exclusion-details/protocols/exclusion-details.d.ts → lib/src/exclusion-details/protocols/exclusion-details.ts} +1 -0
  23. package/{exclusion-details/protocols/show-details-information.d.ts → lib/src/exclusion-details/protocols/show-details-information.ts} +1 -1
  24. package/lib/src/exclusions-list/exclusions-list.component.html +157 -0
  25. package/lib/src/exclusions-list/exclusions-list.component.spec.ts +526 -0
  26. package/lib/src/exclusions-list/exclusions-list.component.ts +335 -0
  27. package/lib/src/exclusions-list/exclusions-list.module.ts +52 -0
  28. package/lib/src/exclusions-list/exclusions-list.routing.ts +89 -0
  29. package/lib/src/exclusions-list/index.ts +2 -0
  30. package/lib/src/logical-delete.module.ts +22 -0
  31. package/{models/exclusion-process-step-group.d.ts → lib/src/models/exclusion-process-step-group.ts} +1 -0
  32. package/{models/exclusion-process-step.d.ts → lib/src/models/exclusion-process-step.ts} +1 -0
  33. package/{models/exclusion-process.d.ts → lib/src/models/exclusion-process.ts} +1 -0
  34. package/{models/list-params.d.ts → lib/src/models/list-params.ts} +1 -0
  35. package/{models/project-config.d.ts → lib/src/models/project-config.ts} +3 -1
  36. package/lib/src/services/filter.service.spec.ts +290 -0
  37. package/lib/src/services/filter.service.ts +109 -0
  38. package/lib/src/services/index.ts +1 -0
  39. package/lib/src/services/logical-delete-config.service.spec.ts +59 -0
  40. package/lib/src/services/logical-delete-config.service.ts +25 -0
  41. package/lib/src/services/logical-delete.service.spec.ts +322 -0
  42. package/lib/src/services/logical-delete.service.ts +122 -0
  43. package/lib/test.ts +14 -0
  44. package/lib/tsconfig.lib.json +19 -0
  45. package/lib/tsconfig.lib.prod.json +6 -0
  46. package/lib/tsconfig.spec.json +12 -0
  47. package/lib/tslint.json +19 -0
  48. package/package.json +59 -18
  49. package/protractor.conf.js +28 -0
  50. package/senior-ci/.devcontainer/Dockerfile +27 -0
  51. package/senior-ci/.devcontainer/devcontainer.json +71 -0
  52. package/senior-ci/.editorconfig +14 -0
  53. package/senior-ci/.gitattributes +5 -0
  54. package/senior-ci/.gitlab-ci.yml +53 -0
  55. package/senior-ci/.pylintrc +562 -0
  56. package/senior-ci/.vscode/launch.json +102 -0
  57. package/senior-ci/CHANGELOG.md +1564 -0
  58. package/senior-ci/CONTRIBUTING.md +31 -0
  59. package/senior-ci/README.md +26 -0
  60. package/senior-ci/ci/ci.sh +74 -0
  61. package/senior-ci/ci/sonar_scanner.py +48 -0
  62. package/senior-ci/common/__init__.py +250 -0
  63. package/senior-ci/common/default-files/pom.xml +10 -0
  64. package/senior-ci/common/docker-helpers.sh +57 -0
  65. package/senior-ci/common/extensions.py +88 -0
  66. package/senior-ci/common/flutter-helpers.sh +3 -0
  67. package/senior-ci/common/getopt_helper.py +168 -0
  68. package/senior-ci/common/graphql_client.py +40 -0
  69. package/senior-ci/common/helm_helpers.py +40 -0
  70. package/senior-ci/common/notification-helpers.sh +15 -0
  71. package/senior-ci/common/npm-helper.sh +4 -0
  72. package/senior-ci/common/parallel-helper.sh +8 -0
  73. package/senior-ci/common/release-helpers.sh +196 -0
  74. package/senior-ci/common/s3cache-helpers.sh +47 -0
  75. package/senior-ci/common/senior-ci-extensions-helpers.sh +15 -0
  76. package/senior-ci/common/sonar_helper.py +203 -0
  77. package/senior-ci/common/validations/buildable_project.py +61 -0
  78. package/senior-ci/common/validations/check_deprecated_primitives.py +49 -0
  79. package/senior-ci/common/validations/check_project_path.py +40 -0
  80. package/senior-ci/common/validations/check_sonar_config_files.py +41 -0
  81. package/senior-ci/common/validations/check_tags.py +41 -0
  82. package/senior-ci/common/validations/validate_changelog.py +151 -0
  83. package/senior-ci/common/validations/validate_issues.py +320 -0
  84. package/senior-ci/docker/build.sh +18 -0
  85. package/senior-ci/docker/config-host.sh +29 -0
  86. package/senior-ci/docker/deploy-service.sh +79 -0
  87. package/senior-ci/docker/push.sh +22 -0
  88. package/senior-ci/frontend/npm/bibliotecas/ci.sh +149 -0
  89. package/senior-ci/frontend/npm/ci.sh +370 -0
  90. package/senior-ci/frontend/npm/release-translations.sh +164 -0
  91. package/senior-ci/helm/deploy.py +56 -0
  92. package/senior-ci/helm/publish.py +41 -0
  93. package/senior-ci/hook/release_notification.sh +88 -0
  94. package/senior-ci/hook/text_notification.sh +10 -0
  95. package/senior-ci/java/bibliotecas/ci.sh +215 -0
  96. package/senior-ci/java/sdl/ci.sh +372 -0
  97. package/senior-ci/java/sdl/scripts/hotfix.sh +78 -0
  98. package/senior-ci/mobile/flutter/apps/__main__.py +5 -0
  99. package/senior-ci/mobile/flutter/apps/ci.py +193 -0
  100. package/senior-ci/mobile/flutter/libs/__main__.py +5 -0
  101. package/senior-ci/mobile/flutter/libs/ci.py +178 -0
  102. package/senior-ci/mobile/flutter/scripts/release.sh +54 -0
  103. package/senior-ci/release-candidate/backend/get_version.sh +64 -0
  104. package/senior-ci/release-candidate/close_branch.sh +113 -0
  105. package/senior-ci/release-candidate/common/create_hotfix.sh +28 -0
  106. package/senior-ci/release-candidate/common/create_release.sh +30 -0
  107. package/senior-ci/release-candidate/create_branch.sh +64 -0
  108. package/senior-ci/release-candidate/frontend/get_version.sh +43 -0
  109. package/senior-ci/requirements-dev.txt +5 -0
  110. package/senior-ci/requirements.txt +5 -0
  111. package/senior-ci/scripts/apply_yamls.py +229 -0
  112. package/senior-ci/scripts/create_sre_issue/__main__.py +7 -0
  113. package/senior-ci/scripts/create_sre_issue/create_sre_issue.py +267 -0
  114. package/senior-ci/scripts/create_sre_issue/helpers.py +166 -0
  115. package/senior-ci/scripts/create_sre_issue/jira_manager.py +37 -0
  116. package/senior-ci/scripts/validate_changelog.sh +3 -0
  117. package/senior-ci/sonar-project.properties +1 -0
  118. package/server.js +5 -0
  119. package/sonar-project.properties +10 -0
  120. package/src/app/app.component.html +43 -0
  121. package/src/app/app.component.scss +36 -0
  122. package/src/app/app.component.ts +56 -0
  123. package/src/app/app.module.ts +64 -0
  124. package/src/app/shared/shared.module.ts +28 -0
  125. package/src/environments/environment.default.ts +3 -0
  126. package/src/environments/environment.prod.ts +6 -0
  127. package/src/environments/environment.ts +7 -0
  128. package/src/favicon.ico +0 -0
  129. package/src/index.html +17 -0
  130. package/src/locale/en-US.json +3 -0
  131. package/src/locale/es-ES.json +3 -0
  132. package/src/locale/pt-BR.json +3 -0
  133. package/src/main.ts +13 -0
  134. package/src/polyfills.ts +58 -0
  135. package/src/styles.scss +11 -0
  136. package/src/tsconfig.app.json +21 -0
  137. package/src/typings.d.ts +15 -0
  138. package/tsconfig.json +39 -0
  139. package/tslint.json +80 -0
  140. package/bundles/seniorsistemas-exclusion-process-component.umd.js +0 -747
  141. package/bundles/seniorsistemas-exclusion-process-component.umd.js.map +0 -1
  142. package/bundles/seniorsistemas-exclusion-process-component.umd.min.js +0 -16
  143. package/bundles/seniorsistemas-exclusion-process-component.umd.min.js.map +0 -1
  144. package/esm2015/enums/enum-exclusion-process-status.js +0 -8
  145. package/esm2015/exclusion-details/exclusion-details.component.js +0 -216
  146. package/esm2015/exclusion-details/exclusion-details.module.js +0 -28
  147. package/esm2015/exclusion-details/index.js +0 -3
  148. package/esm2015/exclusion-details/protocols/exclusion-details.js +0 -1
  149. package/esm2015/exclusion-details/protocols/index.js +0 -2
  150. package/esm2015/exclusion-details/protocols/show-details-information.js +0 -3
  151. package/esm2015/logical-delete.module.js +0 -27
  152. package/esm2015/models/exclusion-process-step-group.js +0 -1
  153. package/esm2015/models/exclusion-process-step.js +0 -1
  154. package/esm2015/models/exclusion-process.js +0 -1
  155. package/esm2015/models/index.js +0 -1
  156. package/esm2015/models/list-params.js +0 -1
  157. package/esm2015/models/list-result.js +0 -1
  158. package/esm2015/models/project-config.js +0 -3
  159. package/esm2015/public-api.js +0 -3
  160. package/esm2015/seniorsistemas-exclusion-process-component.js +0 -9
  161. package/esm2015/services/filter.service.js +0 -104
  162. package/esm2015/services/logical-delete-config.service.js +0 -29
  163. package/esm2015/services/logical-delete.service.js +0 -109
  164. package/esm5/enums/enum-exclusion-process-status.js +0 -8
  165. package/esm5/exclusion-details/exclusion-details.component.js +0 -235
  166. package/esm5/exclusion-details/exclusion-details.module.js +0 -31
  167. package/esm5/exclusion-details/index.js +0 -3
  168. package/esm5/exclusion-details/protocols/exclusion-details.js +0 -1
  169. package/esm5/exclusion-details/protocols/index.js +0 -2
  170. package/esm5/exclusion-details/protocols/show-details-information.js +0 -7
  171. package/esm5/logical-delete.module.js +0 -31
  172. package/esm5/models/exclusion-process-step-group.js +0 -1
  173. package/esm5/models/exclusion-process-step.js +0 -1
  174. package/esm5/models/exclusion-process.js +0 -1
  175. package/esm5/models/index.js +0 -1
  176. package/esm5/models/list-params.js +0 -1
  177. package/esm5/models/list-result.js +0 -1
  178. package/esm5/models/project-config.js +0 -3
  179. package/esm5/public-api.js +0 -3
  180. package/esm5/seniorsistemas-exclusion-process-component.js +0 -9
  181. package/esm5/services/filter.service.js +0 -109
  182. package/esm5/services/logical-delete-config.service.js +0 -30
  183. package/esm5/services/logical-delete.service.js +0 -112
  184. package/exclusion-details/exclusion-details.component.d.ts +0 -49
  185. package/exclusion-details/exclusion-details.module.d.ts +0 -2
  186. package/fesm2015/seniorsistemas-exclusion-process-component.js +0 -495
  187. package/fesm2015/seniorsistemas-exclusion-process-component.js.map +0 -1
  188. package/fesm5/seniorsistemas-exclusion-process-component.js +0 -530
  189. package/fesm5/seniorsistemas-exclusion-process-component.js.map +0 -1
  190. package/logical-delete.module.d.ts +0 -5
  191. package/seniorsistemas-exclusion-process-component.d.ts +0 -8
  192. package/seniorsistemas-exclusion-process-component.metadata.json +0 -1
  193. package/services/filter.service.d.ts +0 -19
  194. package/services/logical-delete-config.service.d.ts +0 -8
  195. package/services/logical-delete.service.d.ts +0 -20
  196. /package/{exclusion-details/index.d.ts → lib/src/exclusion-details/index.ts} +0 -0
  197. /package/{exclusion-details/protocols/index.d.ts → lib/src/exclusion-details/protocols/index.ts} +0 -0
  198. /package/{models/index.d.ts → lib/src/models/index.ts} +0 -0
  199. /package/{models/list-result.d.ts → lib/src/models/list-result.ts} +0 -0
  200. /package/{public-api.d.ts → lib/src/public-api.ts} +0 -0
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+
3
+ get_version_release_candidate
4
+
5
+ call_extension "before_release"
6
+
7
+ echo -e "[CI] Iniciando processo de GitFlow\n"
8
+
9
+ echo "[CI] Criando branch hotfix/$VERSION_HYPHEN"
10
+ git checkout -B hotfix/$VERSION_HYPHEN
11
+
12
+ call_extension "before_change_changelog"
13
+
14
+ commit_changelog_template $VERSION
15
+
16
+ call_extension "after_change_changelog"
17
+
18
+ change_version
19
+
20
+ git commit -a -m "[CI] Criando versão $VERSION"
21
+
22
+ CI_REPOSITORY_URL_FOR_PUSH=$(echo "$CI_REPOSITORY_URL" | sed -e "s|.*@\(.*\)|git@\1|" -e "s|/|:|" )
23
+ git remote set-url --push origin "$CI_REPOSITORY_URL_FOR_PUSH"
24
+
25
+ echo "[CI] Enviando branch de hotfix"
26
+ git push origin hotfix/$VERSION_HYPHEN
27
+
28
+ exit
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+
3
+ get_version_release_candidate
4
+
5
+ call_extension "before_release"
6
+
7
+ create_release_branch
8
+
9
+ call_extension "before_change_changelog"
10
+
11
+ update_changelog_version
12
+
13
+ call_extension "after_change_changelog"
14
+
15
+ change_version
16
+
17
+ git commit -a -m "[CI] Criando versão $VERSION" -m "[auto release]"
18
+
19
+ git checkout develop
20
+
21
+ sed -i 's/{version}/'"$VERSION"'/' CHANGELOG.md
22
+
23
+ commit_changelog_template
24
+
25
+ push_branch_changes
26
+
27
+ echo "[CI] Pushing branchs"
28
+ git push --all
29
+
30
+ exit
@@ -0,0 +1,64 @@
1
+ #!/bin/bash
2
+
3
+ usage()
4
+ {
5
+ printf "\nWelcome,"
6
+ printf "\nThis script is used with the propouse of optimize the branch generation in your project\n"
7
+
8
+ printf "\nHow to Use:"
9
+ printf "\n\nA first parameter:"
10
+ printf "\nUse '-M' to specify that a major release will be create"
11
+ printf "\nUse '-m' to specify that a minor release will be create"
12
+ printf "\nUse '-p' to specify that a patch release will be create"
13
+ printf "\nUse '-h' to specify that a hotfix will be create"
14
+ printf "\n\nAnd a second parameter:"
15
+ printf "\nUse '--front' to specify that a branch are of frontend repository"
16
+ printf "\nUse '--back' to specify that a branch are of backend repository"
17
+ printf "\n"
18
+ }
19
+
20
+ invalid()
21
+ {
22
+ printf "\n $1 Option or Argument is invalid.\n"
23
+ }
24
+
25
+ . senior-ci/common/senior-ci-extensions-helpers.sh
26
+ . senior-ci/common/release-helpers.sh
27
+
28
+ case $2 in
29
+ --back)
30
+ REPO=back
31
+ ;;
32
+ --front)
33
+ REPO=front
34
+ ;;
35
+ *)
36
+ invalid $2;
37
+ usage;
38
+ exit 1
39
+ ;;
40
+ esac
41
+
42
+ case $1 in
43
+ -M)
44
+ RELEASE_KIND=major
45
+ . senior-ci/release-candidate/common/create_release.sh
46
+ ;;
47
+ -m)
48
+ RELEASE_KIND=minor
49
+ . senior-ci/release-candidate/common/create_release.sh
50
+ ;;
51
+ -p)
52
+ RELEASE_KIND=patch
53
+ . senior-ci/release-candidate/common/create_release.sh
54
+ ;;
55
+ -h)
56
+ RELEASE_KIND=patch
57
+ . senior-ci/release-candidate/common/create_hotfix.sh
58
+ ;;
59
+ *)
60
+ invalid $1;
61
+ usage;
62
+ exit 1
63
+ ;;
64
+ esac
@@ -0,0 +1,43 @@
1
+ #!/bin/bash
2
+
3
+ change_version() {
4
+ npm version --no-git-tag-version "$VERSION"
5
+
6
+ sed -i '3d' package.json
7
+ sed -i '3s|^|\t"version": "'$VERSION'",\n|' package.json
8
+ }
9
+
10
+ HEAD="$(git show -s --pretty=%d HEAD)"
11
+
12
+ echo $HEAD
13
+
14
+ VERSION="$(echo "$HEAD" | cut -d ',' -f2 | sed "s/-\([[:digit:]]\)/\.\1/g" | sed "s/[^[:digit:].]//g")"
15
+
16
+ echo "head version: $VERSION"
17
+
18
+ if [ -z "${VERSION}" ]; then
19
+ PACKAGE=$(<package.json)
20
+ VERSION=$(echo "$PACKAGE" | grep "version\":" | head -1 | cut -d ":" -f 2 | sed "s/[{, }, \", ',[:space:]]//g";)
21
+ fi
22
+
23
+ echo "package version: $VERSION"
24
+
25
+ if [ "$1" == "major" -o "$1" == "minor" -o "$1" == "patch" -o $? -ne 0 ]; then
26
+ get_next_version $1
27
+ fi
28
+
29
+ echo "senior-ci version: $VERSION"
30
+
31
+ VERSION_HYPHEN=$(echo "v$VERSION" | sed "s/\.\([[:digit:]]\)/-\1/g")
32
+
33
+ git ls-remote --heads origin | grep -E "refs/heads/hotfix/${VERSION_HYPHEN}/$" >/dev/null
34
+
35
+ if [[ "$?" -eq "0" ]]; then
36
+ echo "[CI] Já tem um hotfix para gerar a versão $VERSION, iremos considerrar a próxima"
37
+
38
+ get_next_version $1 $VERSION
39
+
40
+ VERSION_HYPHEN = $(echo "v$VERSION" | sed "s/\.\([[:digit:]]\)/-\1/g");
41
+ fi
42
+
43
+ echo -e "[CI] Version $VERSION_HYPHEN will be created\n"
@@ -0,0 +1,5 @@
1
+ -r requirements.txt
2
+
3
+ black==22.1.0
4
+ pylint==2.12.2
5
+ python-dotenv==0.19.2
@@ -0,0 +1,5 @@
1
+ colorama==0.4.4
2
+ gql==2.0.0
3
+ jira==3.1.1
4
+ PyYAML==6.0
5
+ boto3==1.12.24
@@ -0,0 +1,229 @@
1
+ import json
2
+ import sys
3
+ import time
4
+ from typing import NoReturn
5
+
6
+ import boto3
7
+ from colorama import Fore
8
+
9
+ sys.path.append("./senior-ci")
10
+
11
+ from common import (
12
+ ExitCode,
13
+ exec_command,
14
+ exec_command_and_return,
15
+ exec_command_without_print,
16
+ exit_message,
17
+ get_env_variable,
18
+ get_env_variable_required,
19
+ print_message,
20
+ )
21
+
22
+ LOCAL_PORT_NUMBER = "32221"
23
+ SKIPPED_STATUS = "Skipped"
24
+ DEVOPS_CD_ROOT_FOLDER = "devops_cd"
25
+ user = get_env_variable("SCI_BASTION_USER", "ec2-user")
26
+ instance_id = get_env_variable_required("SCI_EC2_INSTANCE_ID")
27
+ sci_aws_account_id = get_env_variable_required("SCI_AWS_ACCOUNT_ID")
28
+ default_region = get_env_variable_required("AWS_DEFAULT_REGION")
29
+ keep_devops_cd_folder = get_env_variable("SCI_KEEP_DEVOPS_CD_FOLDER", "false").lower() == 'true'
30
+ need_execute_apply_yamls = get_env_variable("SCI_EXECUTE_APPLY_YAMLS", "true").lower() == 'true'
31
+
32
+ def run_ec2_command(command: str) -> NoReturn:
33
+ exec_command(f'ssh -p {LOCAL_PORT_NUMBER} {user}@localhost "{command}"')
34
+
35
+ def create_folders(folders: list) -> NoReturn:
36
+ folders_str = ' '.join(folders)
37
+ command = f"mkdir -p {folders_str}"
38
+ run_ec2_command(command)
39
+
40
+ def run_scp_command(files: list) -> NoReturn:
41
+ for filename in files:
42
+ path_parts = filename.split('/')
43
+ relative_path = '/'.join(path_parts[:-1])
44
+ command_string = f"scp -P {LOCAL_PORT_NUMBER} {filename}"
45
+ scp_command = f"{command_string} {user}@localhost:{DEVOPS_CD_ROOT_FOLDER}/{relative_path}"
46
+ cmd = exec_command(scp_command)
47
+ if cmd.exit_code != ExitCode.SUCCESS:
48
+ exit_message(f"Não foi possível executar o SCP para o arquivo {filename}. Exit code: {cmd.exit_code}")
49
+
50
+ def access_bastion():
51
+ print("")
52
+ print_message("Acessando Bastion para aplicar os deployments.", Fore.CYAN)
53
+ print("")
54
+
55
+ sts = boto3.client("sts")
56
+ assumed_role_object = sts.assume_role(
57
+ RoleArn=f"arn:aws:iam::{sci_aws_account_id}:role/GitlabPipeline",
58
+ RoleSessionName="GitlabPipeline",
59
+ )
60
+ credentials = assumed_role_object["Credentials"]
61
+ ssm = boto3.client(
62
+ "ssm",
63
+ aws_access_key_id=credentials["AccessKeyId"],
64
+ aws_secret_access_key=credentials["SecretAccessKey"],
65
+ aws_session_token=credentials["SessionToken"],
66
+ )
67
+
68
+ print_message("Port Forwarding")
69
+ response = ssm.start_session(
70
+ Target=instance_id,
71
+ DocumentName="AWS-StartPortForwardingSession",
72
+ Parameters={
73
+ "portNumber": ["22"],
74
+ "localPortNumber": [LOCAL_PORT_NUMBER],
75
+ },
76
+ )
77
+ build_ssm_plugin(response)
78
+
79
+ # Tempo para iniciar o SSH Tunnel
80
+ time.sleep(5)
81
+
82
+ exec_command_without_print('echo "$SCI_BASTION_PRIVATE_KEY" | ssh-add -')
83
+
84
+ yamls_list = run_scp_of_yaml_diff()
85
+
86
+ if need_execute_apply_yamls:
87
+ comment = ','.join(yamls_list)
88
+ # Truncates de comment
89
+ comment = comment[:100]
90
+ status = execute_apply_yamls(ssm, comment)
91
+ else:
92
+ status = SKIPPED_STATUS
93
+
94
+ if not keep_devops_cd_folder:
95
+ run_ec2_command(f"sudo rm -rf {DEVOPS_CD_ROOT_FOLDER}")
96
+
97
+ check_command_invocation_status(status)
98
+
99
+ def execute_apply_yamls(ssm, comment):
100
+ print_message("Sending SSM command to apply YAMLs...")
101
+ response = ssm.send_command(
102
+ InstanceIds=[instance_id],
103
+ DocumentName="DevOps-ApplyYamls",
104
+ Comment=comment,
105
+ Parameters={
106
+ "User": [user]
107
+ }
108
+ )
109
+
110
+ print_message(f"SSM Command id: {response['Command']['CommandId']}")
111
+
112
+ output = None
113
+ command_not_finish = True
114
+
115
+ # Loop para validar se o comando já foi executado
116
+ while command_not_finish:
117
+ time.sleep(5)
118
+
119
+ output = ssm.get_command_invocation(
120
+ CommandId=response["Command"]["CommandId"], InstanceId=instance_id
121
+ )
122
+
123
+ print_message("Command current status: {}".format(output["Status"]))
124
+ if output["Status"] != "InProgress":
125
+ command_not_finish = False
126
+
127
+ stdout = output["StandardErrorContent"]
128
+ lines = stdout.split("\n")
129
+ del lines[-1]
130
+
131
+ for line in lines:
132
+ print_message(line)
133
+
134
+ stdout = output["StandardOutputContent"]
135
+ lines = stdout.split("\n")
136
+ del lines[-1]
137
+
138
+ for line in lines:
139
+ print_message(line)
140
+ return output["Status"]
141
+
142
+
143
+ def run_scp_of_yaml_diff() -> list:
144
+ caught_yamls = exec_command_and_return("git diff HEAD^ --name-only -- '*.yaml' '*.yml'")
145
+ caught_yamls_output = caught_yamls.output
146
+ if not caught_yamls_output:
147
+ exit_message(
148
+ "Não foi possível encontrar nenhum yaml para realizar a aplicação!"
149
+ )
150
+ caught_yamls_list = caught_yamls_output.split('\n')
151
+
152
+ # Removes empty strings
153
+ caught_yamls_list = [ filename for filename in caught_yamls_list if filename.strip() ]
154
+ # Make a list with folders
155
+ folders_to_create = [ '/'.join(filename.split('/')[:-1]) for filename in caught_yamls_list ]
156
+ # Removes duplicates (set) and add root folder for devops_cd
157
+ folders_to_create = [ f"devops_cd/{folder}" for folder in set(folders_to_create) ]
158
+
159
+ create_folders(folders_to_create)
160
+ run_scp_command(caught_yamls_list)
161
+ run_scp_of_cd_script(caught_yamls_list)
162
+ return caught_yamls_list
163
+
164
+
165
+ def run_scp_of_cd_script(caught_yamls: list) -> NoReturn:
166
+ caught_yamls_str = ' '.join(caught_yamls)
167
+ with open("k8s_apply.sh", "w", encoding="utf-8") as k8s_apply_sh:
168
+ script = (
169
+ "#!/bin/bash\n"
170
+ "\n"
171
+ "sudo wget -q https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq\n"
172
+ "\n"
173
+ f"export KUBECONFIG=/home/{user}/.kube/config\n"
174
+ "\n"
175
+ f"yamls=({caught_yamls_str})\n"
176
+ "\n"
177
+ "for i in ${yamls[@]}; do\n"
178
+ ' if [ -f "$i" ]; then\n'
179
+ " kubectl apply -f $i\n"
180
+ "\n"
181
+ " name=`cat $i | /usr/bin/yq -r .metadata.name`\n"
182
+ " namespace=`cat $i | /usr/bin/yq -r .metadata.namespace`\n"
183
+ "\n"
184
+ " if ! kubectl rollout status deployment $name -n $namespace; then\n"
185
+ " kubectl rollout undo deployment $name -n $namespace\n"
186
+ " kubectl rollout status deployment $name -n $namespace\n"
187
+ " fi\n"
188
+ " else\n"
189
+ ' echo "Arquivo não encontrado - $i"\n'
190
+ " fi\n"
191
+ "done\n"
192
+ "\n"
193
+ "echo 'Finish'\n"
194
+ )
195
+ k8s_apply_sh.write(script)
196
+
197
+ run_scp_command(["k8s_apply.sh"])
198
+
199
+ def check_command_invocation_status(status: str) -> NoReturn:
200
+ if status == "Success":
201
+ print_message("Deploy realizado com sucesso na Bastion!", Fore.GREEN)
202
+ elif status == SKIPPED_STATUS:
203
+ print_message("A etapa de deploy foi ignorada.", Fore.YELLOW)
204
+ else:
205
+ exit_message(
206
+ "Não foi possível realizar o deploy, pois foi finalizado com erro."
207
+ )
208
+
209
+
210
+ def build_ssm_plugin(session_manager_response) -> NoReturn:
211
+ plugin_file = "session-manager-plugin.deb"
212
+ session_manager_url = (
213
+ "https://s3.amazonaws.com/session-manager-downloads/"
214
+ f"plugin/latest/ubuntu_64bit/{plugin_file}"
215
+ )
216
+ exec_command(f'curl -s {session_manager_url} -o "{plugin_file}"')
217
+ exec_command(f"sudo dpkg -i {plugin_file}")
218
+
219
+ dumped_res = json.dumps(session_manager_response)
220
+ dumped_trgt = json.dumps(dict(Target=instance_id))
221
+ ssm_aws_url = f"https://ssm.{default_region}.amazonaws.com"
222
+ ssm_prefix = "session-manager-plugin"
223
+ session_start = f"{ssm_prefix} '{dumped_res}' {default_region} StartSession default '{dumped_trgt}' {ssm_aws_url}"
224
+
225
+ exec_command_without_print(f"{session_start} > /dev/null 2>&1 &")
226
+ exec_command_without_print(f"rm session-manager-plugin.deb")
227
+
228
+
229
+ access_bastion()
@@ -0,0 +1,7 @@
1
+ import sys
2
+
3
+ sys.path.append("./senior-ci")
4
+
5
+ from create_sre_issue import CreateSreIssue
6
+
7
+ CreateSreIssue(sys.argv[1:]).exec()
@@ -0,0 +1,267 @@
1
+ import json
2
+ import os
3
+ from datetime import datetime
4
+ from string import capwords
5
+
6
+ from colorama import Fore
7
+ from helpers import Backend, ChangelogReader, Frontend, Repository, find_changed_files
8
+ from jira_manager import JiraManager
9
+
10
+ from common import (
11
+ exit_message,
12
+ get_commit_tag_as_semver,
13
+ get_env_variable,
14
+ get_env_variable_required,
15
+ is_frontend,
16
+ print_message,
17
+ )
18
+ from common.getopt_helper import GetOptBuilder, Param
19
+ from common.graphql_client import GraphqlClient
20
+
21
+
22
+ class CreateSreIssue(GetOptBuilder):
23
+ def __init__(self, argv):
24
+ builder = super()
25
+ builder.__init__(argv)
26
+ self.client_graphql = GraphqlClient()
27
+
28
+ # Deprecated
29
+ tag_param = Param(
30
+ "tag", default_value=get_env_variable_required("CI_COMMIT_TAG")
31
+ )
32
+
33
+ # Deprecated (Only backend remuneration projects use)
34
+ repository_param = Param(
35
+ "repository", default_value=get_env_variable_required("CI_PROJECT_NAME")
36
+ )
37
+
38
+ module_param = Param("module", default_value="")
39
+
40
+ # Deprecated
41
+ changelog_base_path_param = Param("changelog_base_path", default_value=".")
42
+
43
+ sre_team_param = Param("sre_team", is_required=True)
44
+ translations_path_param = Param("translations_path", only_verbose=True)
45
+
46
+ builder.add_params(
47
+ [
48
+ tag_param,
49
+ repository_param,
50
+ module_param,
51
+ changelog_base_path_param,
52
+ sre_team_param,
53
+ translations_path_param,
54
+ ]
55
+ )
56
+
57
+ builder.build()
58
+
59
+ self.tag = tag_param.get_param_value()
60
+ self.module = module_param.get_param_value()
61
+ self.changelog_base_path = changelog_base_path_param.get_param_value()
62
+ self.sre_team = sre_team_param.get_param_value()
63
+ self.translations_path = translations_path_param.get_param_value()
64
+
65
+ self.jira_manager = JiraManager()
66
+
67
+ self.tag_semver = get_commit_tag_as_semver()
68
+
69
+ self.changelog_reader = ChangelogReader(
70
+ self.changelog_base_path, self.jira_manager
71
+ )
72
+
73
+ repository_name = repository_param.get_param_value()
74
+
75
+ self.repository: Repository = (
76
+ Frontend(self.tag_semver, repository_name)
77
+ if is_frontend()
78
+ else Backend(self.tag_semver, repository_name)
79
+ )
80
+
81
+ def exec(self):
82
+ """Reads the issues from a given version in changelog and creates an 'deploy issue'"""
83
+
84
+ changelog_issues = self.changelog_reader.read_issues()
85
+
86
+ if not changelog_issues:
87
+ exit_message(
88
+ f"Nenhuma task encontrada no CHANGELOG para a tag {self.tag_semver}",
89
+ )
90
+
91
+ sre_issue_type = (
92
+ "Bug"
93
+ if any(issue.fields.issuetype.name == "Bug" for issue in changelog_issues)
94
+ else "Story"
95
+ )
96
+
97
+ sre_issue = self._create_sre_issue(sre_issue_type)
98
+
99
+ success_message = (
100
+ "Task criada para o SRE: "
101
+ f"{self.jira_manager.get_issue_url(sre_issue.key)} - {sre_issue.fields.summary} ({self.tag_semver})"
102
+ )
103
+
104
+ print_message(success_message, Fore.GREEN)
105
+
106
+ for issue in changelog_issues:
107
+ if self.jira_manager.create_link(
108
+ "Dependência entre atividades", issue, sre_issue
109
+ ):
110
+ print_message(
111
+ f"Link criado: {self.jira_manager.get_issue_url(issue.key)} - {sre_issue.key}",
112
+ Fore.GREEN,
113
+ )
114
+
115
+ def _create_sre_issue(self, sre_issue_type):
116
+ jira_issue = {
117
+ "project": {"key": self.sre_team},
118
+ "summary": f"Deploy {self.repository.deployment}",
119
+ "issuetype": {"name": "Deploy"},
120
+ "labels": [sre_issue_type, self.module],
121
+ "description": self.get_description(),
122
+ self.repository.deploy_name_custom_field: [self.repository.deploy_info],
123
+ "customfield_11100": [{"value": "Produção - platform.senior.com.br"}],
124
+ }
125
+
126
+ return self.jira_manager.create_issue(jira_issue)
127
+
128
+ def get_description(self):
129
+ description = "*Changelog*\n"
130
+ description += self.changelog_reader.changelog_url
131
+ description += "\n\n"
132
+
133
+ translations_path = (
134
+ self.translations_path
135
+ if self.translations_path
136
+ else self.repository.translations_path
137
+ )
138
+ changed_files = find_changed_files(translations_path)
139
+ translations = ""
140
+ project_url = get_env_variable_required("CI_PROJECT_URL")
141
+
142
+ for translation_file in changed_files:
143
+ filename = os.path.basename(translation_file)
144
+ if filename:
145
+ translations += (
146
+ f"[{filename}|{project_url}/-/raw/{self.tag}/{translation_file}]\n"
147
+ )
148
+
149
+ if translations:
150
+ description += (
151
+ f"*Favor atualizar os arquivos de tradução:*\n{translations}\n\n"
152
+ )
153
+
154
+ description += self.create_merge_request_table()
155
+
156
+ description += f"\n[Deploy pelo SRE Platform|{self.create_sre_platform_url()}]"
157
+
158
+ return description
159
+
160
+ def create_merge_request_table(self):
161
+ table_head = (
162
+ "h2.Merge Requests\n||Título|||Validação do review|||Aberto por|||Fechado por"
163
+ "|||Pipeline|||Aberto em|||Fechado em||\n"
164
+ )
165
+ table_data = table_head
166
+ merge_requests = self.get_merges_between_tags()
167
+
168
+ for merge_request in merge_requests:
169
+ title = merge_request["title"].replace("[", "").replace("]", "")
170
+ author = capwords(merge_request["author"].replace(".", " "))
171
+ merged_by = capwords(merge_request["mergedBy"].replace(".", " "))
172
+
173
+ mr_title = f"*[{title}|{merge_request['url']}]*"
174
+ author_name = (
175
+ f"[{author}|https://git.senior.com.br/{merge_request['author']}]"
176
+ )
177
+ closed_by_name = (
178
+ f"[{merged_by}|https://git.senior.com.br/{merge_request['mergedBy']}]"
179
+ )
180
+ pipeline_status = (
181
+ "(/)" if merge_request["pipelineStatus"] == "success" else "(x)"
182
+ )
183
+ review = "(/)"
184
+
185
+ if merge_request["author"] == merge_request["mergedBy"]:
186
+ author_name += " (flag)"
187
+ closed_by_name += " (flag)"
188
+ review = "(x)"
189
+
190
+ table_row = (
191
+ f"|{mr_title}||{review}|{author_name}|{closed_by_name}|"
192
+ f"|{pipeline_status}|{merge_request['createdAt']}|{merge_request['mergedAt']}|\n"
193
+ )
194
+ table_data += table_row
195
+
196
+ table_subtitle = "~O ícone (flag) indica se o Merge Request foi aberto e fechado pela mesma pessoa.~\n"
197
+ table_data += table_subtitle
198
+
199
+ return table_data
200
+
201
+ def get_merges_between_tags(self):
202
+ query = """
203
+ query ($projectId: Int!, $referenceTag: String) {
204
+ mergesBetweenTags(projectId: $projectId, referenceTag: $referenceTag) {
205
+ mergeRequestsData {
206
+ url
207
+ title
208
+ createdAt
209
+ mergedAt
210
+ pipelineStatus
211
+ author
212
+ assignee
213
+ reviewer
214
+ mergedBy
215
+ }
216
+ }
217
+ }
218
+ """
219
+
220
+ params = {
221
+ "projectId": int(get_env_variable_required("CI_PROJECT_ID")),
222
+ "referenceTag": self.repository.version,
223
+ }
224
+
225
+ request = self.client_graphql.call(query, params)
226
+
227
+ merge_requests_data = request["mergesBetweenTags"]["mergeRequestsData"]
228
+
229
+ for merge_request_data in merge_requests_data:
230
+ merge_request_data["createdAt"] = datetime.strftime(
231
+ datetime.fromisoformat(merge_request_data["createdAt"]),
232
+ "%d/%m/%y %H:%M",
233
+ )
234
+ merge_request_data["mergedAt"] = datetime.strftime(
235
+ datetime.fromisoformat(merge_request_data["mergedAt"]), "%d/%m/%y %H:%M"
236
+ )
237
+
238
+ return merge_requests_data
239
+
240
+ def create_sre_platform_url(self):
241
+ sci_project_type = get_env_variable_required("SCI_PROJECT_TYPE")
242
+
243
+ if sci_project_type in [
244
+ "ANGULAR_SENIORX",
245
+ "ANGULAR_GENERATED",
246
+ ]:
247
+ package_json_file = open("package.json", "r", encoding="utf-8")
248
+ package_json = json.load(package_json_file)
249
+
250
+ name = package_json["project"]["app"]
251
+ domain = package_json["project"]["domain"]
252
+ service = package_json["project"]["service"]
253
+ version = get_env_variable_required("CI_COMMIT_TAG").replace("-", ".")
254
+
255
+ query_params = f"name={name}"
256
+ query_params += f"&domain={domain}"
257
+ query_params += f"&service={service}"
258
+ query_params += f"&version={version}"
259
+ query_params += "&type=FRONTEND"
260
+
261
+ else:
262
+ query_params = f"name={self.repository.deployment}"
263
+ query_params += f"&version={self.repository.version}"
264
+ query_params += f"&sreJiraKey={self.sre_team}"
265
+ query_params += "&type=BACKEND"
266
+
267
+ return f"https://sre-platform.senior.com.br/deployment?{query_params}"