blob: 7f22c43bb20a56c67abee699b399229dc79cb7ea [file] [log] [blame]
Tim Duesterhus871ef2f2021-06-08 15:14:35 +02001#!/usr/bin/python3
2
Tim Duesterhus288c0772020-07-28 23:00:35 +02003# Copyright 2019 Ilya Shipitsin <chipitsine@gmail.com>
4# Copyright 2020 Tim Duesterhus <tim@bastelstu.be>
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License
8# as published by the Free Software Foundation; either version
9# 2 of the License, or (at your option) any later version.
10
Tim Duesterhusfcc21be2022-12-29 17:40:25 +010011import functools
Tim Duesterhus288c0772020-07-28 23:00:35 +020012import json
Tim Duesterhus08109112022-12-29 17:40:29 +010013import re
Tim Duesterhus8d173e12020-11-20 00:16:00 +010014import sys
Ilya Shipitsin94cd7792022-05-13 21:59:38 +050015import urllib.request
Tim Duesterhus8a03bf42022-10-14 19:46:06 +020016from os import environ
Tim Duesterhus8d173e12020-11-20 00:16:00 +010017
18if len(sys.argv) == 2:
Ilya Shipitsin4a04cd32022-12-12 19:15:22 +050019 ref_name = sys.argv[1]
Tim Duesterhus8d173e12020-11-20 00:16:00 +010020else:
Ilya Shipitsin4a04cd32022-12-12 19:15:22 +050021 print("Usage: {} <ref_name>".format(sys.argv[0]), file=sys.stderr)
Tim Duesterhus8d173e12020-11-20 00:16:00 +010022 sys.exit(1)
23
Tim Duesterhus3c9b6f62022-12-29 17:40:24 +010024print("Generating matrix for branch '{}'.".format(ref_name))
Tim Duesterhus288c0772020-07-28 23:00:35 +020025
Tim Duesterhus08109112022-12-29 17:40:29 +010026
Tim Duesterhus288c0772020-07-28 23:00:35 +020027def clean_ssl(ssl):
28 return ssl.replace("_VERSION", "").lower()
29
Tim Duesterhus08109112022-12-29 17:40:29 +010030
Tim Duesterhusfcc21be2022-12-29 17:40:25 +010031@functools.lru_cache(5)
Ilya Shipitsin7b893c22022-05-20 23:02:38 +050032def determine_latest_openssl(ssl):
Tim Duesterhusfd7931e2022-12-29 17:40:26 +010033 headers = {}
Tim Duesterhus08109112022-12-29 17:40:29 +010034 if environ.get("GITHUB_TOKEN") is not None:
35 headers["Authorization"] = "token {}".format(environ.get("GITHUB_TOKEN"))
Tim Duesterhus08109112022-12-29 17:40:29 +010036 request = urllib.request.Request(
37 "https://api.github.com/repos/openssl/openssl/tags", headers=headers
38 )
Ilya Shipitsined79a272023-04-26 20:39:39 +020039 try:
40 openssl_tags = urllib.request.urlopen(request)
41 except:
42 return "OPENSSL_VERSION=failed_to_detect"
Tim Duesterhus08109112022-12-29 17:40:29 +010043 tags = json.loads(openssl_tags.read().decode("utf-8"))
44 latest_tag = ""
Ilya Shipitsin7b893c22022-05-20 23:02:38 +050045 for tag in tags:
Tim Duesterhus08109112022-12-29 17:40:29 +010046 name = tag["name"]
Ilya Shipitsin7b893c22022-05-20 23:02:38 +050047 if "openssl-" in name:
48 if name > latest_tag:
Tim Duesterhus08109112022-12-29 17:40:29 +010049 latest_tag = name
Ilya Shipitsin14711bd2022-10-11 12:10:57 +050050 return "OPENSSL_VERSION={}".format(latest_tag[8:])
Ilya Shipitsin7b893c22022-05-20 23:02:38 +050051
Tim Duesterhus08109112022-12-29 17:40:29 +010052
Tim Duesterhusfcc21be2022-12-29 17:40:25 +010053@functools.lru_cache(5)
Ilya Shipitsin94cd7792022-05-13 21:59:38 +050054def determine_latest_libressl(ssl):
Ilya Shipitsined79a272023-04-26 20:39:39 +020055 try:
56 libressl_download_list = urllib.request.urlopen(
57 "https://cdn.openbsd.org/pub/OpenBSD/LibreSSL/"
58 )
59 except:
60 return "LIBRESSL_VERSION=failed_to_detect"
Ilya Shipitsin94cd7792022-05-13 21:59:38 +050061 for line in libressl_download_list.readlines():
62 decoded_line = line.decode("utf-8")
63 if "libressl-" in decoded_line and ".tar.gz.asc" in decoded_line:
Tim Duesterhus08109112022-12-29 17:40:29 +010064 l = re.split("libressl-|.tar.gz.asc", decoded_line)[1]
Ilya Shipitsin14711bd2022-10-11 12:10:57 +050065 return "LIBRESSL_VERSION={}".format(l)
Tim Duesterhus288c0772020-07-28 23:00:35 +020066
Tim Duesterhus08109112022-12-29 17:40:29 +010067
Tim Duesterhus288c0772020-07-28 23:00:35 +020068def clean_compression(compression):
69 return compression.replace("USE_", "").lower()
70
71
72def get_asan_flags(cc):
Ilya Shipitsincfba1f92022-07-02 10:30:28 +050073 return [
74 "USE_OBSOLETE_LINKER=1",
75 'DEBUG_CFLAGS="-g -fsanitize=address"',
76 'LDFLAGS="-fsanitize=address"',
77 'CPU_CFLAGS.generic="-O1"',
78 ]
Tim Duesterhus288c0772020-07-28 23:00:35 +020079
Tim Duesterhus288c0772020-07-28 23:00:35 +020080
81matrix = []
82
83# Ubuntu
84
Tim Duesterhusfd7931e2022-12-29 17:40:26 +010085if "haproxy-" in ref_name:
86 os = "ubuntu-22.04"
87else:
88 os = "ubuntu-latest"
89
Tim Duesterhus288c0772020-07-28 23:00:35 +020090TARGET = "linux-glibc"
91for CC in ["gcc", "clang"]:
92 matrix.append(
93 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +050094 "name": "{}, {}, no features".format(os, CC),
Tim Duesterhus288c0772020-07-28 23:00:35 +020095 "os": os,
96 "TARGET": TARGET,
97 "CC": CC,
98 "FLAGS": [],
99 }
100 )
101
102 matrix.append(
103 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500104 "name": "{}, {}, all features".format(os, CC),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200105 "os": os,
106 "TARGET": TARGET,
107 "CC": CC,
108 "FLAGS": [
109 "USE_ZLIB=1",
Willy Tarreaued17ca72021-09-12 07:01:36 +0200110 "USE_OT=1",
Ilya Shipitsinb9e3fb72022-01-13 11:36:28 +0500111 "OT_INC=${HOME}/opt-ot/include",
112 "OT_LIB=${HOME}/opt-ot/lib",
Ilya Shipitsin75c95aa2021-05-18 09:46:43 +0000113 "OT_RUNPATH=1",
Tim Duesterhus288c0772020-07-28 23:00:35 +0200114 "USE_PCRE=1",
115 "USE_PCRE_JIT=1",
116 "USE_LUA=1",
117 "USE_OPENSSL=1",
118 "USE_SYSTEMD=1",
119 "USE_WURFL=1",
Willy Tarreau57610c62021-04-02 16:39:44 +0200120 "WURFL_INC=addons/wurfl/dummy",
121 "WURFL_LIB=addons/wurfl/dummy",
Tim Duesterhus288c0772020-07-28 23:00:35 +0200122 "USE_DEVICEATLAS=1",
Willy Tarreauf8d9ec52021-04-02 16:19:39 +0200123 "DEVICEATLAS_SRC=addons/deviceatlas/dummy",
Willy Tarreau3dfadc72021-04-02 15:35:19 +0200124 "USE_PROMEX=1",
Ilya Shipitsinb34aee82020-11-26 20:59:42 +0500125 "USE_51DEGREES=1",
Willy Tarreau977209d2021-04-02 16:12:32 +0200126 "51DEGREES_SRC=addons/51degrees/dummy/pattern",
Tim Duesterhus288c0772020-07-28 23:00:35 +0200127 ],
128 }
129 )
130
Tim Duesterhus08109112022-12-29 17:40:29 +0100131 # ASAN
Ilya Shipitsin6dedeb72022-12-14 18:18:20 +0500132
133 matrix.append(
134 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500135 "name": "{}, {}, ASAN, all features".format(os, CC),
Ilya Shipitsin6dedeb72022-12-14 18:18:20 +0500136 "os": os,
137 "TARGET": TARGET,
138 "CC": CC,
139 "FLAGS": get_asan_flags(CC)
140 + [
141 "USE_ZLIB=1",
142 "USE_OT=1",
143 "OT_INC=${HOME}/opt-ot/include",
144 "OT_LIB=${HOME}/opt-ot/lib",
145 "OT_RUNPATH=1",
146 "USE_PCRE=1",
147 "USE_PCRE_JIT=1",
148 "USE_LUA=1",
149 "USE_OPENSSL=1",
150 "USE_SYSTEMD=1",
151 "USE_WURFL=1",
152 "WURFL_INC=addons/wurfl/dummy",
153 "WURFL_LIB=addons/wurfl/dummy",
154 "USE_DEVICEATLAS=1",
155 "DEVICEATLAS_SRC=addons/deviceatlas/dummy",
156 "USE_PROMEX=1",
157 "USE_51DEGREES=1",
158 "51DEGREES_SRC=addons/51degrees/dummy/pattern",
159 ],
160 }
161 )
162
Tim Duesterhus762b1fd2021-08-14 14:36:55 +0200163 for compression in ["USE_ZLIB=1"]:
Tim Duesterhus288c0772020-07-28 23:00:35 +0200164 matrix.append(
165 {
Tim Duesterhus08109112022-12-29 17:40:29 +0100166 "name": "{}, {}, gz={}".format(os, CC, clean_compression(compression)),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200167 "os": os,
168 "TARGET": TARGET,
169 "CC": CC,
170 "FLAGS": [compression],
171 }
172 )
173
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100174 ssl_versions = [
Tim Duesterhus288c0772020-07-28 23:00:35 +0200175 "stock",
176 "OPENSSL_VERSION=1.0.2u",
William Lallemand393e4e42022-12-12 08:52:03 +0100177 "OPENSSL_VERSION=1.1.1s",
Ilya Shipitsind69d65a2021-11-18 18:27:57 +0500178 "QUICTLS=yes",
Tim Duesterhus08109112022-12-29 17:40:29 +0100179 # "BORINGSSL=yes",
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100180 ]
181
182 if "haproxy-" not in ref_name:
183 ssl_versions = ssl_versions + [
184 "OPENSSL_VERSION=latest",
185 "LIBRESSL_VERSION=latest",
186 ]
187
188 for ssl in ssl_versions:
Tim Duesterhus288c0772020-07-28 23:00:35 +0200189 flags = ["USE_OPENSSL=1"]
Ilya Shipitsin6397c7c2022-11-02 11:59:37 +0500190 if ssl == "BORINGSSL=yes" or ssl == "QUICTLS=yes" or "LIBRESSL" in ssl:
Ilya Shipitsin714f28c2021-05-09 21:27:28 +0500191 flags.append("USE_QUIC=1")
Tim Duesterhus288c0772020-07-28 23:00:35 +0200192 if ssl != "stock":
193 flags.append("SSL_LIB=${HOME}/opt/lib")
194 flags.append("SSL_INC=${HOME}/opt/include")
Ilya Shipitsin94cd7792022-05-13 21:59:38 +0500195 if "LIBRESSL" in ssl and "latest" in ssl:
196 ssl = determine_latest_libressl(ssl)
Ilya Shipitsin7b893c22022-05-20 23:02:38 +0500197 if "OPENSSL" in ssl and "latest" in ssl:
198 ssl = determine_latest_openssl(ssl)
199
Tim Duesterhus288c0772020-07-28 23:00:35 +0200200 matrix.append(
201 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500202 "name": "{}, {}, ssl={}".format(os, CC, clean_ssl(ssl)),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200203 "os": os,
204 "TARGET": TARGET,
205 "CC": CC,
206 "ssl": ssl,
207 "FLAGS": flags,
208 }
209 )
210
Tim Duesterhus288c0772020-07-28 23:00:35 +0200211# macOS
212
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100213if "haproxy-" in ref_name:
214 os = "macos-12"
215else:
216 os = "macos-latest"
217
Tim Duesterhus288c0772020-07-28 23:00:35 +0200218TARGET = "osx"
219for CC in ["clang"]:
220 matrix.append(
221 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500222 "name": "{}, {}, no features".format(os, CC),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200223 "os": os,
224 "TARGET": TARGET,
225 "CC": CC,
226 "FLAGS": [],
227 }
228 )
229
230# Print matrix
231
232print(json.dumps(matrix, indent=4, sort_keys=True))
233
Tim Duesterhus08109112022-12-29 17:40:29 +0100234if environ.get("GITHUB_OUTPUT") is not None:
235 with open(environ.get("GITHUB_OUTPUT"), "a") as f:
Tim Duesterhus8a03bf42022-10-14 19:46:06 +0200236 print("matrix={}".format(json.dumps({"include": matrix})), file=f)