blob: dbf987e93461d79109ba0e04650560915c6525eb [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
Ilya Shipitsin0c6410f2023-07-15 00:00:48 +020024#
25# this CI is used for both development and stable branches of HAProxy
26#
27# naming convention used, if branch name matches:
28#
29# "haproxy-" - stable branches
30# otherwise - development branch (i.e. "latest" ssl variants, "latest" github images)
31#
Tim Duesterhus3c9b6f62022-12-29 17:40:24 +010032print("Generating matrix for branch '{}'.".format(ref_name))
Tim Duesterhus288c0772020-07-28 23:00:35 +020033
Tim Duesterhus08109112022-12-29 17:40:29 +010034
Tim Duesterhus288c0772020-07-28 23:00:35 +020035def clean_ssl(ssl):
36 return ssl.replace("_VERSION", "").lower()
37
Tim Duesterhus08109112022-12-29 17:40:29 +010038
Tim Duesterhusfcc21be2022-12-29 17:40:25 +010039@functools.lru_cache(5)
Ilya Shipitsin7b893c22022-05-20 23:02:38 +050040def determine_latest_openssl(ssl):
Tim Duesterhusfd7931e2022-12-29 17:40:26 +010041 headers = {}
Tim Duesterhus08109112022-12-29 17:40:29 +010042 if environ.get("GITHUB_TOKEN") is not None:
43 headers["Authorization"] = "token {}".format(environ.get("GITHUB_TOKEN"))
Tim Duesterhus08109112022-12-29 17:40:29 +010044 request = urllib.request.Request(
45 "https://api.github.com/repos/openssl/openssl/tags", headers=headers
46 )
Ilya Shipitsined79a272023-04-26 20:39:39 +020047 try:
48 openssl_tags = urllib.request.urlopen(request)
49 except:
50 return "OPENSSL_VERSION=failed_to_detect"
Tim Duesterhus08109112022-12-29 17:40:29 +010051 tags = json.loads(openssl_tags.read().decode("utf-8"))
52 latest_tag = ""
Ilya Shipitsin7b893c22022-05-20 23:02:38 +050053 for tag in tags:
Tim Duesterhus08109112022-12-29 17:40:29 +010054 name = tag["name"]
Ilya Shipitsin7b893c22022-05-20 23:02:38 +050055 if "openssl-" in name:
56 if name > latest_tag:
Tim Duesterhus08109112022-12-29 17:40:29 +010057 latest_tag = name
Ilya Shipitsin14711bd2022-10-11 12:10:57 +050058 return "OPENSSL_VERSION={}".format(latest_tag[8:])
Ilya Shipitsin7b893c22022-05-20 23:02:38 +050059
Tim Duesterhus08109112022-12-29 17:40:29 +010060
Tim Duesterhusfcc21be2022-12-29 17:40:25 +010061@functools.lru_cache(5)
Ilya Shipitsin94cd7792022-05-13 21:59:38 +050062def determine_latest_libressl(ssl):
Ilya Shipitsined79a272023-04-26 20:39:39 +020063 try:
64 libressl_download_list = urllib.request.urlopen(
65 "https://cdn.openbsd.org/pub/OpenBSD/LibreSSL/"
66 )
67 except:
68 return "LIBRESSL_VERSION=failed_to_detect"
Ilya Shipitsin94cd7792022-05-13 21:59:38 +050069 for line in libressl_download_list.readlines():
70 decoded_line = line.decode("utf-8")
71 if "libressl-" in decoded_line and ".tar.gz.asc" in decoded_line:
Tim Duesterhus08109112022-12-29 17:40:29 +010072 l = re.split("libressl-|.tar.gz.asc", decoded_line)[1]
Ilya Shipitsin14711bd2022-10-11 12:10:57 +050073 return "LIBRESSL_VERSION={}".format(l)
Tim Duesterhus288c0772020-07-28 23:00:35 +020074
Tim Duesterhus08109112022-12-29 17:40:29 +010075
Tim Duesterhus288c0772020-07-28 23:00:35 +020076def clean_compression(compression):
77 return compression.replace("USE_", "").lower()
78
79
80def get_asan_flags(cc):
Ilya Shipitsincfba1f92022-07-02 10:30:28 +050081 return [
82 "USE_OBSOLETE_LINKER=1",
83 'DEBUG_CFLAGS="-g -fsanitize=address"',
84 'LDFLAGS="-fsanitize=address"',
85 'CPU_CFLAGS.generic="-O1"',
86 ]
Tim Duesterhus288c0772020-07-28 23:00:35 +020087
Tim Duesterhus288c0772020-07-28 23:00:35 +020088
89matrix = []
90
91# Ubuntu
92
Tim Duesterhusfd7931e2022-12-29 17:40:26 +010093if "haproxy-" in ref_name:
Ilya Shipitsin0c6410f2023-07-15 00:00:48 +020094 os = "ubuntu-22.04" # stable branch
Tim Duesterhusfd7931e2022-12-29 17:40:26 +010095else:
Ilya Shipitsin0c6410f2023-07-15 00:00:48 +020096 os = "ubuntu-latest" # development branch
Tim Duesterhusfd7931e2022-12-29 17:40:26 +010097
Tim Duesterhus288c0772020-07-28 23:00:35 +020098TARGET = "linux-glibc"
99for CC in ["gcc", "clang"]:
100 matrix.append(
101 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500102 "name": "{}, {}, no features".format(os, CC),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200103 "os": os,
104 "TARGET": TARGET,
105 "CC": CC,
106 "FLAGS": [],
107 }
108 )
109
110 matrix.append(
111 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500112 "name": "{}, {}, all features".format(os, CC),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200113 "os": os,
114 "TARGET": TARGET,
115 "CC": CC,
116 "FLAGS": [
117 "USE_ZLIB=1",
Willy Tarreaued17ca72021-09-12 07:01:36 +0200118 "USE_OT=1",
Ilya Shipitsinb9e3fb72022-01-13 11:36:28 +0500119 "OT_INC=${HOME}/opt-ot/include",
120 "OT_LIB=${HOME}/opt-ot/lib",
Ilya Shipitsin75c95aa2021-05-18 09:46:43 +0000121 "OT_RUNPATH=1",
Tim Duesterhus288c0772020-07-28 23:00:35 +0200122 "USE_PCRE=1",
123 "USE_PCRE_JIT=1",
124 "USE_LUA=1",
125 "USE_OPENSSL=1",
126 "USE_SYSTEMD=1",
127 "USE_WURFL=1",
Willy Tarreau57610c62021-04-02 16:39:44 +0200128 "WURFL_INC=addons/wurfl/dummy",
129 "WURFL_LIB=addons/wurfl/dummy",
Tim Duesterhus288c0772020-07-28 23:00:35 +0200130 "USE_DEVICEATLAS=1",
Willy Tarreauf8d9ec52021-04-02 16:19:39 +0200131 "DEVICEATLAS_SRC=addons/deviceatlas/dummy",
Willy Tarreau3dfadc72021-04-02 15:35:19 +0200132 "USE_PROMEX=1",
Ilya Shipitsinb34aee82020-11-26 20:59:42 +0500133 "USE_51DEGREES=1",
Willy Tarreau977209d2021-04-02 16:12:32 +0200134 "51DEGREES_SRC=addons/51degrees/dummy/pattern",
Tim Duesterhus288c0772020-07-28 23:00:35 +0200135 ],
136 }
137 )
138
Tim Duesterhus08109112022-12-29 17:40:29 +0100139 # ASAN
Ilya Shipitsin6dedeb72022-12-14 18:18:20 +0500140
141 matrix.append(
142 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500143 "name": "{}, {}, ASAN, all features".format(os, CC),
Ilya Shipitsin6dedeb72022-12-14 18:18:20 +0500144 "os": os,
145 "TARGET": TARGET,
146 "CC": CC,
147 "FLAGS": get_asan_flags(CC)
148 + [
149 "USE_ZLIB=1",
150 "USE_OT=1",
151 "OT_INC=${HOME}/opt-ot/include",
152 "OT_LIB=${HOME}/opt-ot/lib",
153 "OT_RUNPATH=1",
154 "USE_PCRE=1",
155 "USE_PCRE_JIT=1",
156 "USE_LUA=1",
157 "USE_OPENSSL=1",
158 "USE_SYSTEMD=1",
159 "USE_WURFL=1",
160 "WURFL_INC=addons/wurfl/dummy",
161 "WURFL_LIB=addons/wurfl/dummy",
162 "USE_DEVICEATLAS=1",
163 "DEVICEATLAS_SRC=addons/deviceatlas/dummy",
164 "USE_PROMEX=1",
165 "USE_51DEGREES=1",
166 "51DEGREES_SRC=addons/51degrees/dummy/pattern",
167 ],
168 }
169 )
170
Tim Duesterhus762b1fd2021-08-14 14:36:55 +0200171 for compression in ["USE_ZLIB=1"]:
Tim Duesterhus288c0772020-07-28 23:00:35 +0200172 matrix.append(
173 {
Tim Duesterhus08109112022-12-29 17:40:29 +0100174 "name": "{}, {}, gz={}".format(os, CC, clean_compression(compression)),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200175 "os": os,
176 "TARGET": TARGET,
177 "CC": CC,
178 "FLAGS": [compression],
179 }
180 )
181
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100182 ssl_versions = [
Tim Duesterhus288c0772020-07-28 23:00:35 +0200183 "stock",
184 "OPENSSL_VERSION=1.0.2u",
William Lallemand393e4e42022-12-12 08:52:03 +0100185 "OPENSSL_VERSION=1.1.1s",
Ilya Shipitsind69d65a2021-11-18 18:27:57 +0500186 "QUICTLS=yes",
Tim Duesterhus08109112022-12-29 17:40:29 +0100187 # "BORINGSSL=yes",
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100188 ]
189
Ilya Shipitsin0c6410f2023-07-15 00:00:48 +0200190 if "haproxy-" not in ref_name: # development branch
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100191 ssl_versions = ssl_versions + [
192 "OPENSSL_VERSION=latest",
193 "LIBRESSL_VERSION=latest",
194 ]
195
196 for ssl in ssl_versions:
Tim Duesterhus288c0772020-07-28 23:00:35 +0200197 flags = ["USE_OPENSSL=1"]
Ilya Shipitsin6397c7c2022-11-02 11:59:37 +0500198 if ssl == "BORINGSSL=yes" or ssl == "QUICTLS=yes" or "LIBRESSL" in ssl:
Ilya Shipitsin714f28c2021-05-09 21:27:28 +0500199 flags.append("USE_QUIC=1")
Tim Duesterhus288c0772020-07-28 23:00:35 +0200200 if ssl != "stock":
201 flags.append("SSL_LIB=${HOME}/opt/lib")
202 flags.append("SSL_INC=${HOME}/opt/include")
Ilya Shipitsin94cd7792022-05-13 21:59:38 +0500203 if "LIBRESSL" in ssl and "latest" in ssl:
204 ssl = determine_latest_libressl(ssl)
Ilya Shipitsin7b893c22022-05-20 23:02:38 +0500205 if "OPENSSL" in ssl and "latest" in ssl:
206 ssl = determine_latest_openssl(ssl)
207
Tim Duesterhus288c0772020-07-28 23:00:35 +0200208 matrix.append(
209 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500210 "name": "{}, {}, ssl={}".format(os, CC, clean_ssl(ssl)),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200211 "os": os,
212 "TARGET": TARGET,
213 "CC": CC,
214 "ssl": ssl,
215 "FLAGS": flags,
216 }
217 )
218
Tim Duesterhus288c0772020-07-28 23:00:35 +0200219# macOS
220
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100221if "haproxy-" in ref_name:
Ilya Shipitsin0c6410f2023-07-15 00:00:48 +0200222 os = "macos-12" # stable branch
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100223else:
Ilya Shipitsin0c6410f2023-07-15 00:00:48 +0200224 os = "macos-latest" # development branch
Tim Duesterhusfd7931e2022-12-29 17:40:26 +0100225
Tim Duesterhus288c0772020-07-28 23:00:35 +0200226TARGET = "osx"
227for CC in ["clang"]:
228 matrix.append(
229 {
Ilya Shipitsinf5994fc2022-12-14 18:23:24 +0500230 "name": "{}, {}, no features".format(os, CC),
Tim Duesterhus288c0772020-07-28 23:00:35 +0200231 "os": os,
232 "TARGET": TARGET,
233 "CC": CC,
234 "FLAGS": [],
235 }
236 )
237
238# Print matrix
239
240print(json.dumps(matrix, indent=4, sort_keys=True))
241
Tim Duesterhus08109112022-12-29 17:40:29 +0100242if environ.get("GITHUB_OUTPUT") is not None:
243 with open(environ.get("GITHUB_OUTPUT"), "a") as f:
Tim Duesterhus8a03bf42022-10-14 19:46:06 +0200244 print("matrix={}".format(json.dumps({"include": matrix})), file=f)