Пример #1
0
        /// <summary>
        /// Builds the Releases in the Contrib repository.
        /// Depends on:
        ///     - Compiled BaseLibrary
        ///     - Updated Sample repository
        ///     - Existing release tag name
        /// </summary>
        /// <returns>Edited changelog.</returns>
        private static string BuildContribRelease(string tag,
                                                  string changelog,
                                                  IEnumerable <Project> baseLibrary,
                                                  IEnumerable <Project> allProjects,
                                                  Project serviceGenerator,
                                                  out string zipDir)
        {
            CommandLine.WriteLine("{{white}} =======================================");
            CommandLine.WriteLine("{{white}} Building Contrib-Release");
            CommandLine.WriteLine("{{white}} =======================================");

            string releaseDir = Contrib.Combine(tag);
            string currentDir = Contrib.Combine("Current");
            string stableDir  = Contrib.Combine("Stable");

            // Clear existing directories.
            DirUtils.ClearOrCreateDir(releaseDir);
            DirUtils.ClearOrCreateDir(currentDir);
            if (Arguments.IsStableRelease)
            {
                DirUtils.ClearOrCreateDir(stableDir);
            }

            // Create the <current> release
            string genDir = Path.Combine(currentDir, "Generated");

            Directory.CreateDirectory(genDir);

            #region Current/Generated/Lib
            string libDir = Path.Combine(genDir, "Lib");
            CommandLine.WriteAction("Generating dir: " + DirUtils.GetRelativePath(libDir, Contrib.WorkingDirectory));
            Directory.CreateDirectory(libDir);
            {
                // Copy all third party dlls into this directory.
                foreach (string file in ThirdPartyFiles)
                {
                    DirUtils.CopyFile(file, libDir);
                }

                // Copy all release dlls to this directory.
                foreach (Project project in baseLibrary)
                {
                    project.CopyTo(libDir);
                }
            }
            #endregion

            #region Current/Generated/Bin - and - Current/Generated/Source
            string binDir    = Path.Combine(genDir, "Bin");
            string sourceDir = Path.Combine(genDir, "Source");
            CommandLine.WriteAction("Generating dir: " + DirUtils.GetRelativePath(binDir, Contrib.WorkingDirectory));
            CommandLine.WriteAction("Generating dir: " + DirUtils.GetRelativePath(sourceDir, Contrib.WorkingDirectory));
            Directory.CreateDirectory(binDir);
            Directory.CreateDirectory(sourceDir);
            {
                // Iterate through all services, and put them into the right directory
                string[] toBin = new[] { ".dll", ".xml", ".pdb" };
                string[] toSrc = new[] { ".cs" };

                foreach (string file in Directory.GetFiles(ServiceDir, "*"))
                {
                    string fileName = Path.GetFileName(file);
                    CommandLine.WriteResult("File", fileName);
                    string ext = Path.GetExtension(fileName).ToLower();
                    if (toSrc.Contains(ext)) // Copy this file into the "Source" directory.
                    {
                        DirUtils.CopyFile(file, sourceDir);
                    }
                    if (toBin.Contains(ext)) // Copy this file into the "Binary" directory.
                    {
                        // Get the folder name by looking at the .dll assembly info.
                        string id          = FileVersionInfo.GetVersionInfo(Path.ChangeExtension(file, ".dll")).ProductName;
                        string serviceName = id.Split(':')[0];                           // "buzz:v1" -> "buzz"
                        string folderName  = serviceName.ToUpperFirstChar() + "Service"; // "buzz" -> "BuzzService"

                        // Copy the file there.
                        string folder = Path.Combine(binDir, folderName);
                        DirUtils.CopyFile(file, folder);
                    }
                }
            }

            #endregion

            #region Current/ZipFiles
            string zipFilesDir = Path.Combine(genDir, "ZipFiles");
            CommandLine.WriteAction("Generating dir: " + DirUtils.GetRelativePath(zipFilesDir, Contrib.WorkingDirectory));
            Directory.CreateDirectory(zipFilesDir);
            {
                // Source.zip
                foreach (Project project in allProjects)
                {
                    project.Clean();
                }
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Source.zip")))
                {
                    zip.AddDirectory(Default.WorkingDirectory, "");
                    zip.RemoveDirectory(".hg");
                    zip.RemoveFile(".hgtags");
                    zip.RemoveFile(".hgignore");
                }

                // Binary.zip
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Binary.zip")))
                {
                    zip.AddDirectory(binDir, "Services");
                    zip.AddDirectory(libDir, "Lib");
                }

                // Samples.zip
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Samples.zip")))
                {
                    zip.AddDirectory(Samples.WorkingDirectory, "");
                    zip.RemoveDirectory(".hg");
                    zip.RemoveFile(".hgtags");
                    zip.RemoveFile(".hgignore");
                }
            }
            #endregion

            #region Current/ReleaseNotes.txt
            CommandLine.WriteAction("Writing file...");
            string changelogFile = Path.Combine(currentDir, "ReleaseNotes.txt");
            using (var writer = new StreamWriter(changelogFile, false))
            {
                writer.WriteLine(changelog);
            }
            #endregion

            // Open the created changelog.
            CommandLine.WriteAction("Showing result...");
            Process.Start(changelogFile).WaitForExit();

            // Copy the content to the <tagname> release directory.
            DirUtils.CopyFiles(currentDir, releaseDir);
            if (Arguments.IsStableRelease)
            {
                DirUtils.CopyFiles(currentDir, stableDir);
            }

            // Rename the zips in the named release.
            // Example: Binary.zip -> google-api-dotnet-client-1.0.0-beta.Binary.zip
            string fileFormat = "google-api-dotnet-client-" + ExtractTagVersionAndName(tag) + ".{0}";
            zipDir = zipFilesDir.Replace(currentDir, releaseDir);
            foreach (string file in Directory.GetFiles(zipDir, "*.zip"))
            {
                string dir     = Path.GetDirectoryName(file);
                string newFile = string.Format(fileFormat, Path.GetFileName(file).ToLower());
                File.Move(file, Path.Combine(dir, newFile));
            }

            CommandLine.WriteLine();
            return(File.ReadAllText(changelogFile));
        }
Пример #2
0
        /// <summary>
        /// Builds the Releases in the Contrib repository.
        /// Depends on:
        ///     - Compiled BaseLibrary
        ///     - Updated Sample repository
        ///     - Existing release tag name
        /// </summary>
        /// <returns>Edited changelog.</returns>
        private static string BuildContribRelease(string tag,
                                                  string changelog,
                                                  IEnumerable <Project> baseLibrary,
                                                  IEnumerable <Project> allProjects,
                                                  Project serviceGenerator,
                                                  out string zipDir)
        {
            CommandLine.WriteLine("{{white}} =======================================");
            CommandLine.WriteLine("{{white}} Building Contrib-Release");
            CommandLine.WriteLine("{{white}} =======================================");

            string releaseDir = Contrib.Combine(tag);
            string currentDir = Contrib.Combine("Current");

            // Clear existing directories.
            DirUtils.ClearOrCreateDir(releaseDir);
            // TODO(peleyal): remove currentDir eventually (after at least one or two releases)
            DirUtils.ClearOrCreateDir(currentDir);

            // Create the <current> release
            string genDir = Path.Combine(currentDir, "Generated");

            Directory.CreateDirectory(genDir);

            #region Current/Generated/Bin
            string binDir = Path.Combine(genDir, "Bin");
            CommandLine.WriteAction("Generating dir: " + DirUtils.GetRelativePath(binDir, Contrib.WorkingDirectory));
            Directory.CreateDirectory(binDir);
            {
                // Copy all third party dlls into this directory.
                foreach (string file in ThirdPartyFiles)
                {
                    DirUtils.CopyFile(file, binDir);
                }

                // Copy all release dlls to this directory.
                foreach (Project project in baseLibrary)
                {
                    project.CopyTo(binDir);
                }
            }
            #endregion

            #region Current/ZipFiles
            string zipFilesDir = Path.Combine(genDir, "ZipFiles");
            CommandLine.WriteAction("Generating dir: " +
                                    DirUtils.GetRelativePath(zipFilesDir, Contrib.WorkingDirectory));
            Directory.CreateDirectory(zipFilesDir);
            {
                // clean all projects
                foreach (Project project in allProjects)
                {
                    project.Clean();
                }

                // Source.zip
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Source.zip")))
                {
                    zip.AddDirectory(Default.WorkingDirectory, "");
                    zip.RemoveDirectory(".hg");
                    zip.RemoveFile(".hgtags");
                    zip.RemoveFile(".hgignore");
                }

                // Binary.zip
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Binary.zip")))
                {
                    zip.AddDirectory(binDir, "");
                }

                // Samples.zip
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Samples.zip")))
                {
                    zip.AddDirectory(Samples.WorkingDirectory, "");
                    zip.RemoveDirectory(".hg");
                    zip.RemoveFile(".hgtags");
                    zip.RemoveFile(".hgignore");
                }
            }
            #endregion

            #region Current/ReleaseNotes.txt
            CommandLine.WriteAction("Writing file...");
            string changelogFile = Path.Combine(currentDir, "ReleaseNotes.txt");
            using (var writer = new StreamWriter(changelogFile, false))
            {
                writer.WriteLine(changelog);
            }
            #endregion

            // Open the created changelog.
            CommandLine.WriteAction("Showing result...");
            Process.Start(changelogFile).WaitForExit();

            // Copy the content to the <tagname> release directory.
            DirUtils.CopyFiles(currentDir, releaseDir);

            // Rename the zips in the named release.
            // Example: Binary.zip -> google-api-dotnet-client-1.0.0-beta.Binary.zip
            string fileFormat = "google-api-dotnet-client-" + tag + ".{0}";
            zipDir = zipFilesDir.Replace(currentDir, releaseDir);
            foreach (string file in Directory.GetFiles(zipDir, "*.zip"))
            {
                string dir     = Path.GetDirectoryName(file);
                string newFile = string.Format(fileFormat, Path.GetFileName(file).ToLower());
                File.Move(file, Path.Combine(dir, newFile));
            }

            CommandLine.WriteLine();
            return(File.ReadAllText(changelogFile));
        }