Skip to content

Commit 75b942f

Browse files
committed
RUM-3100 merge verification-metadata.xml in one
1 parent 509406f commit 75b942f

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

.gitlab-ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,3 +1004,44 @@ notify:dogfood-gradle-plugin:
10041004
- pip3 install GitPython requests
10051005
- aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.gh_token --with-decryption --query "Parameter.Value" --out text >> ./gh_token
10061006
- python3 dogfood.py -v $CI_COMMIT_TAG -t gradle-plugin
1007+
1008+
notify:merge-verification-metadata:
1009+
tags: [ "arch:amd64" ]
1010+
only:
1011+
- tags
1012+
image: $CI_IMAGE_DOCKER
1013+
stage: notify
1014+
when: on_success
1015+
dependencies:
1016+
- publish:release-core
1017+
- publish:release-internal
1018+
- publish:release-trace
1019+
- publish:release-trace-otel
1020+
- publish:release-logs
1021+
- publish:release-rum
1022+
- publish:release-ndk
1023+
- publish:release-session-replay
1024+
- publish:release-session-replay-material
1025+
- publish:release-session-replay-compose
1026+
- publish:release-webview
1027+
- publish:release-coil
1028+
- publish:release-compose
1029+
- publish:release-fresco
1030+
- publish:release-glide
1031+
- publish:release-trace-coroutines
1032+
- publish:release-rum-coroutines
1033+
- publish:release-rx
1034+
- publish:release-sqldelight
1035+
- publish:release-timber
1036+
- publish:release-android-tv
1037+
- publish:release-okhttp
1038+
- publish:release-okhttp-otel
1039+
- publish:release-benchmark
1040+
script:
1041+
- python3 merge_verification_metadata.py
1042+
artifacts:
1043+
when: on_success
1044+
expire_in: 3 mos
1045+
paths:
1046+
- verification-metadata.xml
1047+

merge_verification_metadata.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
6+
# Copyright 2019-Present Datadog, Inc
7+
8+
import sys
9+
import os
10+
import glob
11+
12+
import xml.etree.ElementTree as ET
13+
import xml.dom.minidom as MD
14+
15+
from typing import List
16+
17+
18+
DEFAULT_NS = "https://schema.gradle.org/dependency-verification"
19+
NS_PREFIX = "{%s}" % DEFAULT_NS
20+
NSMAP = {None : DEFAULT_NS}
21+
22+
ROOT_TAG = (NS_PREFIX + "verification-metadata")
23+
CONFIGURATION_TAG = (NS_PREFIX + "configuration")
24+
METADATA_TAG = (NS_PREFIX + "verify-metadata")
25+
SIGNATURES_TAG = (NS_PREFIX + "verify-signatures")
26+
27+
COMPONENTS_TAG = (NS_PREFIX + "components")
28+
COMPONENT_TAG = (NS_PREFIX + "component")
29+
30+
def run_main() -> int:
31+
files = glob.glob('**/verification-metadata.xml', recursive=True)
32+
33+
# prepare final xml
34+
root = ET.Element(ROOT_TAG)
35+
configuration = ET.Element(CONFIGURATION_TAG)
36+
metadata = ET.Element(METADATA_TAG)
37+
metadata.text = "true"
38+
configuration.insert(0, metadata)
39+
signatures = ET.Element(SIGNATURES_TAG)
40+
signatures.text = "false" # TODO RUM-3104 also copy signatures content
41+
configuration.insert(1, signatures)
42+
root.insert(0, configuration)
43+
44+
components = ET.Element(COMPONENTS_TAG)
45+
root.insert(1, components)
46+
47+
index = 0
48+
for filename in files:
49+
data = ET.parse(filename).getroot()
50+
for child in data:
51+
if child.tag == COMPONENTS_TAG:
52+
for component in child:
53+
components.insert(index, component)
54+
index = index + 1
55+
56+
# remove unnecessary whitespaces in content
57+
for elem in root.iter():
58+
if elem.text is not None:
59+
elem.text = elem.text.strip()
60+
if elem.tail is not None:
61+
elem.tail = elem.tail.strip()
62+
63+
raw_xml = ET.tostring(root, method="xml").decode('utf-8')
64+
# A bug in the python etree xml api prevents writing standalone xml, so we need
65+
# to remove the default namespace:
66+
sanitized_xml = raw_xml.replace("<ns0:", "<").replace("</ns0:", "</").replace("xmlns:ns0=", "xmlns=")
67+
formatted_xml = MD.parseString(sanitized_xml).toprettyxml(indent=" ", encoding="utf-8")
68+
69+
with open("verification-metadata.xml", "w") as output_file:
70+
output_file.write(formatted_xml.decode('utf-8'))
71+
72+
return 0
73+
74+
75+
if __name__ == "__main__":
76+
sys.exit(run_main())

0 commit comments

Comments
 (0)