Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clı: Added trustUserVersion option #18915

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ protected async Task<ProjectBuildArgs> GetProjectBuildArgsAsync(CommandLineArgs

var skipCache = commandLineArgs.Options.ContainsKey(Options.SkipCache.Long) || commandLineArgs.Options.ContainsKey(Options.SkipCache.Short);

var trustUserVersion = !version.IsNullOrEmpty() && commandLineArgs.Options.ContainsKey(Options.TrustUserVersion.Long) || commandLineArgs.Options.ContainsKey(Options.TrustUserVersion.Short);

return new ProjectBuildArgs(
solutionName,
template,
Expand All @@ -251,7 +253,8 @@ protected async Task<ProjectBuildArgs> GetProjectBuildArgsAsync(CommandLineArgs
pwa,
theme,
themeStyle,
skipCache
skipCache,
trustUserVersion
);
}

Expand Down Expand Up @@ -902,6 +905,11 @@ public static class SkipCache
public const string Long = "skip-cache";
}

public static class TrustUserVersion
{
public const string Short = "tv";
public const string Long = "trust-version";
}

public static class Tiered
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
string version = null,
string templateSource = null,
bool includePreReleases = false,
bool skipCache = false)
bool skipCache = false,
bool trustUserVersion = false)
{
DirectoryHelper.CreateIfNotExists(CliPaths.TemplateCache);
var userSpecifiedVersion = version != null;
Expand Down Expand Up @@ -96,33 +97,36 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
var templateVersion = SemanticVersion.Parse(version);

var outputWarning = false;
if (currentCliVersion.Major != templateVersion.Major || currentCliVersion.Minor != templateVersion.Minor)
if (!trustUserVersion)
{
// major and minor version are different
outputWarning = true;
}
else if (currentCliVersion.Major == templateVersion.Major &&
currentCliVersion.Minor == templateVersion.Minor &&
currentCliVersion.Patch < templateVersion.Patch)
{
// major and minor version are same but patch version is lower
outputWarning = true;
}
else if(currentCliVersion.Major == templateVersion.Major &&
currentCliVersion.Minor == templateVersion.Minor &&
currentCliVersion.Patch == templateVersion.Patch &&
currentCliVersion.IsPrerelease && templateVersion.IsPrerelease)
{
// major and minor and patch version are same but prerelease version may be lower
var cliRcVersion = currentCliVersion.ReleaseLabels.LastOrDefault();
var templateRcVersion = templateVersion.ReleaseLabels.LastOrDefault();
if (cliRcVersion != null && templateRcVersion != null)
if (currentCliVersion.Major != templateVersion.Major || currentCliVersion.Minor != templateVersion.Minor)
{
// major and minor version are different
outputWarning = true;
}
else if (currentCliVersion.Major == templateVersion.Major &&
currentCliVersion.Minor == templateVersion.Minor &&
currentCliVersion.Patch < templateVersion.Patch)
{
// major and minor version are same but patch version is lower
outputWarning = true;
}
else if(currentCliVersion.Major == templateVersion.Major &&
currentCliVersion.Minor == templateVersion.Minor &&
currentCliVersion.Patch == templateVersion.Patch &&
currentCliVersion.IsPrerelease && templateVersion.IsPrerelease)
{
if (int.TryParse(cliRcVersion, out var cliRcVersionNumber) && int.TryParse(templateRcVersion, out var templateRcVersionNumber))
// major and minor and patch version are same but prerelease version may be lower
var cliRcVersion = currentCliVersion.ReleaseLabels.LastOrDefault();
var templateRcVersion = templateVersion.ReleaseLabels.LastOrDefault();
if (cliRcVersion != null && templateRcVersion != null)
{
if (cliRcVersionNumber < templateRcVersionNumber)
if (int.TryParse(cliRcVersion, out var cliRcVersionNumber) && int.TryParse(templateRcVersion, out var templateRcVersionNumber))
{
outputWarning = true;
if (cliRcVersionNumber < templateRcVersionNumber)
{
outputWarning = true;
}
}
}
}
Expand All @@ -147,12 +151,12 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
}
}

if (!await IsVersionExists(name, version))
if (!trustUserVersion && !await IsVersionExists(name, version))
{
throw new Exception("There is no version found with given version: " + version);
}

var nugetVersion = (await GetTemplateNugetVersionAsync(name, type, version)) ?? version;
var nugetVersion = await GetTemplateNugetVersionAsync(name, type, version) ?? version;

if (!string.IsNullOrWhiteSpace(templateSource) && !IsNetworkSource(templateSource))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface ISourceCodeStore
[CanBeNull] string version = null,
[CanBeNull] string templateSource = null,
bool includePreReleases = false,
bool skipCache = false
bool skipCache = false,
bool trustUserVersion = false
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class ProjectBuildArgs
[CanBeNull]
public string Version { get; set; }

public bool TrustUserVersion { get; set; }

public DatabaseProvider DatabaseProvider { get; set; }

public DatabaseManagementSystem DatabaseManagementSystem { get; set; }
Expand Down Expand Up @@ -69,7 +71,8 @@ public class ProjectBuildArgs
bool pwa = false,
Theme? theme = null,
ThemeStyle? themeStyle = null,
bool skipCache = false)
bool skipCache = false,
bool trustUserVersion = false)
{
SolutionName = Check.NotNull(solutionName, nameof(solutionName));
TemplateName = templateName;
Expand All @@ -89,5 +92,6 @@ public class ProjectBuildArgs
Theme = theme;
ThemeStyle = themeStyle;
SkipCache = skipCache;
TrustUserVersion = trustUserVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public async Task<ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
SourceCodeTypes.Template,
args.Version,
args.TemplateSource,
args.ExtraProperties.ContainsKey(NewCommand.Options.Preview.Long)
args.ExtraProperties.ContainsKey(NewCommand.Options.Preview.Long),
trustUserVersion: args.TrustUserVersion
);

ConfigureThemeOptions(args, templateFile.Version);
Expand Down