/// <summary> /// Pushes a version lightweight tag to the 'origin' remote. /// </summary> /// <param name="m">The monitor to use.</param> /// <param name="v">The version to push.</param> /// <returns>True on success, false on error.</returns> public bool PushVersionTag(IActivityMonitor m, SVersion v) { var sv = 'v' + v.ToString(); using (m.OpenInfo($"Pushing tag {sv} to remote for {SubPath}.")) { try { Remote remote = Git.Network.Remotes["origin"]; var options = new PushOptions() { CredentialsProvider = (url, user, cred) => ProtoGitFolder.PATCredentialsHandler(m) }; var exists = Git.Tags[sv]; if (exists == null) { m.Error($"Version Tag {sv} does not exist in {SubPath}."); return(false); } Git.Network.Push(remote, exists.CanonicalName, options); return(true); } catch (Exception ex) { m.Error($"PushVersionTags failed ({sv} on {SubPath}).", ex); return(false); } } }
/// <summary> /// Sets a version lightweight tag on the current head. /// An error is logged if the version tag already exists on another commit that the head. /// </summary> /// <param name="m">The monitor to use.</param> /// <param name="v">The version to set.</param> /// <returns>True on success, false on error.</returns> public bool SetVersionTag(IActivityMonitor m, SVersion v) { var sv = 'v' + v.ToString(); try { var exists = Git.Tags[sv]; if (exists != null && exists.PeeledTarget == Git.Head.Tip) { m.Info($"Version Tag {sv} is already set."); return(true); } Git.ApplyTag(sv); m.Info($"Set Version tag {sv} on {CurrentBranchName}."); return(true); } catch (Exception ex) { m.Error($"SetVersionTag {sv} on {CurrentBranchName} failed.", ex); return(false); } }
/// <summary> /// Removes a version lightweight tag from the repository. /// If the tag /// </summary> /// <param name="m">The monitor to use.</param> /// <param name="v">The version to remove.</param> /// <returns>True on success, false on error.</returns> public bool ClearVersionTag(IActivityMonitor m, SVersion v) { var sv = 'v' + v.ToString(); try { if (Git.Tags[sv] == null) { m.Info($"Tag '{sv}' in {SubPath} not found (cannot remove it)."); } else { Git.Tags.Remove(sv); m.Info($"Removing Version tag '{sv}' from {SubPath}."); } return(true); } catch (Exception ex) { m.Error($"ClearVersionTag {sv} on {SubPath} failed.", ex); return(false); } }
public static NPMDep CreateNPMDepMinVersion(string name, ArtifactDependencyKind kind, SVersion minVersion) { return(new NPMDep(name, NPMVersionDependencyType.MinVersion, kind, ">=" + minVersion.ToString(), minVersion)); }
/// <summary> /// Sets a package reference and returns the number of changes. /// </summary> /// <param name="m">The monitor.</param> /// <param name="frameworks"> /// Frameworks that applies to the reference. Must not be empty. /// Can be this project's <see cref="TargetFrameworks"/> to update the package reference regardless of the framework. /// </param> /// <param name="packageId">The package identifier.</param> /// <param name="version">The new version to set.</param> /// <param name="addIfNotExists">True to add the reference. By default, it is only updated.</param> /// <param name="preserveExisting">True to keep any existing version.</param> /// <param name="throwProjectDependendencies">False to not challenge ProjectReferences.</param> /// <returns>The number of changes.</returns> public int SetPackageReferenceVersion( IActivityMonitor m, CKTrait frameworks, string packageId, SVersion version, bool addIfNotExists = false, bool preserveExisting = false, bool throwProjectDependendencies = true) { if (!_dependencies.IsInitialized) { throw new InvalidOperationException("Invalid Project."); } if (frameworks.IsEmpty) { throw new ArgumentException("Must not be empty.", nameof(frameworks)); } var actualFrameworks = TargetFrameworks.Intersect(frameworks); if (actualFrameworks.IsEmpty) { throw new ArgumentException($"No {frameworks} in {TargetFrameworks}.", nameof(frameworks)); } if (throwProjectDependendencies && _dependencies.Projects.Any(p => p.TargetProject.ProjectName == packageId)) { throw new ArgumentException($"Package {packageId} is already a ProjectReference.", nameof(packageId)); } var sV = version.ToString(); int changeCount = 0; CKTrait pFrameworks = null; foreach (var p in _dependencies.Packages.Where(p => p.PackageId == packageId && !(pFrameworks = p.Frameworks.Intersect(actualFrameworks)).IsEmpty)) { if (p.VersionLocked) { m.Warn($"The version({p.Version}) of the package {packageId} was manually locked. You need to change it manually."); continue; } actualFrameworks = actualFrameworks.Except(pFrameworks); var currentVersion = p.Version; if (currentVersion != version) { if (!preserveExisting) { var e = p.FinalVersionElement; if (e != null) { // <PackageReference Update="CK.Core" Version="13.0.1" /> centrally managed // package or <CKCoreVersion>13.0.1</CKCoreVersion>. if (e.Name == "PackageReference") { e.SetAttributeValue("Version", sV); } else { e.Value = sV; } } else { e = p.OriginElement; e.Attribute(p.IsVersionOverride ? "VersionOverride" : "Version").SetValue(sV); } ++changeCount; m.Trace($"Update in {ToString()}: {packageId} from {currentVersion} to {sV}."); } else { m.Trace($"Preserving existing version {currentVersion} for {packageId} in {ToString()} (skipped version is {sV})."); } } } // Handle creation if needed. if (!actualFrameworks.IsEmpty && addIfNotExists) { var firstPropertyGroup = ProjectFile.Document.Root.Element("PropertyGroup"); var pRef = new XElement("ItemGroup", new XElement("PackageReference", new XAttribute("Include", packageId), new XAttribute("Version", sV))); if (TargetFrameworks == actualFrameworks) { ++changeCount; firstPropertyGroup.AddAfterSelf(pRef); m.Trace($"Added unconditional package reference {packageId} -> {sV} for {ToString()}."); } else { foreach (var f in actualFrameworks.AtomicTraits) { ++changeCount; var withCond = new XElement(pRef); withCond.SetAttributeValue("Condition", $"'(TargetFrameWork)' == '{f}' "); firstPropertyGroup.AddAfterSelf(withCond); m.Trace($"Added conditional {f} package reference {packageId} -> {sV} for {ToString()}."); } } } if (changeCount > 0) { OnChange(m); } return(changeCount); }
public SimplePackageId(string packageId, SVersion v) { PackageIdentity = new PackageIdentity(packageId, NuGetVersion.Parse(v.ToString())); Version = v; }