Skip to content

Commit

Permalink
Refactor versioning strategy to use csproj
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Sep 3, 2023
1 parent ebaecc6 commit a0e2ad9
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 53 deletions.
5 changes: 5 additions & 0 deletions src/Build/Grand.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@
<ItemGroup Condition="'$(GitBranch)'!=''">
<AssemblyMetadata Include="GitBranch" Value="$(GitBranch)" />
</ItemGroup>
<Target Name="SetVersion" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<Version>2.2.0-develop</Version>
</PropertyGroup>
</Target>
</Project>
27 changes: 20 additions & 7 deletions src/Core/Grand.Infrastructure/GrandVersion.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Text.RegularExpressions;

namespace Grand.Infrastructure
{
Expand All @@ -7,32 +8,44 @@ public static class GrandVersion
/// <summary>
/// Gets the major version
/// </summary>
public const string MajorVersion = "2";
public static readonly string MajorVersion = Assembly.GetExecutingAssembly().GetName().Version?.Major.ToString();

/// <summary>
/// Gets the minor version
/// </summary>
public const string MinorVersion = "2";
public static readonly string MinorVersion = Assembly.GetExecutingAssembly().GetName().Version?.Minor.ToString();

/// <summary>
/// Gets the patch version
/// </summary>
public const string PatchVersion = "0-develop";

public static string PatchVersion {
get {

Assembly assembly = Assembly.GetExecutingAssembly();
if (assembly.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute)) is not
AssemblyInformationalVersionAttribute infoVersionAttribute) return "0";
var fullVersion = infoVersionAttribute.InformationalVersion;
Match match = Regex.Match(fullVersion, @"(\d+)\.(\d+)\.(\d+)(?:-([^\+]+))?");
if (!match.Success) return "0";
var patch = match.Groups[3].Value;
var suffix = match.Groups[4].Value;
return string.IsNullOrEmpty(suffix) ? patch : $"{patch}-{suffix}";
}
}
/// <summary>
/// Gets the full version
/// </summary>
public const string FullVersion = $"{MajorVersion}.{MinorVersion}.{PatchVersion}";
public static readonly string FullVersion = $"{MajorVersion}.{MinorVersion}.{PatchVersion}";

/// <summary>
/// Gets the Supported DB version
/// </summary>
public const string SupportedDBVersion = $"{MajorVersion}.{MinorVersion}";
public static readonly string SupportedDBVersion = $"{MajorVersion}.{MinorVersion}";

/// <summary>
/// Gets the Supported plugin version
/// </summary>
public const string SupportedPluginVersion = $"{MajorVersion}.{MinorVersion}";
public static readonly string SupportedPluginVersion = $"{MajorVersion}.{MinorVersion}";

/// <summary>
/// Gets the git branch
Expand Down
15 changes: 13 additions & 2 deletions src/Core/Grand.Infrastructure/Plugins/PluginInfoAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
namespace Grand.Infrastructure.Plugins
using System.Reflection;

namespace Grand.Infrastructure.Plugins
{
[AttributeUsage(AttributeTargets.Assembly)]
public class PluginInfoAttribute : Attribute
{
public PluginInfoAttribute()
{
Assembly assembly = Assembly.GetExecutingAssembly();
Version fullVersion = assembly.GetName().Version;
SupportedVersion = $"{fullVersion?.Minor}.{fullVersion?.Major}";

}
public string Group { get; set; } = string.Empty;
public string FriendlyName { get; set; } = string.Empty;
public string SystemName { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty;

public string SupportedVersion { get; set; }

public string Version { get; set; }
}
}
}
2 changes: 0 additions & 2 deletions src/Plugins/Authentication.Facebook/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Authentication.Facebook;
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;

[assembly: PluginInfo(
FriendlyName = "Facebook authentication",
Group = "Authentication methods",
SystemName = FacebookAuthenticationDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
2 changes: 0 additions & 2 deletions src/Plugins/Authentication.Google/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Authentication.Google;
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;

[assembly: PluginInfo(
FriendlyName = "Google authentication",
Group = "Authentication methods",
SystemName = GoogleAuthenticationDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/DiscountRules.Standard/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;

[assembly: PluginInfo(
FriendlyName = "Standard discount requirements",
Group = "Discount requirements",
SystemName = "DiscountRules.Standard",
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/ExchangeRate.McExchange/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;

[assembly: PluginInfo(
FriendlyName = "Money converter exchange rate provider (from EUR: ECB, from PLN: NBP)",
Group = "Exchange rate providers",
SystemName = "CurrencyExchange.MoneyConverter",
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Payments.BrainTree/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Payments.BrainTree;

[assembly: PluginInfo(
FriendlyName = "BrainTree",
Group = "Payment methods",
SystemName = BrainTreeDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Payments.CashOnDelivery/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Payments.CashOnDelivery;

[assembly: PluginInfo(
FriendlyName = "Cash On Delivery (COD)",
Group = "Payment methods",
SystemName = CashOnDeliveryPaymentDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Payments.PayPalStandard/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Payments.PayPalStandard;

[assembly: PluginInfo(
FriendlyName = "PayPal Standard",
Group = "Payment methods",
SystemName = PayPalStandardPaymentDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Shipping.ByWeight/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Shipping.ByWeight;

[assembly: PluginInfo(
FriendlyName = "Shipping by weight",
Group = "Shipping rate",
SystemName = ByWeightShippingDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Shipping.FixedRateShipping/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Shipping.FixedRateShipping;

[assembly: PluginInfo(
FriendlyName = "Fixed Rate Shipping",
Group = "Shipping rate",
SystemName = FixedRateShippingDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Shipping.ShippingPoint/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Shipping.ShippingPoint;

[assembly: PluginInfo(
FriendlyName = "Shipping Point",
Group = "Shipping rate",
SystemName = ShippingPointRateDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Tax.CountryStateZip/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Tax.CountryStateZip;

[assembly: PluginInfo(
FriendlyName = "Tax By Country & State & Zip",
Group = "Tax providers",
SystemName = CountryStateZipTaxDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Tax.FixedRate/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Tax.FixedRate;

[assembly: PluginInfo(
FriendlyName = "Fixed tax rate provider",
Group = "Tax providers",
SystemName = FixedRateTaxDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Widgets.FacebookPixel/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Widgets.FacebookPixel;

[assembly: PluginInfo(
FriendlyName = "Facebook Pixel",
Group = "Widgets",
SystemName = FacebookPixelDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Widgets.GoogleAnalytics/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Widgets.GoogleAnalytics;

[assembly: PluginInfo(
FriendlyName = "Google Analytics or Universal Analytics",
Group = "Widgets",
SystemName = GoogleAnalyticDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.1"
)]
4 changes: 1 addition & 3 deletions src/Plugins/Widgets.Slider/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Grand.Infrastructure;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.Plugins;
using Widgets.Slider;

[assembly: PluginInfo(
FriendlyName = "Bootstrap Slider",
Group = "Widgets",
SystemName = SliderWidgetDefaults.ProviderSystemName,
SupportedVersion = GrandVersion.SupportedPluginVersion,
Author = "grandnode team",
Version = "2.1.2"
)]
2 changes: 1 addition & 1 deletion src/Web/Grand.Web.Admin/Controllers/PluginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private void Upload(string archivePath)
{
var assembly = Assembly.Load(ToByteArray(unzippedEntryStream));
var pluginInfo = assembly.GetCustomAttribute<PluginInfoAttribute>();
if (pluginInfo is { SupportedVersion: GrandVersion.SupportedPluginVersion })
if (pluginInfo != null && pluginInfo.SupportedVersion == GrandVersion.SupportedPluginVersion)
{
supportedVersion = true;
_fpath = entry.FullName[..entry.FullName.LastIndexOf("/", StringComparison.Ordinal)];
Expand Down

0 comments on commit a0e2ad9

Please sign in to comment.