Skip to content

Commit a8ceba0

Browse files
vdyederrickstolee
authored andcommitted
Merge pull request #399 from vdye/feature/build-installers
Implement workflow to create GitHub release with attached `git` installers
2 parents e799bfc + 0d05ead commit a8ceba0

2 files changed

Lines changed: 709 additions & 0 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import json
2+
import os
3+
import glob
4+
import pprint
5+
import subprocess
6+
import sys
7+
8+
esrp_tool = os.path.join("esrp", "tools", "EsrpClient.exe")
9+
10+
AAD_ID = os.environ['AZURE_AAD_ID'].strip()
11+
AAD_ID_TEMP = os.environ['AZURE_AAD_ID_TEMP'].strip()
12+
WORKSPACE = os.environ['GITHUB_WORKSPACE'].strip()
13+
ARTIFACTS_DIR = os.environ['ARTIFACTS_DIR'].strip()
14+
15+
def main():
16+
source_root_location = os.path.join(WORKSPACE, ARTIFACTS_DIR, "unsigned")
17+
destination_location = os.path.join(WORKSPACE, ARTIFACTS_DIR)
18+
19+
files = glob.glob(os.path.join(source_root_location, "*.deb"))
20+
21+
print("Found files:")
22+
pprint.pp(files)
23+
24+
if len(files) < 1 or not files[0].endswith(".deb"):
25+
print("Error: cannot find .deb to sign")
26+
exit(1)
27+
28+
file_to_sign = os.path.basename(files[0])
29+
30+
auth_json = {
31+
"Version": "1.0.0",
32+
"AuthenticationType": "AAD_CERT",
33+
"TenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
34+
"ClientId": AAD_ID,
35+
"AuthCert": {
36+
"SubjectName": f"CN={AAD_ID_TEMP}.microsoft.com",
37+
"StoreLocation": "LocalMachine",
38+
"StoreName": "My",
39+
},
40+
"RequestSigningCert": {
41+
"SubjectName": f"CN={AAD_ID}",
42+
"StoreLocation": "LocalMachine",
43+
"StoreName": "My",
44+
}
45+
}
46+
47+
input_json = {
48+
"Version": "1.0.0",
49+
"SignBatches": [
50+
{
51+
"SourceLocationType": "UNC",
52+
"SourceRootDirectory": source_root_location,
53+
"DestinationLocationType": "UNC",
54+
"DestinationRootDirectory": destination_location,
55+
"SignRequestFiles": [
56+
{
57+
"CustomerCorrelationId": "01A7F55F-6CDD-4123-B255-77E6F212CDAD",
58+
"SourceLocation": file_to_sign,
59+
"DestinationLocation": os.path.join("signed", file_to_sign),
60+
}
61+
],
62+
"SigningInfo": {
63+
"Operations": [
64+
{
65+
"KeyCode": "CP-450779-Pgp",
66+
"OperationCode": "LinuxSign",
67+
"Parameters": {},
68+
"ToolName": "sign",
69+
"ToolVersion": "1.0",
70+
}
71+
]
72+
}
73+
}
74+
]
75+
}
76+
77+
policy_json = {
78+
"Version": "1.0.0",
79+
"Intent": "production release",
80+
"ContentType": "Debian package",
81+
}
82+
83+
configs = [
84+
("auth.json", auth_json),
85+
("input.json", input_json),
86+
("policy.json", policy_json),
87+
]
88+
89+
for filename, data in configs:
90+
with open(filename, 'w') as fp:
91+
json.dump(data, fp)
92+
93+
# Run ESRP Client
94+
esrp_out = "esrp_out.json"
95+
result = subprocess.run(
96+
[esrp_tool, "sign",
97+
"-a", "auth.json",
98+
"-i", "input.json",
99+
"-p", "policy.json",
100+
"-o", esrp_out,
101+
"-l", "Verbose"],
102+
cwd=WORKSPACE)
103+
104+
if result.returncode != 0:
105+
print("Failed to run ESRPClient.exe")
106+
sys.exit(1)
107+
108+
if os.path.isfile(esrp_out):
109+
print("ESRP output json:")
110+
with open(esrp_out, 'r') as fp:
111+
pprint.pp(json.load(fp))
112+
113+
signed_file = os.path.join(destination_location, "signed", file_to_sign)
114+
if os.path.isfile(signed_file):
115+
print(f"Success!\nSigned {signed_file}")
116+
117+
if __name__ == "__main__":
118+
main()

0 commit comments

Comments
 (0)