Skip to content

Commit 0d8efac

Browse files
Ariouztimfel
authored andcommitted
Fix running style gate on Github
1 parent 2b4f6e8 commit 0d8efac

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

.github/scripts/extract_matrix.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
)
7272

7373
DOWNLOADS_LINKS = {
74-
"GRADLE_JAVA_HOME": "https://download.oracle.com/java/{major_version}/latest/jdk-{major_version}_{os}-{arch_short}_bin{ext}"
74+
"GRADLE_JAVA_HOME": "https://download.oracle.com/java/{major_version}/latest/jdk-{major_version}_{os}-{arch_short}_bin{ext}",
75+
"ECLIPSE": "https://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops4/R-4.26-202211231800/eclipse-SDK-4.26-linux-gtk-x86_64.tar.gz"
7576
}
7677

7778
# Gitlab Runners OSS
@@ -82,12 +83,25 @@
8283
"windows-latest": ["windows", "amd64"]
8384
}
8485

85-
# Override unavailable Python versions for some OS/Arch combinations
86+
# Override unavailable Python versions for some OS/Arch / job name combinations
8687
PYTHON_VERSIONS = {
8788
"ubuntu-24.04-arm": "3.12.8",
89+
"ubuntu-latest": "3.12.8",
90+
"style-gate": "3.8.12",
91+
"style-ecj-gate": "3.8.12",
92+
}
93+
94+
EXCLUDED_SYSTEM_PACKAGES = {
95+
"devkit",
96+
"msvc_source",
8897
}
8998

9099

100+
PYTHON_PACKAGES_VERSIONS = {
101+
"pylint": "==2.4",
102+
"astroid": "==2.4"
103+
}
104+
91105
@dataclass
92106
class Artifact:
93107
name: str
@@ -148,8 +162,10 @@ def python_version(self) -> str | None:
148162
if "MX_PYTHON_VERSION" in self.env:
149163
del self.env["MX_PYTHON_VERSION"]
150164

151-
if self.runs_on in PYTHON_VERSIONS:
152-
python_version = PYTHON_VERSIONS[self.runs_on]
165+
for key, version in PYTHON_VERSIONS.items():
166+
if self.runs_on == key or key in self.name:
167+
python_version = version
168+
153169
return python_version
154170

155171
@cached_property
@@ -163,16 +179,20 @@ def system_packages(self) -> list[str]:
163179
continue
164180
elif k.startswith("00:") or k.startswith("01:"):
165181
k = k[3:]
182+
if any(excluded in k for excluded in EXCLUDED_SYSTEM_PACKAGES):
183+
continue
166184
system_packages.append(f"'{k}'" if self.runs_on != "windows-latest" else f"{k}")
167185
return system_packages
168186

169187
@cached_property
170188
def python_packages(self) -> list[str]:
171-
python_packages = []
189+
python_packages = [f"{key}{value}" for key, value in PYTHON_PACKAGES_VERSIONS.items()]
172190
for k, v in self.job.get("packages", {}).items():
173191
if k.startswith("pip:"):
174-
python_packages.append(f"'{k[4:]}{v}'" if self.runs_on != "windows-latest" else f"{k[4:]}{v}")
175-
return python_packages
192+
key = k[4:]
193+
if key in PYTHON_PACKAGES_VERSIONS: continue
194+
python_packages.append(f"{key}{v}")
195+
return [f"'{pkg}'" if self.runs_on != "windows-latest" else f"{pkg}" for pkg in python_packages]
176196

177197
def get_download_steps(self, key: str, version: str) -> str:
178198
download_link = self.get_download_link(key, version)
@@ -186,7 +206,7 @@ def get_download_steps(self, key: str, version: str) -> str:
186206
Add-Content $env:GITHUB_ENV "{key}=$(Resolve-Path $dirname)"
187207
""")
188208

189-
return (f"wget -q {download_link} && "
209+
return (f"wget -q '{download_link}' -O {filename} && "
190210
f"dirname=$(tar -tzf {filename} | head -1 | cut -f1 -d '/') && "
191211
f"tar -xzf {filename} && "
192212
f'echo {key}=$(realpath "$dirname") >> $GITHUB_ENV')
@@ -201,7 +221,7 @@ def get_download_link(self, key: str, version: str) -> str:
201221

202222
vars = {
203223
"major_version": major_version,
204-
"os":os,
224+
"os": os,
205225
"arch": arch,
206226
"arch_short": arch_short,
207227
"ext": extension,
@@ -261,6 +281,15 @@ def download_artifact(self) -> Artifact | None:
261281
return Artifact(pattern, os.path.normpath(artifacts[0].get("dir", ".")))
262282
return None
263283

284+
@staticmethod
285+
def safe_join(args: list[str]) -> str:
286+
safe_args = []
287+
for s in args:
288+
if s.startswith("$(") and s.endswith(")"):
289+
safe_args.append(s)
290+
else:
291+
safe_args.append(shlex.quote(s))
292+
return " ".join(safe_args)
264293

265294
@staticmethod
266295
def flatten_command(args: list[str | list[str]]) -> list[str]:
@@ -269,18 +298,19 @@ def flatten_command(args: list[str | list[str]]) -> list[str]:
269298
if isinstance(s, list):
270299
flattened_args.append(f"$( {shlex.join(s)} )")
271300
else:
272-
flattened_args.append(s)
301+
out = re.sub(r"\$\{([A-Z0-9_]+)\}", r"$\1", s).replace("'", "")
302+
flattened_args.append(out)
273303
return flattened_args
274304

275305
@cached_property
276306
def setup(self) -> str:
277307
cmds = [self.flatten_command(step) for step in self.job.get("setup", [])]
278-
return "\n".join(shlex.join(s) for s in cmds)
308+
return "\n".join(self.safe_join(s) for s in cmds)
279309

280310
@cached_property
281311
def run(self) -> str:
282312
cmds = [self.flatten_command(step) for step in self.job.get("run", [])]
283-
return "\n".join(shlex.join(s) for s in cmds)
313+
return "\n".join(self.safe_join(s) for s in cmds)
284314

285315
@cached_property
286316
def logs(self) -> str:
@@ -295,6 +325,7 @@ def to_dict(self):
295325
"name": self.name,
296326
"mx_version": self.mx_version,
297327
"os": self.runs_on,
328+
"fetch_depth": 0 if "--tags style" in self.run else 1,
298329
"python_version": self.python_version,
299330
"setup_steps": self.setup,
300331
"run_steps": self.run,
@@ -304,7 +335,7 @@ def to_dict(self):
304335
"require_artifact": [self.download_artifact.name, self.download_artifact.pattern] if self.download_artifact else None,
305336
"logs": self.logs.replace("../", "${{ env.PARENT_DIRECTORY }}/"),
306337
"env": self.env,
307-
"downloads_steps": " ".join(self.downloads),
338+
"downloads_steps": "\n".join(self.downloads),
308339
}
309340

310341
def __str__(self):

.github/workflows/ci-matrix-gen.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
TARGET: tier1
3131
JOBS: ${{ inputs.jobs_to_run }}
3232
steps: &generate_matrix
33-
- uses: actions/checkout@v4
33+
- uses: actions/checkout@v6
3434
- name: Download sjsonnet
3535
run: |
3636
curl -L -o sjsonnet https://github.com/databricks/sjsonnet/releases/download/0.5.7/sjsonnet-0.5.7-linux-x86_64
@@ -68,6 +68,10 @@ jobs:
6868
matrix:
6969
include: ${{ fromJson(needs.generate-tier1.outputs.matrix) }}
7070
steps: &buildsteps
71+
- name: Process matrix downloads
72+
if: ${{ matrix.downloads_steps }}
73+
run: |
74+
${{ matrix.downloads_steps }}
7175
7276
- name: Setup env
7377
shell: bash
@@ -92,10 +96,10 @@ jobs:
9296
"$($pair.Name)=$value" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
9397
}
9498
95-
- name: Actions/Checkout
96-
uses: actions/checkout@v4
99+
- uses: actions/checkout@v6
97100
with:
98101
path: main
102+
fetch-depth: ${{ matrix.fetch_depth }}
99103

100104
- name: Setup Unix paths like on buildbot CI
101105
if: runner.os != 'Windows'
@@ -209,11 +213,6 @@ jobs:
209213
if: ${{ runner.os == 'Windows' }}
210214
uses: microsoft/setup-msbuild@v1.0.2
211215

212-
- name: Process matrix downloads
213-
if: ${{ matrix.downloads_steps }}
214-
run: |
215-
${{ matrix.downloads_steps }}
216-
217216
- name: Setup
218217
working-directory: main
219218
if: ${{ matrix.setup_steps }}

.github/workflows/ci-unittest-retagger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
steps:
4141

4242
- name: Actions/Checkout
43-
uses: actions/checkout@main
43+
uses: actions/checkout@v6
4444
with:
4545
path: main
4646

0 commit comments

Comments
 (0)