diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml new file mode 100644 index 0000000..bf199fd --- /dev/null +++ b/.github/workflows/dotnet-core.yml @@ -0,0 +1,59 @@ +name: Build .NET Core + +on: + push: + branches: + - master + - develop + - GA-* + +env: + MAIN_PROJECT: OneScript/OneScriptWeb.csproj + TEST_PROJECT: OneScriptWeb.Tests/OneScriptWeb.Tests.csproj + SOLUTION: OneScript.sln + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest] + dotnet-version: [3.1.301] + include: + - os: windows-latest + RID: win-x64 + target: netcoreapp3.1 + - os: ubuntu-latest + RID: linux-x64 + target: netcoreapp3.1 + defaults: + run: + working-directory: src + steps: + + # актуализация с сабмодулями + - uses: actions/checkout@v2 + with: + submodules: true + + # установка дотнет + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ matrix.dotnet-version }} + + # Сборка + - name: Build + run: dotnet build ${{env.MAIN_PROJECT}} -c Release -r ${{matrix.RID}} -f ${{ matrix.target }} -o ../artifact/${{matrix.target}}/${{matrix.RID}} + + # Тесты + - name: Test + run: dotnet test ${{env.TEST_PROJECT}} -c Release --runtime=${{matrix.RID}} -f ${{ matrix.target }} --logger="trx;LogFileName=${{matrix.RID}}.trx" --results-directory=testResults + + # Заливка в артефакты + - name: Artifact + uses: actions/upload-artifact@v2 + with: + name: oscript.web-${{matrix.RID}}.zip + path: ./artifact/${{matrix.target}}/${{matrix.RID}} diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml new file mode 100644 index 0000000..9b287c4 --- /dev/null +++ b/.github/workflows/qa.yml @@ -0,0 +1,70 @@ +name: Continuous Code Quality + +on: + push: + branches: + - master + - develop + # для отладки, нужно после убрать + - GA-* + pull_request: + types: [opened, synchronize, reopened] + +env: + MAIN_PROJECT: OneScript/OneScriptWeb.csproj + TEST_PROJECT: OneScriptWeb.Tests/OneScriptWeb.Tests.csproj + SOLUTION: OneScript.sln + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest] + dotnet-version: [3.1.301] + include: + - os: windows-latest + RID: win-x64 + target: netcoreapp3.1 + defaults: + run: + working-directory: src + steps: + + # актуализация с сабмодулями + - uses: actions/checkout@v2 + with: + submodules: true + + # установка дотнет + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ matrix.dotnet-version }} + + # Установка SonarScanner + - run: dotnet tool install --global dotnet-sonarscanner --version 4.10.0 + + # Java для dotnet + - name: Setup java + uses: actions/setup-java@v1 + with: + java-version: 11 + + # Старт SonarScanner + - run: dotnet sonarscanner begin /k:"1script-web" /d:sonar.login=${{ env.SONAR_TOKEN }} /d:sonar.host.url=${{ env.SONAR_HOST }} + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST: ${{ secrets.SONAR_HOST }} + + # Сборка + - name: Build + run: | + dotnet build ${{env.MAIN_PROJECT}} -c Release -r ${{matrix.RID}} -f ${{ matrix.target }} + + # Завершение SonarScanner + - run: dotnet sonarscanner end /d:sonar.login=${{ env.SONAR_TOKEN }} + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}} diff --git a/Jenkinsfile b/Jenkinsfile index 45ed968..23b9a2c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,10 +1,10 @@ pipeline { agent none + environment { ReleaseNumber = '0.7.0' } - stages { stage('Build and test'){ @@ -100,8 +100,8 @@ pipeline { unstash 'buildResults' withCredentials([usernamePassword(credentialsId: 'docker-hub', passwordVariable: 'dockerpassword', usernameVariable: 'dockeruser')]) { - sh 'docker build -t evilbeaver/oscript-web:0.7.0 --file Dockerfile src' - sh 'docker login -p $dockerpassword -u $dockeruser && docker push evilbeaver/oscript-web:0.7.0' + sh "docker build -t evilbeaver/oscript-web:${ReleaseNumber} --file Dockerfile src" + sh "docker login -p $dockerpassword -u $dockeruser && docker push evilbeaver/oscript-web:${ReleaseNumber}" } } } diff --git a/src/Include/OneScript b/src/Include/OneScript index 6e3d3df..44d84f2 160000 --- a/src/Include/OneScript +++ b/src/Include/OneScript @@ -1 +1 @@ -Subproject commit 6e3d3df01d1196c7afac04dd4d17ccade41e11af +Subproject commit 44d84f29680fa691d016520c98d183c726181515 diff --git a/src/OneScript.sln b/src/OneScript.sln index 177ca59..b3a471e 100644 --- a/src/OneScript.sln +++ b/src/OneScript.sln @@ -34,18 +34,23 @@ Global {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {59C56111-1C71-475C-8BE9-1173C9E7B7E0}.Release|Any CPU.Build.0 = Release|Any CPU {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.Debug|Any CPU.Build.0 = Debug|Any CPU {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0753066-45FE-4A74-9E25-D1D0A6EE1162}.Release|Any CPU.Build.0 = Release|Any CPU {778596E5-05C4-4775-A88B-34B3B48B56BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {778596E5-05C4-4775-A88B-34B3B48B56BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {778596E5-05C4-4775-A88B-34B3B48B56BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {778596E5-05C4-4775-A88B-34B3B48B56BA}.Release|Any CPU.Build.0 = Release|Any CPU {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.Debug|Any CPU.Build.0 = Debug|Any CPU {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {272DC28D-54B6-4D4D-9970-D3BA324DBECF}.Release|Any CPU.Build.0 = Release|Any CPU {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E8530889-A741-4A5E-B606-6C25FE4B8EA4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/OneScript/Application/ApplicationInstance.cs b/src/OneScript/Application/ApplicationInstance.cs index ba7b00a..4769e47 100644 --- a/src/OneScript/Application/ApplicationInstance.cs +++ b/src/OneScript/Application/ApplicationInstance.cs @@ -147,10 +147,15 @@ public void UseStaticFiles() [ContextMethod("ИспользоватьМаршруты")] public void UseMvcRoutes(string handler = null) { - if (handler == null) - _startupBuilder.UseMvcWithDefaultRoute(); + _startupBuilder.UseRouting(); + if (handler == default) + { + _startupBuilder.UseEndpoints(x => x.MapDefaultControllerRoute()); + } else + { CallRoutesRegistrationHandler(handler); + } } /// @@ -221,14 +226,13 @@ private void CallRoutesRegistrationHandler(string handler) var handlerIndex = GetScriptMethod(handler); var routesCol = new RoutesCollectionContext(); - CallScriptMethod(handlerIndex, new IValue[]{routesCol}); - _startupBuilder.UseMvc(routes => + _startupBuilder.UseEndpoints(routes => { foreach (var route in routesCol) { - routes.MapRoute(route.Name, route.Template, route.Defaults?.Select(x=> + routes.MapControllerRoute(route.Name, route.Template, route.Defaults?.Select(x=> { var kv = new KeyValuePair(x.Key.AsString(),ContextValuesMarshaller.ConvertToCLRObject(x.Value)); return kv; @@ -260,7 +264,7 @@ public static ApplicationInstance Create(ICodeSource src, IApplicationRuntime we var bc = compiler.Compile(src); var app = new ApplicationInstance(new LoadedModule(bc)); var machine = MachineInstance.Current; - webApp.Environment.LoadMemory(machine); + machine.PrepareThread(webApp.Environment); webApp.Engine.InitializeSDO(app); return app; diff --git a/src/OneScript/Authorization/OneScriptAuthorizationHandlerProvider.cs b/src/OneScript/Authorization/OneScriptAuthorizationHandlerProvider.cs index 171f20d..1c428af 100644 --- a/src/OneScript/Authorization/OneScriptAuthorizationHandlerProvider.cs +++ b/src/OneScript/Authorization/OneScriptAuthorizationHandlerProvider.cs @@ -31,7 +31,7 @@ private void AppendScriptedHandlers(IApplicationRuntime runtime, IFileProvider f if(!authFile.Exists || authFile.IsDirectory) return; - runtime.Environment.LoadMemory(MachineInstance.Current); + MachineInstance.Current.PrepareThread(runtime.Environment); var codeSource = new FileInfoCodeSource(authFile); runtime.DebugCurrentThread(); diff --git a/src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs b/src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs index ad29b31..10eee55 100644 --- a/src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs +++ b/src/OneScript/BackgroundJobs/BackgroundJobsManagerContext.cs @@ -6,6 +6,7 @@ This Source Code Form is subject to the terms of the ----------------------------------------------------------*/ using System; using Hangfire; +using OneScript.WebHost.Infrastructure; using ScriptEngine; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; @@ -51,8 +52,7 @@ public void WaitForCompletion() // должен быть public, т.к. hangfire не умеет вызывать private public static void PerformAction(string module, string method) { - var machine = MachineInstance.Current; - _globalEnv.LoadMemory(machine); + MachineInstance.Current.PrepareThread(_globalEnv); var scriptObject = (IRuntimeContextInstance)_globalEnv.GetGlobalProperty(module); var methodId = scriptObject.FindMethod(method); diff --git a/src/OneScript/BackgroundJobs/ScheduledJobsManagerContext.cs b/src/OneScript/BackgroundJobs/ScheduledJobsManagerContext.cs index 494654f..40d3cfc 100644 --- a/src/OneScript/BackgroundJobs/ScheduledJobsManagerContext.cs +++ b/src/OneScript/BackgroundJobs/ScheduledJobsManagerContext.cs @@ -98,7 +98,7 @@ public void RunContinuationsTask(string TaskIDFrom, string module, string method public static void PerformAction(string module, string method) { - _globalEnv.LoadMemory(MachineInstance.Current); + MachineInstance.Current.PrepareThread(_globalEnv); ApplicationDbContext dbContext = null; try diff --git a/src/OneScript/Infrastructure/Implementations/OscriptApplicationModelProvider.cs b/src/OneScript/Infrastructure/Implementations/OscriptApplicationModelProvider.cs index 078d34c..1cfc209 100644 --- a/src/OneScript/Infrastructure/Implementations/OscriptApplicationModelProvider.cs +++ b/src/OneScript/Infrastructure/Implementations/OscriptApplicationModelProvider.cs @@ -99,7 +99,7 @@ public void OnProvidersExecuting(ApplicationModelProviderContext context) private void FillContext(IEnumerable sources, ApplicationModelProviderContext context) { var reflector = new TypeReflectionEngine(); - _fw.Environment.LoadMemory(MachineInstance.Current); + MachineInstance.Current.PrepareThread(_fw.Environment); foreach (var virtualPath in sources) { LoadedModule module; diff --git a/src/OneScript/Infrastructure/Implementations/ScriptedControllerActivator.cs b/src/OneScript/Infrastructure/Implementations/ScriptedControllerActivator.cs index 1558d4d..4ffe6b1 100644 --- a/src/OneScript/Infrastructure/Implementations/ScriptedControllerActivator.cs +++ b/src/OneScript/Infrastructure/Implementations/ScriptedControllerActivator.cs @@ -39,8 +39,8 @@ public object Create(ControllerContext context) var module = info.Module; var instance = new ScriptedController(context, module); var machine = MachineInstance.Current; - engine.Environment.LoadMemory(machine); - + machine.PrepareThread(engine.Environment); + _runtime.DebugCurrentThread(); engine.InitializeSDO(instance); return instance; diff --git a/src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs b/src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs index 4fb3cbf..3589c74 100644 --- a/src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs +++ b/src/OneScript/Infrastructure/Implementations/ScriptedMiddlewareActivator.cs @@ -37,7 +37,7 @@ public async Task InvokeAsync(HttpContext context) var engine = _runtime.Engine; var instance = new ScriptedMiddleware(_next, _module); var machine = MachineInstance.Current; - engine.Environment.LoadMemory(machine); + machine.PrepareThread(engine.Environment); try { _runtime.DebugCurrentThread(); diff --git a/src/OneScript/Infrastructure/RuntimeExtensions.cs b/src/OneScript/Infrastructure/RuntimeExtensions.cs new file mode 100644 index 0000000..b1656ed --- /dev/null +++ b/src/OneScript/Infrastructure/RuntimeExtensions.cs @@ -0,0 +1,21 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ + +using ScriptEngine; +using ScriptEngine.Machine; + +namespace OneScript.WebHost.Infrastructure +{ + public static class RuntimeExtensions + { + public static void PrepareThread(this MachineInstance machine, RuntimeEnvironment env) + { + if (!machine.IsRunning) + env.LoadMemory(machine); + } + } +} \ No newline at end of file diff --git a/src/OneScript/OneScriptWeb.csproj b/src/OneScript/OneScriptWeb.csproj index b821216..351bc5e 100644 --- a/src/OneScript/OneScriptWeb.csproj +++ b/src/OneScript/OneScriptWeb.csproj @@ -19,6 +19,10 @@ Copyright (c) 2018 EvilBeaver Debug;Release AnyCPU + + + + {E2CEBBAF-6DF7-41E9-815D-9AD4CF90C844} @@ -29,6 +33,8 @@ AnyCPU bin\Release\$(TargetFramework)\OneScript.WebHost.xml + false + 2 @@ -48,6 +54,8 @@ + + @@ -55,7 +63,7 @@ - + diff --git a/src/OneScript/Startup.cs b/src/OneScript/Startup.cs index 16d7c41..a5787ac 100644 --- a/src/OneScript/Startup.cs +++ b/src/OneScript/Startup.cs @@ -71,9 +71,9 @@ public void ConfigureServices(IServiceCollection services) //TODO подумать как вывести данную конструкцию в конфигурацю доступную для разработчика 1С services.AddAntiforgery(options => options.Cookie.Name = "OScriptWeb.Antiforgery"); - services.AddMvc() + services.AddControllersWithViews(mvcopts => mvcopts.EnableEndpointRouting = false) + .AddRazorRuntimeCompilation() .ConfigureApplicationPartManager(pm=>pm.FeatureProviders.Add(new ScriptedViewComponentFeatureProvider())); - services.AddOneScript(); services.AddOneScriptDebug(Configuration); } @@ -106,8 +106,10 @@ private static void StartOneScriptApp(IApplicationBuilder app, IServiceProvider try { var oscriptApp = services.GetService(); + + MachineInstance.Current.PrepareThread(appRuntime.Environment); + appRuntime.Engine.DebugController = services.GetService(); - if (appRuntime.DebugEnabled()) { var logger = services.GetService>();