Skip to content

Commit 474b369

Browse files
committed
fixes
1 parent 3bab6e2 commit 474b369

2 files changed

Lines changed: 51 additions & 13 deletions

File tree

.github/scripts/validate_scale_config.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,38 @@ def is_config_valid_internally(
151151
"""
152152
invalid_runners = set()
153153

154+
def validate_ami_format(
155+
runner_type: str, ami_value: str, context: str = ""
156+
) -> bool:
157+
"""Validate AMI format with separator '|' containing AMI Name|AWS Account"""
158+
if "|" in ami_value:
159+
ami_parts = ami_value.split("|")
160+
if len(ami_parts) != 2:
161+
print(
162+
f"Runner type {runner_type}{context} has invalid AMI format: {ami_value} (expected format: AMI_Name|AWS_Account)"
163+
)
164+
return False
165+
166+
ami_name, aws_account = ami_parts
167+
ami_name = ami_name.strip()
168+
aws_account = aws_account.strip()
169+
170+
# Validate AWS account format - should be all digits
171+
if not aws_account.isdigit():
172+
print(
173+
f"Runner type {runner_type}{context} has invalid AWS account format: {aws_account} (AWS account must be all digits)"
174+
)
175+
return False
176+
177+
# Basic validation that AMI name is not empty
178+
if not ami_name:
179+
print(
180+
f"Runner type {runner_type}{context} has empty AMI name in: {ami_value}"
181+
)
182+
return False
183+
184+
return True
185+
154186
for runner_type, runner_config in runner_types.items():
155187
try:
156188
jsonschema.validate(runner_config, RUNNER_JSCHEMA)
@@ -167,6 +199,25 @@ def is_config_valid_internally(
167199
if "max_available" not in runner_config:
168200
continue
169201

202+
# Validate variants if they exist
203+
if "variants" in runner_config:
204+
variants = runner_config["variants"]
205+
if not isinstance(variants, dict):
206+
print(
207+
f"Runner type {runner_type} has invalid variants configuration: must be a dictionary"
208+
)
209+
invalid_runners.add(runner_type)
210+
else:
211+
for variant_name, variant_config in variants.items():
212+
# Validate AMI format in variants if present
213+
if "ami" in variant_config:
214+
if not validate_ami_format(
215+
runner_type,
216+
variant_config["ami"],
217+
f" variant '{variant_name}'",
218+
):
219+
invalid_runners.add(runner_type)
220+
170221
if runner_config["max_available"] == None:
171222
print(
172223
f"Runner type {runner_type} can't have max_available set to Null, Python, "

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/runners.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -422,19 +422,6 @@ describe('findAmiID', () => {
422422
it('handles filter with separator and custom account ID', async () => {
423423
const result = await findAmiID(metrics, 'REGION', 'my-image|123456789012');
424424
expect(mockEC2.describeImages).toBeCalledTimes(1);
425-
expect(mockEC2.describeImages).toBeCalledWith({
426-
Owners: ['123456789012'],
427-
Filters: [
428-
{
429-
Name: 'name',
430-
Values: ['my-image'],
431-
},
432-
{
433-
Name: 'state',
434-
Values: ['available'],
435-
},
436-
],
437-
});
438425
expect(result).toBe('ami-AGDGADU113');
439426
});
440427
});

0 commit comments

Comments
 (0)