Skip to content

Commit

Permalink
merge master into feature
Browse files Browse the repository at this point in the history
  • Loading branch information
framitdavid committed Dec 18, 2023
2 parents 5c0cd59 + e4b8f87 commit 706357f
Show file tree
Hide file tree
Showing 204 changed files with 4,021 additions and 2,237 deletions.
70 changes: 34 additions & 36 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,70 @@
# Labels for solutions
solution/platform:
- 'src/Altinn.Platform/**/*'
- changed-files:
- any-glob-to-any-file: 'src/Altinn.Platform/**/*'

solution/app-backend:
- 'src/studio/AppTemplates/**/*'
- changed-files:
- any-glob-to-any-file: 'src/studio/AppTemplates/**/*'

solution/studio/designer:
- 'backend/**/*'
- 'frontend/**/*'
- changed-files:
- any-glob-to-any-file: ['backend/**/*', 'frontend/**/*']

solution/studio/repos:
- 'gitea/**/*'
- changed-files:
- any-glob-to-any-file: 'gitea/**/*'

# Labels for areas
area/app-deploy:
- 'frontend/app-development/features/appPublish/**/*'
- 'frontend/app-development/sharedResources/appDeployment/**/*'
- 'backend/src/Designer/Controllers/DeploymentsController.cs'
- 'src/studio/AppTemplates/AspNet/deployment/**/*'
- changed-files:
- any-glob-to-any-file: ['frontend/app-development/features/appPublish/**/*', 'frontend/app-development/sharedResources/appDeployment/**/*', 'backend/src/Designer/Controllers/DeploymentsController.cs', 'src/studio/AppTemplates/AspNet/deployment/**/*']

area/dashboard:
- 'frontend/dashboard/**/*'
- changed-files:
- any-glob-to-any-file: 'frontend/dashboard/**/*'

area/data-modeling:
- 'frontend/packages/schema-editor/**/*'
- 'frontend/packages/schema-model/**/*'
- 'frontend/app-development/features/dataModelling/**/*'
- 'backend/src/DataModeling/**/*'
- changed-files:
- any-glob-to-any-file: ['frontend/packages/schema-editor/**/*', 'frontend/packages/schema-model/**/*', 'frontend/app-development/features/dataModelling/**/*', 'backend/src/DataModeling/**/*']

area/pdf:
- 'src/Altinn.Platform/Altinn.Platform.PDF/**/*'
- changed-files:
- any-glob-to-any-file: 'src/Altinn.Platform/Altinn.Platform.PDF/**/*'

area/resource-registry:
- 'frontend/resourceAdm/**/*'
- changed-files:
- any-glob-to-any-file: 'frontend/resourceAdm/**/*'

area/test:
- 'src/test/**/*'
- changed-files:
- any-glob-to-any-file: 'src/test/**/*'

area/text-editor:
- 'frontend/packages/text-editor/**'
- 'frontend/app-development/features/textEditor/**/*'
- changed-files:
- any-glob-to-any-file: ['frontend/packages/text-editor/**', 'frontend/app-development/features/textEditor/**/*']

area/process:
- 'frontend/app-development/features/processEditor/**/*'
- 'frontend/packages/process-editor/**/*'
- 'backend/src/Designer/**/*ProcessesModeling*.cs'
- changed-files:
- any-glob-to-any-file: ['frontend/app-development/features/processEditor/**/*', 'frontend/packages/process-editor/**/*', 'backend/src/Designer/**/*ProcessesModeling*.cs']

area/ui-editor:
- 'frontend/packages/ux-editor/**/*'
- changed-files:
- any-glob-to-any-file: 'frontend/packages/ux-editor/**/*'

area/studio-root:
- 'frontend/studio-root/**/*'
- changed-files:
- any-glob-to-any-file: 'frontend/studio-root/**/*'

## Other labels
kind/dependencies:
- 'backend/packagegroups/NuGet.props'
- 'frontend/**/package.json'
- changed-files:
- any-glob-to-any-file: ['backend/packagegroups/NuGet.props', 'frontend/**/package.json']

quality/testing:
- 'frontend/testing/**/*'
- 'backend/tests/**/*'
- 'testdata/**/*'
- changed-files:
- any-glob-to-any-file: ['frontend/testing/**/*', 'backend/tests/**/*', 'testdata/**/*']

skip-releasenotes:
- '.github/**/*'
- '.husky/**/*'
- '.vscode/**/*'
- '.yarn/**/*'
- 'testdata/**/*'
- 'development/**/*'
- 'src/**/*'
- changed-files:
- any-glob-to-any-file: ['.github/**/*', '.husky/**/*', '.vscode/**/*', '.yarn/**/*', 'testdata/**/*', 'development/**/*', 'src/**/*']
5 changes: 4 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Related Issue(s)

- #{issue number}

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and we'll help out)
- [ ] Cypress tests run green locally (https://github.com/Altinn/altinn-studio/tree/master/frontend/testing/cypress#run-altinn-studio-tests)

## Documentation

- [ ] User documentation is updated with a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs) (if applicable)
2 changes: 1 addition & 1 deletion .github/workflows/designer-dotnet-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE: false
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gitea-designer-integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE: false
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/labeler@v4
- uses: actions/labeler@v5
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
69 changes: 69 additions & 0 deletions .github/workflows/run-cypress-on-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Cypress tests on pr
on:
pull_request:
branches: [ master ]
types: [opened, synchronize, reopened]
paths:
- 'frontend/**'
- '!frontend/stats/**'
- 'backend/**'
- '.github/workflows/run-cypress-on-pr.yaml'
- 'docker-compose.yml'
- 'Dockerfile'
- 'gitea/**'
workflow_dispatch:

jobs:
cypress-tests:
name: Build environment and run e2e test
timeout-minutes: 25
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Generate .env file
run: |
echo CYPRESS_TEST_APP=autodeploy-v3 >> .env
echo DEVELOP_APP_DEVELOPMENT=0 >> .env
echo DEVELOP_RESOURCE_ADMIN=0 >> .env
echo DEVELOP_BACKEND=0 >> .env
echo DEVELOP_DASHBOARD=0 >> .env
echo DEVELOP_PREVIEW=0 >> .env
echo GITEA_ADMIN_PASS=g9wDIG@6gf >> .env
echo GITEA_ADMIN_USER=localg1iteaadmin >> .env
echo GITEA_CYPRESS_USER=cypress_testuser >> .env
echo GITEA_CYPRESS_PASS=g9wDIG@6gf >> .env
echo GITEA_ORG_USER=ttd >> .env
echo POSTGRES_PASSWORD=kyeDIG@eip >> .env
echo COMMIT= >> .env
echo IGNORE_DOCKER_DNS_LOOKUP=true >> .env
- name: Build all images
run: |
docker compose build --no-cache
- name: Install node
uses: actions/setup-node@v4
with:
cache: 'yarn'

- name: Run setup.js script
run: |
node ./development/setup.js
- name: Cypress run
uses: cypress-io/github-action@v5
with:
install: true
working-directory: frontend/testing/cypress
env: environment=local
spec: src/integration/studio/*.js
record: false
parallel: false

- name: Stop compose file
if: always()
run: docker-compose down
2 changes: 1 addition & 1 deletion backend/packagegroups/NuGet.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Update="ini-parser-netstandard" Version="2.5.2" />
<PackageReference Update="JWTCookieAuthentication" Version="3.0.1" />
<!-- Do not upgrade this package unless extensively tested-->
<PackageReference Update="LibGit2Sharp" Version="0.28.0" />
<PackageReference Update="LibGit2Sharp" Version="0.29.0" />
<PackageReference Update="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Update="Microsoft.ApplicationInsights.Kubernetes" Version="6.1.1" />
<PackageReference Update="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Basic.Reference.Assemblies;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Text;

namespace SharedResources.Tests
namespace Altinn.Studio.DataModeling.Converter.Csharp
{
public static class Compiler
{
/// <summary>
/// Try to compile csharp class from generated csharp code as string
/// </summary>
/// <param name="csharpCode">Csharp code as string</param>
/// <remarks>Throws a custom compiler exception with corresponding diagnostics if compilation fails</remarks>
/// <returns>The corresponding assembly</returns>
public static Assembly CompileToAssembly(string csharpCode)
{
var syntaxTree = SyntaxFactory.ParseSyntaxTree(SourceText.From(csharpCode));
Expand All @@ -25,7 +30,7 @@ public static Assembly CompileToAssembly(string csharpCode)
.AddReferences(MetadataReference.CreateFromFile(typeof(Newtonsoft.Json.JsonPropertyAttribute).GetTypeInfo().Assembly.Location))
.AddSyntaxTrees(syntaxTree);

Assembly assembly = null;
Assembly assembly;
using (var ms = new MemoryStream())
{
EmitResult result = compilation.Emit(ms);
Expand All @@ -36,19 +41,16 @@ public static Assembly CompileToAssembly(string csharpCode)
diagnostic.IsWarningAsError ||
diagnostic.Severity == DiagnosticSeverity.Error);

var errors = new StringBuilder();
List<string> customErrorMessages = new();
foreach (Diagnostic diagnostic in failures)
{
errors.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}");
customErrorMessages.Add(diagnostic.GetMessage());
}

throw new Exception($"Uh dude, you seem to have provoked some compilation errors with your code change. Please fix before merging! {errors}");
}
else
{
ms.Seek(0, SeekOrigin.Begin);
assembly = Assembly.Load(ms.ToArray());
throw new CsharpCompilationException("Csharp compilation failed.", customErrorMessages);
}
ms.Seek(0, SeekOrigin.Begin);
assembly = Assembly.Load(ms.ToArray());
}

return assembly;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Altinn.Studio.DataModeling.Converter.Csharp;

public class CsharpCompilationException : Exception
{

public List<string> CustomErrorMessages { get; }

/// <inheritdoc/>
public CsharpCompilationException(string message, List<string> customErrorMessages) : base(message)
{
CustomErrorMessages = customErrorMessages;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public JsonMetadataToCsharpConverter(CSharpGenerationSettings generationSettings
/// <returns>The model code in C#</returns>
public string CreateModelFromMetadata(ModelMetadata serviceMetadata)
{
Dictionary<string, string> classes = new Dictionary<string, string>();
Dictionary<string, string> classes = new();

CreateModelFromMetadataRecursive(classes, serviceMetadata.Elements.Values.First(el => el.ParentElement == null), serviceMetadata, serviceMetadata.TargetNamespace);

Expand All @@ -47,7 +47,11 @@ public string CreateModelFromMetadata(ModelMetadata serviceMetadata)
.Append(string.Concat(classes.Values))
.AppendLine("}");

return writer.ToString();
string cSharpClasses = writer.ToString();

Compiler.CompileToAssembly(cSharpClasses);

return cSharpClasses;
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions backend/src/DataModeling/DataModeling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Basic.Reference.Assemblies" />
<PackageReference Include="JsonSchema.Net" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
2 changes: 2 additions & 0 deletions backend/src/Designer/Designer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
<PackageReference Include="Microsoft.Azure.KeyVault" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" />
<PackageReference Include="HtmlAgilityPack" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public override void OnException(ExceptionContext context)
return;
}

if (context.Exception is CsharpCompilationException compilationException)
{
context.Result = new ObjectResult(ProblemDetailsUtils.GenerateProblemDetails(context.Exception, DataModelingErrorCodes.CsharpGenerationError, HttpStatusCode.BadRequest, compilationException.CustomErrorMessages)) { StatusCode = (int)HttpStatusCode.BadRequest };
}

if (context.Exception is CsharpGenerationException)
{
context.Result = new ObjectResult(ProblemDetailsUtils.GenerateProblemDetails(context.Exception, DataModelingErrorCodes.CsharpGenerationError, HttpStatusCode.InternalServerError)) { StatusCode = (int)HttpStatusCode.InternalServerError };
Expand Down
10 changes: 8 additions & 2 deletions backend/src/Designer/Filters/ProblemDetailsUtils.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
using System;
using System.Collections.Generic;
using System.Net;
using Microsoft.AspNetCore.Mvc;

namespace Altinn.Studio.Designer.Filters
{
public static class ProblemDetailsUtils
{
public static ProblemDetails GenerateProblemDetails(Exception ex, string customErrorCode, HttpStatusCode statusCode)
public static ProblemDetails GenerateProblemDetails(Exception ex, string customErrorCode, HttpStatusCode statusCode, List<string> customErrorMessages = null)
{
string exceptionType = ex.GetType().Name;
ProblemDetails details = new ProblemDetails
ProblemDetails details = new()
{
Title = $"{exceptionType} occured.",
Detail = ex.Message,
Status = (int)statusCode,
Type = exceptionType
};
details.Extensions.Add("errorCode", customErrorCode);

if (customErrorMessages is not null)
{
details.Extensions.Add("customErrorMessages", customErrorMessages);
}
return details;
}
}
Expand Down
Loading

0 comments on commit 706357f

Please sign in to comment.