com.unity.asset-store-tools
com.unity.asset-store-tools copied to clipboard
Allow validation from external scripts
As a plugin developer for the Unity Asset Store I want to be able to utilize the official Asset Store Tools validation feature in my plugins CI to ensure maximum quality of my plugin. This is not possible at the time since everything is marked as internal.
If this is not something you have decided to specifically disallow, I would suggest opening the validation part of the tool up to be called from external scripts. I did a quick and dirty proof of concept of this which works (though needs improvement to keep the same quality as the rest of the tool):
namespace AssetStoreTools.Validator
{
public static class PackageValidatorExposer
{
public class ValidationResult
{
public bool Success { get; set; }
public string Error { get; set; }
}
public static ValidationResult ValidatePackage(string path)
{
var settings = new ValidationSettings
{
Category = "",
ValidationPaths = new List<string> { path }
};
var result = PackageValidator.ValidatePackage(settings);
bool testFailures = false;
string testFailureMessages = "";
foreach (var test in result.AutomatedTests)
{
testFailures |= test.Result.Result != TestResult.ResultStatus.Pass;
if (test.Result.Result != TestResult.ResultStatus.Pass)
{
for (int i = 0; i < test.Result.MessageCount; i++)
{
testFailureMessages += test.Result.GetMessage(i).GetText() + "\n";
}
}
}
var newResult = new ValidationResult
{
Success = result.Status == ValidationStatus.RanToCompletion && !result.HadCompilationErrors &&
string.IsNullOrEmpty(result.Error) && !testFailures,
Error = result.Error + "\n" + testFailureMessages
};
return newResult;
}
}
}