Tim Duesterhus | 871ef2f | 2021-06-08 15:14:35 +0200 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 3 | # 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 Duesterhus | fcc21be | 2022-12-29 17:40:25 +0100 | [diff] [blame] | 11 | import functools |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 12 | import json |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 13 | import re |
Tim Duesterhus | 8d173e1 | 2020-11-20 00:16:00 +0100 | [diff] [blame] | 14 | import sys |
Ilya Shipitsin | 94cd779 | 2022-05-13 21:59:38 +0500 | [diff] [blame] | 15 | import urllib.request |
Tim Duesterhus | 8a03bf4 | 2022-10-14 19:46:06 +0200 | [diff] [blame] | 16 | from os import environ |
Tim Duesterhus | 8d173e1 | 2020-11-20 00:16:00 +0100 | [diff] [blame] | 17 | |
| 18 | if len(sys.argv) == 2: |
Ilya Shipitsin | 4a04cd3 | 2022-12-12 19:15:22 +0500 | [diff] [blame] | 19 | ref_name = sys.argv[1] |
Tim Duesterhus | 8d173e1 | 2020-11-20 00:16:00 +0100 | [diff] [blame] | 20 | else: |
Ilya Shipitsin | 4a04cd3 | 2022-12-12 19:15:22 +0500 | [diff] [blame] | 21 | print("Usage: {} <ref_name>".format(sys.argv[0]), file=sys.stderr) |
Tim Duesterhus | 8d173e1 | 2020-11-20 00:16:00 +0100 | [diff] [blame] | 22 | sys.exit(1) |
| 23 | |
Tim Duesterhus | 3c9b6f6 | 2022-12-29 17:40:24 +0100 | [diff] [blame] | 24 | print("Generating matrix for branch '{}'.".format(ref_name)) |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 25 | |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 26 | |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 27 | def clean_ssl(ssl): |
| 28 | return ssl.replace("_VERSION", "").lower() |
| 29 | |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 30 | |
Tim Duesterhus | fcc21be | 2022-12-29 17:40:25 +0100 | [diff] [blame] | 31 | @functools.lru_cache(5) |
Ilya Shipitsin | 7b893c2 | 2022-05-20 23:02:38 +0500 | [diff] [blame] | 32 | def determine_latest_openssl(ssl): |
Tim Duesterhus | fd7931e | 2022-12-29 17:40:26 +0100 | [diff] [blame] | 33 | headers = {} |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 34 | if environ.get("GITHUB_TOKEN") is not None: |
| 35 | headers["Authorization"] = "token {}".format(environ.get("GITHUB_TOKEN")) |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 36 | request = urllib.request.Request( |
| 37 | "https://api.github.com/repos/openssl/openssl/tags", headers=headers |
| 38 | ) |
Ilya Shipitsin | ed79a27 | 2023-04-26 20:39:39 +0200 | [diff] [blame] | 39 | try: |
| 40 | openssl_tags = urllib.request.urlopen(request) |
| 41 | except: |
| 42 | return "OPENSSL_VERSION=failed_to_detect" |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 43 | tags = json.loads(openssl_tags.read().decode("utf-8")) |
| 44 | latest_tag = "" |
Ilya Shipitsin | 7b893c2 | 2022-05-20 23:02:38 +0500 | [diff] [blame] | 45 | for tag in tags: |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 46 | name = tag["name"] |
Ilya Shipitsin | 7b893c2 | 2022-05-20 23:02:38 +0500 | [diff] [blame] | 47 | if "openssl-" in name: |
| 48 | if name > latest_tag: |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 49 | latest_tag = name |
Ilya Shipitsin | 14711bd | 2022-10-11 12:10:57 +0500 | [diff] [blame] | 50 | return "OPENSSL_VERSION={}".format(latest_tag[8:]) |
Ilya Shipitsin | 7b893c2 | 2022-05-20 23:02:38 +0500 | [diff] [blame] | 51 | |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 52 | |
Tim Duesterhus | fcc21be | 2022-12-29 17:40:25 +0100 | [diff] [blame] | 53 | @functools.lru_cache(5) |
Ilya Shipitsin | 94cd779 | 2022-05-13 21:59:38 +0500 | [diff] [blame] | 54 | def determine_latest_libressl(ssl): |
Ilya Shipitsin | ed79a27 | 2023-04-26 20:39:39 +0200 | [diff] [blame] | 55 | 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 Shipitsin | 94cd779 | 2022-05-13 21:59:38 +0500 | [diff] [blame] | 61 | 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 Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 64 | l = re.split("libressl-|.tar.gz.asc", decoded_line)[1] |
Ilya Shipitsin | 14711bd | 2022-10-11 12:10:57 +0500 | [diff] [blame] | 65 | return "LIBRESSL_VERSION={}".format(l) |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 66 | |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 67 | |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 68 | def clean_compression(compression): |
| 69 | return compression.replace("USE_", "").lower() |
| 70 | |
| 71 | |
| 72 | def get_asan_flags(cc): |
Ilya Shipitsin | cfba1f9 | 2022-07-02 10:30:28 +0500 | [diff] [blame] | 73 | return [ |
| 74 | "USE_OBSOLETE_LINKER=1", |
| 75 | 'DEBUG_CFLAGS="-g -fsanitize=address"', |
| 76 | 'LDFLAGS="-fsanitize=address"', |
| 77 | 'CPU_CFLAGS.generic="-O1"', |
| 78 | ] |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 79 | |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 80 | |
| 81 | matrix = [] |
| 82 | |
| 83 | # Ubuntu |
| 84 | |
Tim Duesterhus | fd7931e | 2022-12-29 17:40:26 +0100 | [diff] [blame] | 85 | if "haproxy-" in ref_name: |
| 86 | os = "ubuntu-22.04" |
| 87 | else: |
| 88 | os = "ubuntu-latest" |
| 89 | |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 90 | TARGET = "linux-glibc" |
| 91 | for CC in ["gcc", "clang"]: |
| 92 | matrix.append( |
| 93 | { |
Ilya Shipitsin | f5994fc | 2022-12-14 18:23:24 +0500 | [diff] [blame] | 94 | "name": "{}, {}, no features".format(os, CC), |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 95 | "os": os, |
| 96 | "TARGET": TARGET, |
| 97 | "CC": CC, |
| 98 | "FLAGS": [], |
| 99 | } |
| 100 | ) |
| 101 | |
| 102 | matrix.append( |
| 103 | { |
Ilya Shipitsin | f5994fc | 2022-12-14 18:23:24 +0500 | [diff] [blame] | 104 | "name": "{}, {}, all features".format(os, CC), |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 105 | "os": os, |
| 106 | "TARGET": TARGET, |
| 107 | "CC": CC, |
| 108 | "FLAGS": [ |
| 109 | "USE_ZLIB=1", |
Willy Tarreau | ed17ca7 | 2021-09-12 07:01:36 +0200 | [diff] [blame] | 110 | "USE_OT=1", |
Ilya Shipitsin | b9e3fb7 | 2022-01-13 11:36:28 +0500 | [diff] [blame] | 111 | "OT_INC=${HOME}/opt-ot/include", |
| 112 | "OT_LIB=${HOME}/opt-ot/lib", |
Ilya Shipitsin | 75c95aa | 2021-05-18 09:46:43 +0000 | [diff] [blame] | 113 | "OT_RUNPATH=1", |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 114 | "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 Tarreau | 57610c6 | 2021-04-02 16:39:44 +0200 | [diff] [blame] | 120 | "WURFL_INC=addons/wurfl/dummy", |
| 121 | "WURFL_LIB=addons/wurfl/dummy", |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 122 | "USE_DEVICEATLAS=1", |
Willy Tarreau | f8d9ec5 | 2021-04-02 16:19:39 +0200 | [diff] [blame] | 123 | "DEVICEATLAS_SRC=addons/deviceatlas/dummy", |
Willy Tarreau | 3dfadc7 | 2021-04-02 15:35:19 +0200 | [diff] [blame] | 124 | "USE_PROMEX=1", |
Ilya Shipitsin | b34aee8 | 2020-11-26 20:59:42 +0500 | [diff] [blame] | 125 | "USE_51DEGREES=1", |
Willy Tarreau | 977209d | 2021-04-02 16:12:32 +0200 | [diff] [blame] | 126 | "51DEGREES_SRC=addons/51degrees/dummy/pattern", |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 127 | ], |
| 128 | } |
| 129 | ) |
| 130 | |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 131 | # ASAN |
Ilya Shipitsin | 6dedeb7 | 2022-12-14 18:18:20 +0500 | [diff] [blame] | 132 | |
| 133 | matrix.append( |
| 134 | { |
Ilya Shipitsin | f5994fc | 2022-12-14 18:23:24 +0500 | [diff] [blame] | 135 | "name": "{}, {}, ASAN, all features".format(os, CC), |
Ilya Shipitsin | 6dedeb7 | 2022-12-14 18:18:20 +0500 | [diff] [blame] | 136 | "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 Duesterhus | 762b1fd | 2021-08-14 14:36:55 +0200 | [diff] [blame] | 163 | for compression in ["USE_ZLIB=1"]: |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 164 | matrix.append( |
| 165 | { |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 166 | "name": "{}, {}, gz={}".format(os, CC, clean_compression(compression)), |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 167 | "os": os, |
| 168 | "TARGET": TARGET, |
| 169 | "CC": CC, |
| 170 | "FLAGS": [compression], |
| 171 | } |
| 172 | ) |
| 173 | |
Tim Duesterhus | fd7931e | 2022-12-29 17:40:26 +0100 | [diff] [blame] | 174 | ssl_versions = [ |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 175 | "stock", |
| 176 | "OPENSSL_VERSION=1.0.2u", |
William Lallemand | 393e4e4 | 2022-12-12 08:52:03 +0100 | [diff] [blame] | 177 | "OPENSSL_VERSION=1.1.1s", |
Ilya Shipitsin | d69d65a | 2021-11-18 18:27:57 +0500 | [diff] [blame] | 178 | "QUICTLS=yes", |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 179 | # "BORINGSSL=yes", |
Tim Duesterhus | fd7931e | 2022-12-29 17:40:26 +0100 | [diff] [blame] | 180 | ] |
| 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 Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 189 | flags = ["USE_OPENSSL=1"] |
Ilya Shipitsin | 6397c7c | 2022-11-02 11:59:37 +0500 | [diff] [blame] | 190 | if ssl == "BORINGSSL=yes" or ssl == "QUICTLS=yes" or "LIBRESSL" in ssl: |
Ilya Shipitsin | 714f28c | 2021-05-09 21:27:28 +0500 | [diff] [blame] | 191 | flags.append("USE_QUIC=1") |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 192 | if ssl != "stock": |
| 193 | flags.append("SSL_LIB=${HOME}/opt/lib") |
| 194 | flags.append("SSL_INC=${HOME}/opt/include") |
Ilya Shipitsin | 94cd779 | 2022-05-13 21:59:38 +0500 | [diff] [blame] | 195 | if "LIBRESSL" in ssl and "latest" in ssl: |
| 196 | ssl = determine_latest_libressl(ssl) |
Ilya Shipitsin | 7b893c2 | 2022-05-20 23:02:38 +0500 | [diff] [blame] | 197 | if "OPENSSL" in ssl and "latest" in ssl: |
| 198 | ssl = determine_latest_openssl(ssl) |
| 199 | |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 200 | matrix.append( |
| 201 | { |
Ilya Shipitsin | f5994fc | 2022-12-14 18:23:24 +0500 | [diff] [blame] | 202 | "name": "{}, {}, ssl={}".format(os, CC, clean_ssl(ssl)), |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 203 | "os": os, |
| 204 | "TARGET": TARGET, |
| 205 | "CC": CC, |
| 206 | "ssl": ssl, |
| 207 | "FLAGS": flags, |
| 208 | } |
| 209 | ) |
| 210 | |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 211 | # macOS |
| 212 | |
Tim Duesterhus | fd7931e | 2022-12-29 17:40:26 +0100 | [diff] [blame] | 213 | if "haproxy-" in ref_name: |
| 214 | os = "macos-12" |
| 215 | else: |
| 216 | os = "macos-latest" |
| 217 | |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 218 | TARGET = "osx" |
| 219 | for CC in ["clang"]: |
| 220 | matrix.append( |
| 221 | { |
Ilya Shipitsin | f5994fc | 2022-12-14 18:23:24 +0500 | [diff] [blame] | 222 | "name": "{}, {}, no features".format(os, CC), |
Tim Duesterhus | 288c077 | 2020-07-28 23:00:35 +0200 | [diff] [blame] | 223 | "os": os, |
| 224 | "TARGET": TARGET, |
| 225 | "CC": CC, |
| 226 | "FLAGS": [], |
| 227 | } |
| 228 | ) |
| 229 | |
| 230 | # Print matrix |
| 231 | |
| 232 | print(json.dumps(matrix, indent=4, sort_keys=True)) |
| 233 | |
Tim Duesterhus | 0810911 | 2022-12-29 17:40:29 +0100 | [diff] [blame] | 234 | if environ.get("GITHUB_OUTPUT") is not None: |
| 235 | with open(environ.get("GITHUB_OUTPUT"), "a") as f: |
Tim Duesterhus | 8a03bf4 | 2022-10-14 19:46:06 +0200 | [diff] [blame] | 236 | print("matrix={}".format(json.dumps({"include": matrix})), file=f) |