Beispiel #1
0
        internal static void Increment(BuildMetadata buildMetadata, BuildTarget buildTarget)
        {
#if GOOGLE_DOC_CONNECTOR_PRO_ENABLED
            var firstOrDefault = BuildSystemSettings.Instance.MaskList.FirstOrDefault(m => Regex.IsMatch(buildMetadata.BranchName, m));

            s_LastBuildNumberAndroid = PlayerSettings.Android.bundleVersionCode;
            s_LastBuildNumberIOS     = PlayerSettings.iOS.buildNumber;

            if (firstOrDefault != null || !BuildSystemSettings.Instance.MaskList.Any())
            {
                try
                {
                    SaveBuildMetadata(buildMetadata, buildTarget);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
            else
            {
                Debug.Log($"Build Increment skipped, no matched branch mask found for the {buildMetadata.BranchName} branch. ");
            }
#endif
        }
Beispiel #2
0
        private string EncodeTemplateInner(Build build)
        {
            this.logger.LogInformation("Building build metadata");
            var buildMetadata = new BuildMetadata
            {
                VersionNumber         = 0,
                NewTemplate           = true,
                Header                = 14,
                PrimaryProfessionId   = build.Primary.Id,
                SecondaryProfessionId = build.Secondary.Id,
                AttributeCount        = build.Attributes.Count,
                AttributesIds         = build.Attributes.Select(attrEntry => attrEntry.Attribute.Id).ToList(),
                AttributePoints       = build.Attributes.Select(attrEntry => attrEntry.Points).ToList(),
                SkillIds              = build.Skills.Select(skill => skill.Id).ToList(),
                TailPresent           = true
            };

            this.logger.LogInformation("Encoding metadata into binary");
            var encodedBinary = BuildEncodedString(buildMetadata);
            int index         = 0;
            var encodedBase64 = new List <int>();

            while (index < encodedBinary.Length)
            {
                var subset = new string(encodedBinary.Skip(index).Take(6).ToArray());
                encodedBase64.Add(FromBitString(subset));
                index += 6;
            }

            var template = new string(encodedBase64.Select(b => DecodingLookupTable[b]).ToArray());

            return(template);
        }
    protected override void OnBuildInitialized()
    {
        base.OnBuildInitialized();
        var gitVersion = GitVersion(o => o.SetLogOutput(false).SetOutput(GitVersionOutput.json)).Result;

        Metadata = new BuildMetadata(gitVersion);
    }
Beispiel #4
0
        static void SaveBuildMetadata(BuildMetadata buildMetadata)
        {
            if (!Directory.Exists(BuildMetadataDirectoryPath))
            {
                Directory.CreateDirectory(BuildMetadataDirectoryPath);
            }

            AssetDatabase.CreateAsset(buildMetadata, k_BuildMetadataPath);
        }
        public BuildMetadata GetBuildMetadata()
        {
            if (m_BuildMetadata == null)
            {
                m_BuildMetadata = BuildProcessor.CreateBuildMetadata();
            }

            return(m_BuildMetadata);
        }
Beispiel #6
0
        private static string BuildEncodedString(BuildMetadata buildMetadata)
        {
            var stream = new EncodeCharStream();

            if (buildMetadata.NewTemplate || buildMetadata.Header == 14)
            {
                stream.Write(14, 4);
            }

            stream.Write(0, 4);

            var desiredProfessionIdLength = GetBitLength(new List <int> {
                buildMetadata.PrimaryProfessionId, buildMetadata.SecondaryProfessionId
            }.Max());
            var professionIdLength      = Math.Max((desiredProfessionIdLength - 4) / 2, 0);
            var finalProfessionIdLength = professionIdLength * 2 + 4;

            stream.Write(professionIdLength, 2);
            stream.Write(buildMetadata.PrimaryProfessionId, finalProfessionIdLength);
            stream.Write(buildMetadata.SecondaryProfessionId, finalProfessionIdLength);

            stream.Write(buildMetadata.AttributeCount, 4);
            var desiredAttributesLength = GetBitLength(buildMetadata.AttributesIds.Any() ? buildMetadata.AttributesIds.Max() : 0);
            var attributesLength        = Math.Max(desiredAttributesLength - 4, 0);
            var finalAttributesLength   = attributesLength + 4;

            stream.Write(attributesLength, 4);
            for (int i = 0; i < buildMetadata.AttributeCount; i++)
            {
                stream.Write(buildMetadata.AttributesIds[i], finalAttributesLength);
                stream.Write(buildMetadata.AttributePoints[i], 4);
            }

            var desiredSkillsLength = GetBitLength(buildMetadata.SkillIds.Max());
            var skillsLength        = Math.Max(desiredSkillsLength - 8, 0);
            var finalSkillsLength   = skillsLength + 8;

            stream.Write(skillsLength, 4);
            for (int i = 0; i < 8; i++)
            {
                stream.Write(buildMetadata.SkillIds[i], finalSkillsLength);
            }

            if (buildMetadata.TailPresent)
            {
                stream.Write(0, 1);
            }

            return(stream.GetEncodedString());
        }
Beispiel #7
0
        private static BuildMetadata ParseEncodedTemplate(string template)
        {
            var curedTemplate = template.Trim();

            var buildMetadata = new BuildMetadata
            {
                Base64Decoded = template.Select(c => DecodingLookupTable.IndexOf(c)).ToList(),
            };

            buildMetadata.BinaryDecoded = buildMetadata.Base64Decoded.Select(b => ToBitString(b)).ToList();

            var stream = new DecodeCharStream(buildMetadata.BinaryDecoded.ToArray());

            buildMetadata.Header = stream.Read(4);
            if (buildMetadata.Header == 14)
            {
                buildMetadata.VersionNumber = stream.Read(4);
                buildMetadata.NewTemplate   = true;
            }
            else
            {
                buildMetadata.VersionNumber = buildMetadata.Header;
                buildMetadata.NewTemplate   = false;
            }

            buildMetadata.ProfessionIdLength    = stream.Read(2) * 2 + 4;
            buildMetadata.PrimaryProfessionId   = stream.Read(buildMetadata.ProfessionIdLength);
            buildMetadata.SecondaryProfessionId = stream.Read(buildMetadata.ProfessionIdLength);
            buildMetadata.AttributeCount        = stream.Read(4);
            buildMetadata.AttributesLength      = stream.Read(4) + 4;
            for (int i = 0; i < buildMetadata.AttributeCount; i++)
            {
                buildMetadata.AttributesIds.Add(stream.Read(buildMetadata.AttributesLength));
                buildMetadata.AttributePoints.Add(stream.Read(4));
            }

            buildMetadata.SkillsLength = stream.Read(4) + 8;
            for (int i = 0; i < 8; i++)
            {
                buildMetadata.SkillIds.Add(stream.Read(buildMetadata.SkillsLength));
            }

            if (stream.Position < stream.Length - 1)
            {
                buildMetadata.TailPresent = true;
            }

            return(buildMetadata);
        }
Beispiel #8
0
        public void CommitDateFormatTest(string format, string expectedOutcome)
        {
            var date          = new DateTime(2017, 10, 6);
            var buildMetadata = new BuildMetadata(
                0, "master",
                "3139d4eeb044f46057693473eacc2655b3b27e7d",
                new DateTimeOffset(date, TimeSpan.Zero)); // assume time zone is UTC

            var config = new EffectiveConfiguration(
                AssemblyVersioningScheme.MajorMinorPatch,
                AssemblyFileVersioningScheme.MajorMinorPatch,
                "", VersioningMode.ContinuousDelivery, "", "", "",
                IncrementStrategyType.Inherit,
                "", true, "", "", false, "", "", "", "",
                CommitMessageIncrementMode.Enabled, 4, 4,
                Enumerable.Empty <IVersionFilter>(), false, true, format);

            var version = new SemanticVersion(1, 0, 0, null, buildMetadata);
            var values  = new VersionFormatValues(version, config);

            Assert.That(values.CommitDate, Is.EqualTo(expectedOutcome));
        }
Beispiel #9
0
 public BuildMetadataJSON(BuildMetadata metadata) : base(metadata)
 {
 }
Beispiel #10
0
        static void SaveBuildMetadata(BuildMetadata buildMetadata, BuildTarget buildTarget)
        {
            foreach (var extraField in BuildSystemSettings.Instance.ExtraFields)
            {
                s_Headers.Add(extraField.Name);
            }

            if (string.IsNullOrEmpty(BuildSystemSettings.Instance.SpreadsheetId))
            {
                Debug.LogError("Versions Spreadsheet Id is empty");
                return;
            }

            var spreadsheet = new Spreadsheet(BuildSystemSettings.Instance.SpreadsheetId);

            spreadsheet.Load();
            if (spreadsheet.SyncErrorMassage != null)
            {
                Debug.LogError(spreadsheet.SyncErrorMassage);
                throw new Exception(spreadsheet.SyncErrorMassage);
            }

            var sheetName     = $"{buildMetadata.Version} - {buildTarget}";
            var versionsSheet = spreadsheet.Sheets.FirstOrDefault(sh => sheetName.Equals(sh.Name));
            var rangeAppend   = $"{sheetName}!A:K";
            var buildNumber   = 0;

            if (versionsSheet == null)
            {
                spreadsheet.CreateGoogleSheet(sheetName);
                spreadsheet.AppendGoogleCell(rangeAppend, s_Headers);
                if (spreadsheet.SyncErrorMassage != null)
                {
                    Debug.LogError(spreadsheet.SyncErrorMassage);
                    throw new Exception(spreadsheet.SyncErrorMassage);
                }
            }
            else
            {
                var cell = versionsSheet.GetCell(versionsSheet.Rows.Count() - 1, 0);
                buildNumber = cell != null
                    ? versionsSheet.GetCell(versionsSheet.Rows.Count() - 1, 0).GetValue <int>()
                    : 0;
            }

            buildMetadata.BuildNumber = buildNumber + 1;
            Debug.LogWarning("Setting build number to " + buildMetadata.BuildNumber);
            PlayerSettings.Android.bundleVersionCode = buildMetadata.BuildNumber;
            PlayerSettings.iOS.buildNumber           = buildMetadata.BuildNumber.ToString();


            var commitValue = buildMetadata.CommitShortHash;

            if (!string.IsNullOrEmpty(BuildSystemSettings.Instance.GitHubRepository))
            {
                commitValue = $"=HYPERLINK(\"https://github.com/{BuildSystemSettings.Instance.GitHubRepository}/commit/{buildMetadata.CommitHash}\",\"{buildMetadata.CommitShortHash}\")";
            }

            if (UnityCloudBuildHooks.IsRunningOnUnityCloud)
            {
                var manifest = (TextAsset)Resources.Load("UnityCloudBuildManifest.json");
                if (manifest != null)
                {
                    var manifestDict = Json.Deserialize(manifest.text) as Dictionary <string, object>;
                    foreach (var kvp in manifestDict)
                    {
                        // Be sure to check for null values!
                        var value = kvp.Value != null?kvp.Value.ToString() : string.Empty;

                        foreach (var extraField in BuildSystemSettings.Instance.ExtraFields)
                        {
                            extraField.Value = extraField.Value.Replace("{" + kvp.Key + "}", value);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("[IncrementBuildNumber] UnityCloudBuildManifest.json not found");
                }
            }

            var appendList = new List <object>
            {
                buildMetadata.BuildNumber,
                buildMetadata.Version,
                buildMetadata.MachineName,
                buildMetadata.BranchName,
                buildMetadata.CommitMessage,
                commitValue,
                buildMetadata.BuildTime.ToString("G"),
                buildMetadata.CommitTime.ToString("G")
            };

            foreach (var extraField in BuildSystemSettings.Instance.ExtraFields)
            {
                appendList.Add(extraField.Value);
            }

            spreadsheet.AppendGoogleCell(rangeAppend, appendList);
            if (spreadsheet.SyncErrorMassage != null)
            {
                Debug.LogError(spreadsheet.SyncErrorMassage);
            }
        }
Beispiel #11
0
 public BuildPipeline(string name, BuildMetadata metadata, BuildDefinition definition)
 {
     Name       = name;
     Metadata   = metadata;
     Definition = definition;
 }
 /// <summary>
 /// The default hash function.
 /// </summary>
 /// <returns>A hash code for the current object.</returns>
 public override int GetHashCode()
 {
     return(Major ^ Minor ^ Patch ^ (!string.IsNullOrEmpty(Prerelease) ? Prerelease.GetHashCode() : 0) ^
            (!string.IsNullOrEmpty(BuildMetadata) ? BuildMetadata.GetHashCode() : 0));
 }
Beispiel #13
0
 public async Task SaveAsync(BuildMetadata entity)
 {
     buildDb.Update(entity);
     await buildDb.SaveChangesAsync();
 }