Skip to content

Commit c18f9c2

Browse files
Fix validation issues (#56)
* Adding test and validation stage before publishing * Adding utils python package * Adding ignored packages folder * Fix test project * Use correct publish machine * Fix path for unity launcher in the validation phase * Create Editor folder and add registry to manifest * Add missing package to manifest * Provide Test folder to package * Fix project Version * Disable tests and fix terminal tests path * Reintroducing editmode tests * Use correct version * Fix solution file
1 parent 67b344e commit c18f9c2

File tree

192 files changed

+2487
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+2487
-294
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ publish/
143143
# NuGet Packages
144144
*.nupkg
145145
# The packages folder can be ignored because of Package Restore
146-
**/packages/*
146+
#**/packages/*
147147
# except build/, which is used as an MSBuild target.
148148
!**/packages/build/
149149
# Uncomment if necessary however generally it will be regenerated when needed

.gitlab-ci.yml

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,78 @@ variables:
22
GIT_SUBMODULE_STRATEGY: recursive
33

44
stages:
5-
- run_tests
5+
- run_tests_on_mono
66
- build_package
7+
- run_package_tests
78
- validate_package
89
- publish_package
910

10-
run_tests:mac:
11-
stage: run_tests
11+
run_tests_on_mono:mac:
12+
stage: run_tests_on_mono
1213
tags:
1314
- mac
1415
script:
15-
- cd src
16+
- cd src/
1617
- nuget restore
1718
- msbuild Unity.Mathematics.sln
18-
- mono packages/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe Unity.Mathematics.Tests/bin/Debug/Unity.Mathematics.Tests.dll --process=single
19+
- mono packages/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe Tests/bin/Debug/Unity.Mathematics.Tests.dll --process=single
1920

2021
build_package:mac:
2122
stage: build_package
2223
tags:
2324
- mac
2425
script:
25-
- cd src/
26+
- cd src
2627
- npm version 0.0.1
2728
- npm pack .
2829
artifacts:
2930
paths:
3031
- src/*.tgz
3132

33+
run_package_tests:mac:
34+
stage: run_package_tests
35+
tags:
36+
- mac
37+
before_script:
38+
- python Tools/CI/get_unity_launcher.py
39+
script:
40+
- tar xzvf src/com.unity.mathematics-0.0.1.tgz
41+
- ./.UnityLauncher.Editor/osx.10.12-x64/publish/UnityLauncher.Editor -registryoverride https://bfartifactory.bf.unity3d.com/artifactory/api/npm/unity-upm-staging -timeout 1200 -scriptingBackend mono -unityexecutable ~/Editor/Unity.app/Contents/MacOS/Unity -projectpath Unity.Mathematics.TestProject -batchmode -silentcrashes -automated -logfile output-macOS-editmode-test.log -cleanedLogFile output-macOS-editmode-test-cleaned.log -runtests -testresults results.xml -testPlatform editmode --ignoreErrorsOnArtifactCreation
42+
3243
validate_package:mac:
3344
stage: validate_package
3445
tags:
3546
- mac
47+
only:
48+
- tags
49+
before_script:
50+
- python Tools/CI/get_unity_launcher.py
3651
script:
52+
- cp Tools/CI/ValidatePackage.cs Unity.Mathematics.TestProject/Assets/Editor/ValidatePackage.cs
3753
- tar xzvf src/com.unity.mathematics-0.0.1.tgz
38-
- python Tools/CI/validation.py --package-path package
54+
- cd package
55+
- npm version $CI_COMMIT_TAG
56+
- jq --arg rev $CI_COMMIT_SHA '.repository.revision=$rev' package.json > temp_package && mv temp_package package.json
57+
- cd ..
58+
- ./.UnityLauncher.Editor/osx.10.12-x64/publish/UnityLauncher.Editor -registryoverride https://bfartifactory.bf.unity3d.com/artifactory/api/npm/unity-upm-staging -timeout 1200 -unityexecutable ~/Editor/Unity.app/Contents/MacOS/Unity -executeMethod ValidatePackage.Validate ../package -projectpath Unity.Mathematics.TestProject -batchmode -silentcrashes -automated -logfile output-linux-validation.log -cleanedLogFile output-linux-validation-cleaned.log -quit -displayResolutionDialog disabled -addPackage [email protected]
3959
dependencies:
4060
- build_package:mac
61+
artifacts:
62+
paths:
63+
- package/
64+
4165

4266
publish_package:mac:
4367
stage: publish_package
4468
tags:
45-
- mac
69+
- gamecode
70+
- macOS
4671
only:
4772
- tags
4873
script:
49-
- tar xzvf src/com.unity.mathematics-0.0.1.tgz
74+
- python Tools/CI/validation.py --package-path package --commit-tag $CI_COMMIT_TAG
5075
- cd package
51-
- npm version $CI_COMMIT_TAG
52-
- npm pack .
53-
- npm publish com.unity.mathematics-$CI_COMMIT_TAG.tgz
76+
#- npm publish --registry https://staging-packages.unity.com
77+
- echo "Would have published com.unity.mathematics $CI_COMMIT_TAG"
5478
dependencies:
55-
- build_package:mac
79+
- validate_package:mac

Tools/CI/ValidatePackage.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text.RegularExpressions;
7+
using Unity.Properties.Serialization;
8+
using UnityEditor;
9+
using UnityEditor.PackageManager.ValidationSuite;
10+
using UnityEngine;
11+
12+
public class ValidatePackage
13+
{
14+
static List<string> failuresWhitelist = new List<string>{};// "Restricted File Type Validation", "Tests Validation" };
15+
16+
[MenuItem("Window/Validate Mathematics")]
17+
public static void ValidateMathematics()
18+
{
19+
ValidateInternal("../package");
20+
}
21+
22+
static void FilterWhitelistedFailures(string report)
23+
{
24+
var reportLines = report.Split(new string[] {"\r\n\r\n"}, StringSplitOptions.RemoveEmptyEntries);
25+
Array.Copy(reportLines, 2, reportLines, 0, reportLines.Length - 2);
26+
Regex regex = new Regex($"(\\w+)[ -]+\"([\\w\\s]+)\"\\s+(.*)");
27+
28+
var issues = string.Empty;
29+
30+
foreach (var line in reportLines)
31+
{
32+
var match = regex.Match(line);
33+
if (match.Success)
34+
{
35+
var status = match.Groups[1].Captures[0].Value;
36+
if (status != "Failed")
37+
continue;
38+
var check = match.Groups[2].Captures[0].Value;
39+
var data = match.Groups[3].Captures[0].Value;
40+
41+
if (status == "Failed" && failuresWhitelist.Contains(check))
42+
continue;
43+
44+
issues += line + "\r\n";
45+
}
46+
}
47+
48+
if (issues != string.Empty)
49+
{
50+
throw new Exception(issues);
51+
}
52+
}
53+
54+
public static void ValidateInternal(string packagePath)
55+
{
56+
var packageManifest = Path.Combine(packagePath, "package.json");
57+
if (!File.Exists(packageManifest))
58+
throw new Exception($"File package.json not found in {packagePath}");
59+
60+
object dict;
61+
if (!Json.TryDeserializeObject(File.ReadAllText(packageManifest), out dict))
62+
throw new Exception($"Invalid package.json file in {packageManifest}");
63+
64+
Json.TryGetValue((IDictionary<string, object>)dict, "name", out string name);
65+
Json.TryGetValue((IDictionary<string, object>)dict, "version", out string version);
66+
67+
var result = ValidationSuite.ValidatePackage($"{name}@{version}", ValidationType.Publishing);
68+
if (!result)
69+
FilterWhitelistedFailures(ValidationSuite.GetValidationSuiteReport(name, version));
70+
}
71+
72+
public static void Validate()
73+
{
74+
var arguments = Environment.GetCommandLineArgs();
75+
var executeMethodIndex = 0;
76+
while (executeMethodIndex < arguments.Length)
77+
{
78+
if (arguments[executeMethodIndex] == "-executeMethod")
79+
break;
80+
executeMethodIndex++;
81+
}
82+
83+
// Need to advance by 2 elements because the format is -executeMethod Builders.Build <Target>
84+
// n.b.: executeMethodIndex is the index of -executeMethod
85+
var targetIndex = executeMethodIndex + 2;
86+
if (targetIndex >= arguments.Length || arguments[targetIndex].StartsWith("-"))
87+
throw new Exception("Wrong argument. To execute this method run unity with the parameter -executeMethod ValidatePackage.Validate <path_to_package>");
88+
89+
var packagePath = arguments[targetIndex];
90+
ValidateInternal(packagePath);
91+
}
92+
}

Tools/CI/get_unity_launcher.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import sys
3+
4+
import utils
5+
6+
artifactory_api_url = "https://artifactory.eu-cph-1.unityops.net"
7+
artifactory_api_repository = "core-automation"
8+
artifactory_download_url = "https://bfartifactory.bf.unity3d.com/artifactory/ie-generic-core-automation"
9+
bokken_artifactory_cache_url = "http://172.28.214.140/"
10+
build_version = '2018.2.*&latest=true'
11+
12+
def download_unity_launcher(type):
13+
if not os.path.exists(".tmp"):
14+
os.mkdir(".tmp")
15+
download_url = artifactory_download_url
16+
if 'USE_UBERBUCKET' in os.environ:
17+
download_url = bokken_artifactory_cache_url
18+
utils.download_url("%s/tools/unity-launcher/UnityLauncher.%s.zip" % (download_url, type),
19+
".tmp/UnityLauncher.%s.zip" % type)
20+
21+
22+
def extract_unity_launcher(type):
23+
utils.extract_zip(".tmp/UnityLauncher.%s.zip" % type,
24+
".UnityLauncher.%s" % type)
25+
current_os = utils.get_current_os()
26+
if current_os == "macOS":
27+
os.chmod('.UnityLauncher.{0}/osx.10.12-x64/publish/UnityLauncher.{0}'.format(type), 0755)
28+
elif current_os == "linux":
29+
os.chmod('.UnityLauncher.{0}/linux-x64/publish/UnityLauncher.{0}'.format(type), 0755)
30+
31+
32+
def prepare_unity_launcher(run_type):
33+
34+
download_unity_launcher(run_type)
35+
extract_unity_launcher(run_type)
36+
37+
def main():
38+
prepare_unity_launcher("Editor")
39+
return
40+
41+
42+
if __name__ == "__main__":
43+
main()

Tools/CI/utils.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import json
2+
import os
3+
import shutil
4+
import tarfile
5+
import zipfile
6+
import subprocess
7+
8+
import requests
9+
10+
import sys
11+
12+
target_os = sys.platform
13+
14+
def get_current_os():
15+
p = sys.platform
16+
if p == "darwin":
17+
return "macOS"
18+
if p == "win32":
19+
return "windows"
20+
return "linux"
21+
22+
23+
def get_target_os():
24+
if target_os != sys.platform:
25+
return target_os
26+
27+
return get_current_os()
28+
29+
30+
def set_target_os(target):
31+
global target_os
32+
target_os = target
33+
34+
def get_url_json(url):
35+
print " Getting json from {0}".format(url)
36+
import urllib2
37+
response = urllib2.urlopen(url)
38+
return json.loads(response.read())
39+
40+
41+
def extract_tarball(download_path, extract_path):
42+
print " Extracting %s into %s" % (download_path, extract_path)
43+
tar = tarfile.open(download_path, "r:gz")
44+
tar.extractall(extract_path)
45+
tar.close()
46+
47+
48+
def download_url(url, filename):
49+
print " Downloading %s to %s" % (url, filename)
50+
51+
r = requests.get(url, stream=True)
52+
with open(filename, 'wb') as f:
53+
shutil.copyfileobj(r.raw, f)
54+
55+
56+
def extract_zip(archive, destination):
57+
print " Extracting %s into %s" % (archive, destination)
58+
import zipfile
59+
if get_current_os() == "windows":
60+
zip_ref = ZipfileLongWindowsPaths(archive, 'r')
61+
else:
62+
zip_ref = zipfile.ZipFile(archive, 'r')
63+
zip_ref.extractall(destination)
64+
zip_ref.close()
65+
66+
67+
def winapi_path(dos_path, encoding=None):
68+
path = os.path.abspath(dos_path)
69+
70+
if path.startswith("\\\\"):
71+
path = "\\\\?\\UNC\\" + path[2:]
72+
else:
73+
path = "\\\\?\\" + path
74+
75+
return path
76+
77+
78+
def npm_cmd(cmd, registry):
79+
registry_cmd = ''
80+
if registry:
81+
registry_cmd = "--registry {0}".format(registry)
82+
83+
formatted_cmd = 'npm {0} {1}'.format(cmd, registry_cmd)
84+
85+
print " Running: {0}".format(formatted_cmd)
86+
return subprocess.check_output(formatted_cmd, shell=True, stderr=subprocess.STDOUT)
87+
88+
89+
def git_cmd(cmd, print_command=True):
90+
formatted_cmd = "git {0}".format(cmd)
91+
if print_command:
92+
print " Running: {0}".format(formatted_cmd)
93+
return subprocess.check_output(formatted_cmd, shell=True, stderr=subprocess.STDOUT)
94+
95+
96+
def git_cmd_code_only(cmd, print_command=True):
97+
formatted_cmd = "git {0}".format(cmd)
98+
if print_command:
99+
print " Running: {0}".format(formatted_cmd)
100+
with open(os.devnull, 'w') as devnull:
101+
return subprocess.call(formatted_cmd, shell=True, stderr=devnull, stdout=devnull)
102+
103+
104+
class ZipfileLongWindowsPaths(zipfile.ZipFile):
105+
106+
def _extract_member(self, member, targetpath, pwd):
107+
targetpath = winapi_path(targetpath)
108+
return zipfile.ZipFile._extract_member(self, member, targetpath, pwd)

0 commit comments

Comments
 (0)