Created
July 16, 2021 15:31
-
-
Save TuM0xA-S/8e75f8f181cd6252f166c9c8a1c9575a to your computer and use it in GitHub Desktop.
fix proto conflict in scratch project easily
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# script to fix proto conflict panics | |
import re | |
target_variable = "GOLANG_PROTOBUF_REGISTRATION_CONFLICT" | |
def gitlabci_fixer(): | |
gitlabci_fix = \ | |
"""\ | |
# hack to fix proto conflict | |
GOLANG_PROTOBUF_REGISTRATION_CONFLICT: "warn" | |
""" | |
gitlabci_path = ".gitlab-ci.yml" | |
print(gitlabci_path) | |
gitlab_ci_file = open(gitlabci_path) | |
text = gitlab_ci_file.read() | |
gitlab_ci_file.close() | |
if text.find(target_variable) != -1: | |
return | |
fixed_text = re.sub('(?m)(?<=^variables:\n)', gitlabci_fix, text, 1) | |
gitlab_ci_file = open(gitlabci_path, 'w') | |
gitlab_ci_file.write(fixed_text) | |
gitlab_ci_file.close() | |
def values_fixer(): | |
values_files_path = ".o3/k8s/" | |
values_fix = \ | |
"""\ | |
# hack to fix proto conflict | |
- name: GOLANG_PROTOBUF_REGISTRATION_CONFLICT | |
value: "warn" | |
""" | |
values_files = [ | |
# "values.yaml", | |
"values_development.yaml", | |
"values_staging.yaml", | |
"values_production.yaml", | |
# "values_local.yaml" | |
] | |
for path in values_files: | |
path = values_files_path + path | |
print(path) | |
values_file = open(path, 'r') | |
text = values_file.read() | |
values_file.close() | |
if text.find(target_variable) != -1: | |
return | |
fixed_text = re.sub('(?m)(?<=^deploy:\n env:\n)', values_fix, text, 1) | |
values_file = open(path, 'w') | |
values_file.write(fixed_text) | |
values_file.close() | |
print("fixing...") | |
gitlabci_fixer() | |
values_fixer() | |
print("fixed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment