mirror of
https://github.com/ivuorinen/actions.git
synced 2026-02-11 15:46:36 +00:00
fix: node-setup caching, validate-inputs optional_inputs type (#320)
* fix: node-setup caching, validate-inputs optional_inputs type * test(validate-inputs): dict optional_inputs backward compatibility Verify that legacy dict format for optional_inputs correctly generates conventions from dict keys. Updates existing test to expect list type for optional_inputs default.
This commit is contained in:
@@ -275,7 +275,8 @@ runs:
|
|||||||
with:
|
with:
|
||||||
node-version: ${{ steps.version.outputs.detected-version }}
|
node-version: ${{ steps.version.outputs.detected-version }}
|
||||||
registry-url: ${{ inputs.registry-url }}
|
registry-url: ${{ inputs.registry-url }}
|
||||||
cache: false
|
# Note: cache parameter removed for actions/setup-node@v6 compatibility
|
||||||
|
# Caching is handled separately via common-cache action (step: Cache Dependencies)
|
||||||
|
|
||||||
- name: Enable Corepack
|
- name: Enable Corepack
|
||||||
id: corepack
|
id: corepack
|
||||||
|
|||||||
@@ -48,9 +48,47 @@ class TestConventionsValidator:
|
|||||||
rules = validator._rules
|
rules = validator._rules
|
||||||
assert rules["action_type"] == "nonexistent-action"
|
assert rules["action_type"] == "nonexistent-action"
|
||||||
assert rules["required_inputs"] == []
|
assert rules["required_inputs"] == []
|
||||||
assert isinstance(rules["optional_inputs"], dict)
|
assert isinstance(rules["optional_inputs"], list)
|
||||||
assert isinstance(rules["conventions"], dict)
|
assert isinstance(rules["conventions"], dict)
|
||||||
|
|
||||||
|
def test_load_rules_with_dict_optional_inputs(self, tmp_path):
|
||||||
|
"""Test backward compatibility with dict format for optional_inputs."""
|
||||||
|
# Create a rules file with legacy dict format for optional_inputs
|
||||||
|
rules_file = tmp_path / "legacy_rules.yml"
|
||||||
|
rules_file.write_text("""
|
||||||
|
action_type: legacy-action
|
||||||
|
required_inputs: []
|
||||||
|
optional_inputs:
|
||||||
|
foo: int
|
||||||
|
bar: str
|
||||||
|
baz:
|
||||||
|
type: boolean
|
||||||
|
validator: boolean
|
||||||
|
conventions: {}
|
||||||
|
overrides: {}
|
||||||
|
""")
|
||||||
|
# Load rules and verify conventions are built from dict keys
|
||||||
|
validator = ConventionBasedValidator("legacy-action")
|
||||||
|
rules = validator.load_rules(rules_file)
|
||||||
|
|
||||||
|
# Verify optional_inputs is preserved as-is from YAML
|
||||||
|
assert "optional_inputs" in rules
|
||||||
|
assert isinstance(rules["optional_inputs"], dict)
|
||||||
|
|
||||||
|
# Verify conventions were auto-generated from optional_inputs dict keys
|
||||||
|
assert "conventions" in rules
|
||||||
|
assert isinstance(rules["conventions"], dict)
|
||||||
|
conventions_keys = set(rules["conventions"].keys())
|
||||||
|
optional_keys = set(rules["optional_inputs"].keys())
|
||||||
|
assert conventions_keys == optional_keys, (
|
||||||
|
f"Conventions keys {conventions_keys} should match optional_inputs keys {optional_keys}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify each key from the dict is in conventions
|
||||||
|
assert "foo" in rules["conventions"]
|
||||||
|
assert "bar" in rules["conventions"]
|
||||||
|
assert "baz" in rules["conventions"]
|
||||||
|
|
||||||
def test_load_rules_with_custom_path(self, tmp_path):
|
def test_load_rules_with_custom_path(self, tmp_path):
|
||||||
"""Test loading rules from custom path."""
|
"""Test loading rules from custom path."""
|
||||||
rules_file = tmp_path / "custom_rules.yml"
|
rules_file = tmp_path / "custom_rules.yml"
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class ConventionBasedValidator(BaseValidator):
|
|||||||
return {
|
return {
|
||||||
"action_type": self.action_type,
|
"action_type": self.action_type,
|
||||||
"required_inputs": [],
|
"required_inputs": [],
|
||||||
"optional_inputs": {},
|
"optional_inputs": [],
|
||||||
"conventions": {},
|
"conventions": {},
|
||||||
"overrides": {},
|
"overrides": {},
|
||||||
}
|
}
|
||||||
@@ -93,16 +93,27 @@ class ConventionBasedValidator(BaseValidator):
|
|||||||
|
|
||||||
# Ensure all expected keys exist
|
# Ensure all expected keys exist
|
||||||
rules.setdefault("required_inputs", [])
|
rules.setdefault("required_inputs", [])
|
||||||
rules.setdefault("optional_inputs", {})
|
rules.setdefault("optional_inputs", [])
|
||||||
rules.setdefault("conventions", {})
|
rules.setdefault("conventions", {})
|
||||||
rules.setdefault("overrides", {})
|
rules.setdefault("overrides", {})
|
||||||
|
|
||||||
# Build conventions from optional_inputs if not explicitly set
|
# Build conventions from optional_inputs if not explicitly set
|
||||||
if not rules["conventions"] and rules["optional_inputs"]:
|
if not rules["conventions"] and rules["optional_inputs"]:
|
||||||
conventions = {}
|
conventions = {}
|
||||||
for input_name, input_config in rules["optional_inputs"].items():
|
optional_inputs = rules["optional_inputs"]
|
||||||
# Try to infer validator type from the input name or pattern
|
|
||||||
conventions[input_name] = self._infer_validator_type(input_name, input_config)
|
# Handle both list and dict formats for optional_inputs
|
||||||
|
if isinstance(optional_inputs, list):
|
||||||
|
# List format: just input names
|
||||||
|
for input_name in optional_inputs:
|
||||||
|
conventions[input_name] = self._infer_validator_type(input_name, {})
|
||||||
|
elif isinstance(optional_inputs, dict):
|
||||||
|
# Dict format: input names with config
|
||||||
|
for input_name, input_config in optional_inputs.items():
|
||||||
|
conventions[input_name] = self._infer_validator_type(
|
||||||
|
input_name, input_config
|
||||||
|
)
|
||||||
|
|
||||||
rules["conventions"] = conventions
|
rules["conventions"] = conventions
|
||||||
|
|
||||||
return rules
|
return rules
|
||||||
@@ -110,7 +121,7 @@ class ConventionBasedValidator(BaseValidator):
|
|||||||
return {
|
return {
|
||||||
"action_type": self.action_type,
|
"action_type": self.action_type,
|
||||||
"required_inputs": [],
|
"required_inputs": [],
|
||||||
"optional_inputs": {},
|
"optional_inputs": [],
|
||||||
"conventions": {},
|
"conventions": {},
|
||||||
"overrides": {},
|
"overrides": {},
|
||||||
}
|
}
|
||||||
@@ -285,7 +296,7 @@ class ConventionBasedValidator(BaseValidator):
|
|||||||
# Get conventions and overrides from rules
|
# Get conventions and overrides from rules
|
||||||
conventions = self._rules.get("conventions", {})
|
conventions = self._rules.get("conventions", {})
|
||||||
overrides = self._rules.get("overrides", {})
|
overrides = self._rules.get("overrides", {})
|
||||||
optional_inputs = self._rules.get("optional_inputs", {})
|
optional_inputs = self._rules.get("optional_inputs", [])
|
||||||
required_inputs = self.get_required_inputs()
|
required_inputs = self.get_required_inputs()
|
||||||
|
|
||||||
# Validate each input
|
# Validate each input
|
||||||
|
|||||||
Reference in New Issue
Block a user