chore: add tests, update docs and actions (#299)

* docs: update documentation

* feat: validate-inputs has it's own pyproject

* security: mask DOCKERHUB_PASSWORD

* chore: add tokens, checkout, recrete docs, integration tests

* fix: add `statuses: write` permission to pr-lint
This commit is contained in:
2025-10-18 13:09:19 +03:00
committed by GitHub
parent d3c2de1bd1
commit 7061aafd35
148 changed files with 5119 additions and 1897 deletions

View File

@@ -3,8 +3,8 @@
from __future__ import annotations
import os
from pathlib import Path
import sys
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest # pylint: disable=import-error
@@ -24,14 +24,11 @@ class TestModularValidator:
output_file = tmp_path / "github_output"
output_file.touch()
with (
patch.dict(
os.environ,
{"GITHUB_OUTPUT": str(output_file)},
clear=True,
),
pytest.raises(SystemExit) as exc_info,
):
with patch.dict(
os.environ,
{"GITHUB_OUTPUT": str(output_file)},
clear=True,
), pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 1
@@ -45,19 +42,16 @@ class TestModularValidator:
output_file.touch()
# docker-build is a known action with a validator
with (
patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
"INPUT_TAG": "v1.0.0",
"INPUT_IMAGE_NAME": "myapp",
},
clear=True,
),
patch("modular_validator.logger") as mock_logger,
):
with patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
"INPUT_TAG": "v1.0.0",
"INPUT_IMAGE_NAME": "myapp",
},
clear=True,
), patch("modular_validator.logger") as mock_logger:
main()
content = output_file.read_text()
@@ -69,20 +63,18 @@ class TestModularValidator:
output_file = tmp_path / "github_output"
output_file.touch()
with (
patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
"INPUT_TAG": "invalid_tag!", # Invalid tag format
},
clear=True,
),
patch("modular_validator.logger") as mock_logger,
pytest.raises(SystemExit) as exc_info,
with patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
"INPUT_TAG": "invalid_tag!", # Invalid tag format
},
clear=True,
):
main()
with patch("modular_validator.logger") as mock_logger:
with pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 1
content = output_file.read_text()
@@ -99,21 +91,18 @@ class TestModularValidator:
mock_validator.validate_inputs.return_value = True
mock_validator.errors = []
with (
patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
"INPUT_TAG": "v1.0.0",
"INPUT_IMAGE_NAME": "myapp",
"INPUT_BUILD_ARGS": "NODE_ENV=prod",
"NOT_AN_INPUT": "should_be_ignored",
},
clear=True,
),
patch("modular_validator.get_validator", return_value=mock_validator),
):
with patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
"INPUT_TAG": "v1.0.0",
"INPUT_IMAGE_NAME": "myapp",
"INPUT_BUILD_ARGS": "NODE_ENV=prod",
"NOT_AN_INPUT": "should_be_ignored",
},
clear=True,
), patch("modular_validator.get_validator", return_value=mock_validator):
main()
# Check that validate_inputs was called with correct inputs
@@ -133,18 +122,15 @@ class TestModularValidator:
mock_validator.validate_inputs.return_value = True
mock_validator.errors = []
with (
patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
"INPUT_BUILD_ARGS": "test=value",
},
clear=True,
),
patch("modular_validator.get_validator", return_value=mock_validator),
):
with patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
"INPUT_BUILD_ARGS": "test=value",
},
clear=True,
), patch("modular_validator.get_validator", return_value=mock_validator):
main()
# Check that both underscore and dash versions are present
@@ -160,17 +146,14 @@ class TestModularValidator:
mock_validator.validate_inputs.return_value = True
mock_validator.errors = []
with (
patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
},
clear=True,
),
patch("modular_validator.get_validator", return_value=mock_validator) as mock_get,
):
with patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
},
clear=True,
), patch("modular_validator.get_validator", return_value=mock_validator) as mock_get:
main()
# get_validator should be called with underscore version
@@ -181,19 +164,16 @@ class TestModularValidator:
output_file = tmp_path / "github_output"
output_file.touch()
with (
patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
},
clear=True,
),
patch("modular_validator.get_validator", side_effect=ValueError("Test error")),
pytest.raises(SystemExit) as exc_info,
):
main()
with patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
},
clear=True,
), patch("modular_validator.get_validator", side_effect=ValueError("Test error")):
with pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 1
content = output_file.read_text()
@@ -206,13 +186,11 @@ class TestModularValidator:
fallback_path = Path.home() / "github_output"
try:
with (
patch.dict(os.environ, {"INPUT_ACTION_TYPE": "docker-build"}, clear=True),
patch("modular_validator.get_validator", side_effect=ValueError("Test error")),
patch("modular_validator.logger"),
pytest.raises(SystemExit) as exc_info,
):
main()
with patch.dict(os.environ, {"INPUT_ACTION_TYPE": "docker-build"}, clear=True):
with patch("modular_validator.get_validator", side_effect=ValueError("Test error")):
with patch("modular_validator.logger"):
with pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 1
@@ -235,19 +213,16 @@ class TestModularValidator:
mock_validator.validate_inputs.return_value = False
mock_validator.errors = ["Error 1", "Error 2"]
with (
patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
},
clear=True,
),
patch("modular_validator.get_validator", return_value=mock_validator),
pytest.raises(SystemExit) as exc_info,
):
main()
with patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": "docker-build",
},
clear=True,
), patch("modular_validator.get_validator", return_value=mock_validator):
with pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 1
content = output_file.read_text()
@@ -260,18 +235,16 @@ class TestModularValidator:
output_file = tmp_path / "github_output"
output_file.touch()
with (
patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": " ", # Whitespace only
},
clear=True,
),
pytest.raises(SystemExit) as exc_info,
with patch.dict(
os.environ,
{
"GITHUB_OUTPUT": str(output_file),
"INPUT_ACTION_TYPE": " ", # Whitespace only
},
clear=True,
):
main()
with pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 1
content = output_file.read_text()