예제 #1
0
        /// <summary>
        /// Generates and uploads the Manifest.json on the master using all file hashes computed and stored
        /// by workers using <see cref="VsoClient.RegisterFilesForBuildManifestAsync"/> for the given drop.
        /// Should be called only when DropConfig.EnableBuildManifestCreation is true.
        /// </summary>
        public async static Task <IIpcResult> GenerateAndUploadBuildManifestFileAsync(DropDaemon daemon)
        {
            Contract.Requires(daemon.DropConfig.EnableBuildManifestCreation == true, "GenerateBuildManifestData API called even though Build Manifest Generation is Disabled in DropConfig");

            var bxlResult = await daemon.ApiClient.GenerateBuildManifestData(
                daemon.DropName,
                daemon.DropConfig.Repo,
                daemon.DropConfig.Branch,
                daemon.DropConfig.CommitId,
                daemon.DropConfig.CloudBuildId);

            if (!bxlResult.Succeeded)
            {
                return(new IpcResult(IpcResultStatus.ExecutionError, $"GenerateBuildManifestData API call failed for Drop: {daemon.DropName}. Failure: {bxlResult.Failure}"));
            }

            string localFilePath;
            string buildManifestJsonStr = BuildManifestData.GenerateBuildManifestJsonString(bxlResult.Result);

            try
            {
                localFilePath = Path.GetTempFileName();
                System.IO.File.WriteAllText(localFilePath, buildManifestJsonStr);
            }
            catch (Exception ex)
            {
                return(new IpcResult(IpcResultStatus.ExecutionError, $"Exception while trying to store Build Manifest locally before drop upload: {ex}"));
            }

            var dropItem = new DropItemForFile(localFilePath, relativeDropPath: DropBuildManifestPath);

            return(await daemon.AddFileAsync(dropItem));
        }
예제 #2
0
        public void TestBuildManifestDataHashCodes()
        {
            List <BuildManifestFile> outputs0 = new List <BuildManifestFile>();

            outputs0.Add(new BuildManifestFile("relativePath", "vsohash", "sha256Hash"));

            BuildManifestData data0 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs0);
            int hashCode0           = data0.GetHashCode();

            List <BuildManifestFile> outputs1 = new List <BuildManifestFile>();

            outputs1.Add(new BuildManifestFile("relativePath", "vsohash", "sha256Hash"));

            BuildManifestData data1 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs1);
            int hashCode1           = data1.GetHashCode();

            XAssert.AreEqual(hashCode0, hashCode1);
            XAssert.AreEqual(data0, data1);

            List <BuildManifestFile> outputs2 = new List <BuildManifestFile>();

            outputs2.Add(new BuildManifestFile("relativePath2", "vsohash", "sha256Hash"));
            BuildManifestData data2 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs2);

            XAssert.AreNotEqual(data0, data2);
        }
예제 #3
0
        /// <summary>
        /// Executes <see cref="GenerateBuildManifestDataCommand"/>. Generates a BuildManifest.json file for given
        /// <see cref="GenerateBuildManifestDataCommand.DropName"/>.
        /// </summary>
        private IIpcResult ExecuteGenerateBuildManifestData(GenerateBuildManifestDataCommand cmd)
        {
            Contract.Requires(cmd != null);
            Contract.Requires(m_buildManifestGenerator != null, "Build Manifest data can only be generated on master");

            BuildManifestData buildManifestData = m_buildManifestGenerator.GenerateBuildManifestData(cmd.DropName);

            return(IpcResult.Success(cmd.RenderResult(buildManifestData)));
        }
예제 #4
0
        public async Task TestGenerateBuildManifestDataAsync()
        {
            string            dropName     = "DropName";
            BuildManifestData expectedData = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", new List <BuildManifestFile>());

            using var apiClient = CreateApiClient(ipcOperation =>
            {
                var cmd = (GenerateBuildManifestDataCommand)Command.Deserialize(ipcOperation.Payload);
                XAssert.AreEqual(dropName, cmd.DropName);
                return(IpcResult.Success(cmd.RenderResult(expectedData)));
            });
            var maybeResult = await apiClient.GenerateBuildManifestData(dropName, "Repo", "branch", "commitId", "cbId");

            XAssert.PossiblySucceeded(maybeResult);
            XAssert.AreEqual(expectedData, maybeResult.Result);
        }
예제 #5
0
    // From https://gist.github.com/mattiaswargren/e50ba1b8a9c2b5449da3143f0d1b2816
    private static BuildManifestData LoadBuildManifest()
    {
        BuildManifestData manifest = null;
        TextAsset         json     = (TextAsset)Resources.Load("UnityCloudBuildManifest.json");

        if (json != null)
        {
            manifest = JsonUtility.FromJson <BuildManifestData>(json.text);
            Debug.Log("Attempted to load build manifest from .json file.\n"
                      + "build #: " + manifest.buildNumber
                      + "\nstart time: " + manifest.buildStartTime
                      + "\ntarget name: " + manifest.cloudBuildTargetName);
        }
        else
        {
            Debug.Log("Failed to load build manifest .json file as TextAsset.");
        }
        return(manifest);
    }
예제 #6
0
        public void TestValidBuildManifestData()
        {
            List <BuildManifestFile> outputs = new List <BuildManifestFile>();
            BuildManifestData        data0   = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs);

            XAssert.IsTrue(BuildManifestData.TryParse(data0.ToString(), out var parsedData0));
            XAssert.AreEqual(data0, parsedData0);

            outputs.Add(new BuildManifestFile("relativePath1", "vsohash", "sha256Hash"));
            BuildManifestData data1 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs);

            XAssert.IsTrue(BuildManifestData.TryParse(data1.ToString(), out var parsedData1));
            XAssert.AreEqual(data1, parsedData1);

            outputs.Add(new BuildManifestFile("relativePath2", "vsohash", "sha256Hash"));
            BuildManifestData data2 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs);

            XAssert.IsTrue(BuildManifestData.TryParse(data2.ToString(), out var parsedData2));
            XAssert.AreEqual(data2, parsedData2);
        }
예제 #7
0
        /// <summary>
        /// Executes <see cref="GenerateBuildManifestDataCommand"/>. Generates a BuildManifest.json file for given
        /// <see cref="GenerateBuildManifestDataCommand.DropName"/>.
        /// </summary>
        private IIpcResult ExecuteGenerateBuildManifestData(GenerateBuildManifestDataCommand cmd)
        {
            Contract.Requires(cmd != null);
            Contract.Requires(m_buildManifestGenerator != null, "Build Manifest data can only be generated on master");

            var duplicateEntries = m_buildManifestGenerator.DuplicateEntries(cmd.DropName);

            if (duplicateEntries.Count != 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append($"Operation Register BuildManifest Hash for Drop '{cmd.DropName}' failed due to files with different hashes being uploaded to the same path: ");
                foreach (var entry in duplicateEntries)
                {
                    sb.Append($"[Path: {entry.relativePath}'. RecordedHash: '{entry.recordedHash}'. RejectedHash: '{entry.rejectedHash}'] ");
                }

                return(new IpcResult(IpcResultStatus.ExecutionError, sb.ToString()));
            }

            BuildManifestData buildManifestData = m_buildManifestGenerator.GenerateBuildManifestData(cmd);

            return(IpcResult.Success(cmd.RenderResult(buildManifestData)));
        }
예제 #8
0
 public void TestOutputCountInBuildManifestData(string str, bool isValid)
 {
     XAssert.AreEqual(BuildManifestData.TryParse(str, out _), isValid);
 }
예제 #9
0
 [InlineData("string|1|not-int")]  // 3rd field not an int
 public void TestInvalidBuildManifestData(string str)
 {
     XAssert.IsFalse(BuildManifestData.TryParse(str, out _));
 }