コード例 #1
0
        public void Add(string stepNameAndVersion)
        {
            var index = new[] { ':', '=' }.Select(s => stepNameAndVersion.IndexOf(s)).Where(i => i >= 0).OrderBy(i => i).FirstOrDefault();

            if (index <= 0)
            {
                throw new CommandException("The package argument '" + stepNameAndVersion + "' does not use expected format of : {Step Name}:{Version}");
            }

            var key   = stepNameAndVersion.Substring(0, index);
            var value = (index >= stepNameAndVersion.Length - 1) ? string.Empty : stepNameAndVersion.Substring(index + 1);

            if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
            {
                throw new CommandException("The package argument '" + stepNameAndVersion + "' does not use expected format of : {Step Name}:{Version}");
            }

            SemanticVersion version;

            if (!SemanticVersion.TryParse(value, out version))
            {
                throw new CommandException("The version portion of the package constraint '" + stepNameAndVersion + "' is not a valid semantic version number.");
            }

            Add(key, value);
        }
コード例 #2
0
        public void Add(string stepNameAndVersion)
        {
            var split = stepNameAndVersion.Split(Delimiters);

            if (split.Length < 2)
            {
                throw new CommandException("The package argument '" + stepNameAndVersion + "' does not use expected format of : {Step Name}:{Version}");
            }

            var stepOrPackageId      = split[0];
            var packageReferenceName = split.Length > 2 ? split[1] : null;
            var version = split.Length > 2 ? split[2] : split[1];

            if (string.IsNullOrWhiteSpace(stepOrPackageId) || string.IsNullOrWhiteSpace(version))
            {
                throw new CommandException("The package argument '" + stepNameAndVersion + "' does not use expected format of : {Step Name}:{Version}");
            }

            if (!SemanticVersion.TryParse(version, out var parsedVersion))
            {
                throw new CommandException("The version portion of the package constraint '" + stepNameAndVersion + "' is not a valid semantic version number.");
            }

            Add(stepOrPackageId, packageReferenceName, version);
        }
コード例 #3
0
ファイル: PackCommand.cs プロジェクト: OctopusDeploy/Octo.exe
        public PackCommand(ILogger log, IOctopusFileSystem fileSystem)
        {
            this.log = log;
            this.fileSystem = fileSystem;

            var common = optionGroups.For("Advanced options");
            common.Add("include=", "[Optional, Multiple] Add a file pattern to include, relative to the base path e.g. /bin/*.dll - if none are specified, defaults to **", v => includes.Add(v));
            common.Add("overwrite", "[Optional] Allow an existing package file of the same ID/version to be overwritten", v => overwrite = true);

            var nuget = optionGroups.For("NuGet packages");
            nuget.Add("author=", "[Optional, Multiple] Add an author to the package metadata; defaults to the current user", v => authors.Add(v));
            nuget.Add("title=", "[Optional] The title of the package", v => title = v);
            nuget.Add("description=", "[Optional] A description of the package; defaults to a generic description", v => description = v);
            nuget.Add("releaseNotes=", "[Optional] Release notes for this version of the package", v => releaseNotes = v);
            nuget.Add("releaseNotesFile=", "[Optional] A file containing release notes for this version of the package", v => releaseNotesFile = v);
            
            var basic = optionGroups.For("Basic options");
            basic.Add("id=", "The ID of the package; e.g. MyCompany.MyApp", v => id = v);
            basic.Add("format=", "Package format. Options are: NuPkg, Zip. Defaults to NuPkg, though we recommend Zip going forward.", fmt => packageBuilder = SelectFormat(fmt));
            basic.Add("version=", "[Optional] The version of the package; must be a valid SemVer; defaults to a timestamp-based version", v => version = string.IsNullOrWhiteSpace(v) ? null : new SemanticVersion(v));
            basic.Add("outFolder=", "[Optional] The folder into which the generated NUPKG file will be written; defaults to '.'", v => outFolder = v);
            basic.Add("basePath=", "[Optional] The root folder containing files and folders to pack; defaults to '.'", v => basePath = v);

            packageBuilder = SelectFormat("nupkg");
        }
コード例 #4
0
 public void Default(string packageVersion)
 {
     try
     {
         SemanticVersion.Parse(packageVersion);
         defaultVersion = packageVersion;
     }
     catch (ArgumentException)
     {
         if (packageVersion.Contains(":"))
         {
             throw new ArgumentException("Invalid package version format. Use the package parameter if you need to specify the step name and version.");
         }
         throw;
     }
 }
コード例 #5
0
        public void Add(string stepName, string packageVersion)
        {
            string current;

            if (stepNameToVersion.TryGetValue(stepName, out current))
            {
                var newVersion     = SemanticVersion.Parse(packageVersion);
                var currentVersion = SemanticVersion.Parse(current);
                if (newVersion < currentVersion)
                {
                    return;
                }
            }

            stepNameToVersion[stepName] = packageVersion;
        }
コード例 #6
0
        public void Add(string stepName, string packageReferenceName, string packageVersion)
        {
            // Double wild card == default value
            if (stepName == WildCard && packageReferenceName == WildCard)
            {
                Default(packageVersion);
                return;
            }

            var key = new PackageKey(stepName, packageReferenceName ?? string.Empty);

            if (stepNameToVersion.TryGetValue(key, out var current))
            {
                var newVersion     = SemanticVersion.Parse(packageVersion);
                var currentVersion = SemanticVersion.Parse(current);
                if (newVersion < currentVersion)
                {
                    return;
                }
            }

            stepNameToVersion[key] = packageVersion;
        }
コード例 #7
0
        public Task Execute(string[] commandLineArguments)
        {
            return(Task.Run(() =>
            {
                optionGroups.Parse(commandLineArguments);

                if (string.IsNullOrWhiteSpace(id))
                {
                    throw new CommandException("An ID is required");
                }

                if (includes.All(string.IsNullOrWhiteSpace))
                {
                    includes.Add("**");
                }

                if (string.IsNullOrWhiteSpace(basePath))
                {
                    basePath = Path.GetFullPath(Directory.GetCurrentDirectory());
                }

                if (string.IsNullOrWhiteSpace(outFolder))
                {
                    outFolder = Path.GetFullPath(Directory.GetCurrentDirectory());
                }

                if (version == null)
                {
                    var now = DateTime.Now;
                    version = SemanticVersion.Parse($"{now.Year}.{now.Month}.{now.Day}.{now.Hour*10000 + now.Minute*100 + now.Second}");
                }

                if (authors.All(string.IsNullOrWhiteSpace))
                {
                    authors.Add(Environment.GetEnvironmentVariable("USERNAME") + "@" + Environment.GetEnvironmentVariable("USERDOMAIN"));
                }

                if (string.IsNullOrWhiteSpace(description))
                {
                    description = "A deployment package created from files on disk.";
                }

                string allReleaseNotes = null;
                if (!string.IsNullOrWhiteSpace(releaseNotesFile))
                {
                    if (!File.Exists(releaseNotesFile))
                    {
                        log.Warning("The release notes file '{Path:l}' could not be found", releaseNotesFile);
                    }
                    else
                    {
                        allReleaseNotes = fileSystem.ReadFile(releaseNotesFile);
                    }
                }

                if (!string.IsNullOrWhiteSpace(releaseNotes))
                {
                    if (allReleaseNotes != null)
                    {
                        allReleaseNotes += Environment.NewLine + releaseNotes;
                    }
                    else
                    {
                        allReleaseNotes = releaseNotes;
                    }
                }

                if (string.IsNullOrWhiteSpace(version.OriginalString))
                {
                    throw new Exception("Somehow we created a SemanticVersion without the OriginalString value being preserved. We want to use the OriginalString so we can preserve the version as intended by the caller.");
                }

                var metadata = new ManifestMetadata
                {
                    Id = id,
                    Authors = authors,
                    Description = description,
                    Version = NuGetVersion.Parse(version.OriginalString)
                };

                if (!string.IsNullOrWhiteSpace(allReleaseNotes))
                {
                    metadata.ReleaseNotes = allReleaseNotes;
                }

                if (!string.IsNullOrWhiteSpace(title))
                {
                    metadata.Title = title;
                }


                if (verbose)
                {
                    log.Information("Verbose logging");
                }
                log.Information("Packing {id:l} version {Version}...", id, version);

                packageBuilder.BuildPackage(basePath, includes, metadata, outFolder, overwrite, verbose);

                log.Information("Done.");
            }));
        }
コード例 #8
0
        public PackCommand(ILogger log, IOctopusFileSystem fileSystem)
        {
            this.log        = log;
            this.fileSystem = fileSystem;

            var common = optionGroups.For("Advanced options");

            common.Add("include=", "[Optional, Multiple] Add a file pattern to include, relative to the base path e.g. /bin/*.dll - if none are specified, defaults to **", v => includes.Add(v));
            common.Add("overwrite", "[Optional] Allow an existing package file of the same ID/version to be overwritten", v => overwrite = true);

            var nuget = optionGroups.For("NuGet packages");

            nuget.Add("author=", "[Optional, Multiple] Add an author to the package metadata; defaults to the current user", v => authors.Add(v));
            nuget.Add("title=", "[Optional] The title of the package", v => title = v);
            nuget.Add("description=", "[Optional] A description of the package; defaults to a generic description", v => description = v);
            nuget.Add("releaseNotes=", "[Optional] Release notes for this version of the package", v => releaseNotes = v);
            nuget.Add("releaseNotesFile=", "[Optional] A file containing release notes for this version of the package", v => releaseNotesFile = v);

            var basic = optionGroups.For("Basic options");

            basic.Add("id=", "The ID of the package; e.g. MyCompany.MyApp", v => id = v);
            basic.Add("format=", "Package format. Options are: NuPkg, Zip. Defaults to NuPkg, though we recommend Zip going forward", fmt => packageBuilder = SelectFormat(fmt));
            basic.Add("version=", "[Optional] The version of the package; must be a valid SemVer; defaults to a timestamp-based version", v => version      = string.IsNullOrWhiteSpace(v) ? null : new SemanticVersion(v));
            basic.Add("outFolder=", "[Optional] The folder into which the generated NUPKG file will be written; defaults to '.'", v => { v.CheckForIllegalPathCharacters(nameof(outFolder)); outFolder = v; });
            basic.Add("basePath=", "[Optional] The root folder containing files and folders to pack; defaults to '.'", v => { v.CheckForIllegalPathCharacters(nameof(basePath)); basePath = v; });
            basic.Add("verbose", "[Optional] verbose output", v => verbose = true);

            packageBuilder = SelectFormat("nupkg");
        }
コード例 #9
0
ファイル: PackCommand.cs プロジェクト: stjordanis/OctopusCLI
        public PackCommand(IOctopusFileSystem fileSystem, ICommandOutputProvider commandOutputProvider) : base(commandOutputProvider)
        {
            this.fileSystem = fileSystem;

            var common = Options.For("Advanced options");

            common.Add <string>("include=", "[Optional, Multiple] Add a file pattern to include, relative to the base path e.g. /bin/*.dll - if none are specified, defaults to **.", v => includes.Add(v), allowsMultiple: true);
            common.Add <bool>("overwrite", "[Optional] Allow an existing package file of the same ID/version to be overwritten.", v => overwrite = true);

            var zip = Options.For("Zip packages");

            zip.Add <PackageCompressionLevel>("compressionLevel=", $"[Optional] Sets the compression level of the package. Valid values are {Enum.GetNames(typeof(PackageCompressionLevel)).ReadableJoin()}. Default is {DefaultPackageCompressionLevel}.", c => packageCompressionLevel = c);

            var nuget = Options.For("NuGet packages");

            nuget.Add <string>("author=", "[Optional, Multiple] Add an author to the package metadata; defaults to the current user.", v => authors.Add(v), allowsMultiple: true);
            nuget.Add <string>("title=", "[Optional] The title of the package.", v => title = v);
            nuget.Add <string>("description=", "[Optional] A description of the package; defaults to a generic description.", v => description = v);
            nuget.Add <string>("releaseNotes=", "[Optional] Release notes for this version of the package.", v => releaseNotes = v);
            nuget.Add <string>("releaseNotesFile=", "[Optional] A file containing release notes for this version of the package.", v => releaseNotesFile = v);

            var basic = Options.For("Basic options");

            basic.Add <string>("id=", "The ID of the package; e.g. MyCompany.MyApp.", v => id = v);
            basic.Add <PackageFormat>("format=", $"Package format. Valid values are {supportedPackageFormats}. Default is {DefaultPackageFormat}, though we recommend {RecommendedPackageFormat} going forward.", fmt => packageBuilder = SelectFormat(fmt));
            basic.Add <string>("version=", "[Optional] The version of the package; must be a valid SemVer; defaults to a timestamp-based version.", v => version = string.IsNullOrWhiteSpace(v) ? null : new SemanticVersion(v));
            basic.Add <string>("outFolder=", "[Optional] The folder into which the generated NuPkg file will be written; defaults to '.'.", v => { v.CheckForIllegalPathCharacters(nameof(outFolder)); outFolder = v; });
            basic.Add <string>("basePath=", "[Optional] The root folder containing files and folders to pack; defaults to '.'.", v => { v.CheckForIllegalPathCharacters(nameof(basePath)); basePath = v; });
            basic.Add <bool>("verbose", "[Optional] verbose output.", v => verbose = true);
            basic.AddLogLevelOptions();

            packageBuilder = SelectFormat(DefaultPackageFormat);
        }
コード例 #10
0
ファイル: PackCommand.cs プロジェクト: OctopusDeploy/Octo.exe
        public Task Execute(string[] commandLineArguments)
        {
            return Task.Run(() =>
            {
                optionGroups.Parse(commandLineArguments);

                if (string.IsNullOrWhiteSpace(id))
                    throw new CommandException("An ID is required");

                if (includes.All(string.IsNullOrWhiteSpace))
                    includes.Add("**");

                if (string.IsNullOrWhiteSpace(basePath))
                    basePath = Path.GetFullPath(Directory.GetCurrentDirectory());

                if (string.IsNullOrWhiteSpace(outFolder))
                    outFolder = Path.GetFullPath(Directory.GetCurrentDirectory());

                if (version == null)
                {
                    var now = DateTime.Now;
                    version = SemanticVersion.Parse($"{now.Year}.{now.Month}.{now.Day}.{now.Hour*10000 + now.Minute*100 + now.Second}");
                }

                if (authors.All(string.IsNullOrWhiteSpace))
                    authors.Add(Environment.GetEnvironmentVariable("USERNAME") + "@" + Environment.GetEnvironmentVariable("USERDOMAIN"));

                if (string.IsNullOrWhiteSpace(description))
                    description = "A deployment package created from files on disk.";

                string allReleaseNotes = null;
                if (!string.IsNullOrWhiteSpace(releaseNotesFile))
                {
                    if (!File.Exists(releaseNotesFile))
                        log.Warning("The release notes file '{Path:l}' could not be found", releaseNotesFile);
                    else
                        allReleaseNotes = fileSystem.ReadFile(releaseNotesFile);
                }

                if (!string.IsNullOrWhiteSpace(releaseNotes))
                {
                    if (allReleaseNotes != null)
                        allReleaseNotes += Environment.NewLine + releaseNotes;
                    else
                        allReleaseNotes = releaseNotes;
                }

                if (string.IsNullOrWhiteSpace(version.OriginalString))
                {
                    throw new Exception("Somehow we created a SemanticVersion without the OriginalString value being preserved. We want to use the OriginalString so we can preserve the version as intended by the caller.");
                }

                var metadata = new ManifestMetadata
                {
                    Id = id,
                    Authors = authors,
                    Description = description,
                    Version = NuGetVersion.Parse(version.OriginalString)
                };

                if (!string.IsNullOrWhiteSpace(allReleaseNotes))
                    metadata.ReleaseNotes = allReleaseNotes;

                if (!string.IsNullOrWhiteSpace(title))
                    metadata.Title = title;

                log.Information("Packing {PackageId:l} version {Version}...", id, version);

                packageBuilder.BuildPackage(basePath, includes, metadata, outFolder, overwrite);

                log.Information("Done.");
            });
        }