Skip to content

Commit

Permalink
fixes in Upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Nov 12, 2020
1 parent 227a8e7 commit a1a37a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Signum.Upgrade/Upgrades/Upgrade_20200929_WebAuthn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public override void Execute(UpgradeContext uctx)
file.InsertAfterFirstLine(
l => l.Contains("import NotFound from './NotFound'"),
"import Login from '@extensions/Authorization/Login/Login'");
"import LoginPage from '@extensions/Authorization/Login/LoginPage'");
file.InsertBeforeFirstLine(
l => l.Contains("Services.SessionSharing.setAppNameAndRequestSessionStorage"),
@"Login.customLoginButtons = ctx => <WebAuthnClient.WebAuthnLoginButton ctx={ctx} />;
@"LoginPage.customLoginButtons = ctx => <WebAuthnClient.WebAuthnLoginButton ctx={ctx} />;
");
file.InsertAfterFirstLine(
Expand Down
18 changes: 18 additions & 0 deletions Signum.Upgrade/Upgrades/Upgrade_20201110_DotNet5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public override void Execute(UpgradeContext uctx)

uctx.ChangeCodeFile($@"Southwind.React/package.json", file =>
{
file.UpgradeNpmPackage("@types/react", "file:../Framework/Signum.React/node_modules/@types/react");
file.UpgradeNpmPackage("node-sass", "5.0.0");
file.UpgradeNpmPackage("sass-loader", "10.1.0");
});
Expand All @@ -67,6 +68,23 @@ public override void Execute(UpgradeContext uctx)
a => a.Contains("RUN apt-get -y install nodejs"),
@"RUN apt-get -y install curl
RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -
RUN apt-get install -y nodejs");
});

uctx.ChangeCodeFile($@"Southwind.React/App/MainPublic.tsx", file =>
{
file.ReplaceLine(
a => a.Contains("FROM mcr.microsoft.com/dotnet/core/aspnet"),
"FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base");
file.ReplaceLine(
a => a.Contains("FROM mcr.microsoft.com/dotnet/core/sdk"),
"FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build");
file.ReplaceBetween(
a => a.Contains("RUN apt-get -y install curl"),
a => a.Contains("RUN apt-get -y install nodejs"),
@"RUN apt-get -y install curl
RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -
RUN apt-get install -y nodejs");
});

Expand Down

4 comments on commit a1a37a4

@olmobrutall
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presenting Signum.Upgrade

The pain of upgrading

Signum Framework is more than 11 years old, but we have always been proud of keeping it up to date with technology.

We have always tried to make the upgrade process as simple as possible by keeping Southwind as a reference application to manually copy the changes, and by posting entries like this in the change log with upgrading instructions.

Still, upgrading the framework is the nightmare of many Signum Framework developers. A Signum Framework update typically also means upgrades in NuGet packages, NPM packages, or even Typescript, C# or .Net Core version. All technical updates that take time, can produce bugs, and are hard to justify to non-technical stakeholders.

Being scared of this changes only makes the problem worst: By delaying the upgrades they accumulate like a growing snow ball.

This problem is not particular to Signum Framework applications, most applications just never upgrade...

The solution

Signum.Upgrade is a new console application in Signum.Framework.

image

This project contains a directory called Upgrades with classes inheriting from CodeUpgradeBase and responsible of automatically modifying your code. Think of them like migrations but instead of changing your database they change your code.

This Upgrades can do any kind of transformation in your code like replacing spans, adding, removing or replacing any arbitrary line, and of course adding/removing or updating NPM or Nuget references.

Controlling your git repo

Signum.Upgrade also takes the liberty of controlling of your git repository using libgit2Sharp. Specifically, it prevents from running Upgrades if you have not committed all your code (except submodule changes), and after running each Upgrade allows you to automatically make a commit with its name. This way you can easily revert/retry any upgrade.

Warnings

The reliability of this changes depends strongly on how aligned your project is with Southwind example application.

If some file that needs to be modified has been renamed or deleted (packages.json, Startup.cs, MainPublic.tsx, ...), or some reference line has been removed, some steps of the Upgrade could produce warnings.

How to use it

Since Signum.Upgrade is in the master branch, it's already using .Net 5, so you need to:

  1. Update Visual Studio to 16.8.0 or greater.
  2. Download .Net 5 SDK https://dotnet.microsoft.com/download/dotnet/5.0
  3. Update Framework and Extensions submodules in you git repository
  4. In Solution Explorer, in the Framework virtual folder, Add -> Existing Project Signum.Upgrade.
  5. Start Signum.Upgrade

Signum.Upgrade will automatically detect the the root directory of your application.

The first time it will need to create a SignumUpgrade.txt file in your application folder. This file keeps track of the Upgrades that have already been executed, so you need to determine manually which Upgrades should be considered already executed. If you were up to date with changes until today select Upgrade_20201110_DotNet5.

Conclusion

The changes made by Signum.Upgrade could be enough for small upgrades, but often you will need to also manually fix more custom parts of your code. Also is strongly advised to carefully review and understand the changes made.

Still, I think Signum.Upgrade will strongly alleviate the process of upgrading Signum Applications, specially if you have more than one.

Enjoy :)

@MehdyKarimpour
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, Excellent!

@doganc
Copy link

@doganc doganc commented on a1a37a4 Nov 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent,

@MehdyKarimpour
Copy link
Contributor

@MehdyKarimpour MehdyKarimpour commented on a1a37a4 Nov 13, 2020 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.