Skip to content

Commit

Permalink
Merge pull request #27 from thygesteffensen/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
thygesteffensen authored May 15, 2023
2 parents de739e0 + 587ef23 commit 1fd0838
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 24 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/.releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
branches:
- name: main
- name: dev
prerelease: alpha

plugins:
- - "@semantic-release/commit-analyzer"
- preset: conventionalcommits

- - "@semantic-release/release-notes-generator"
- preset: conventionalcommits

- - "@semantic-release/github"
- assets:
- path: ../../artifacts/PAMU_CDS.*.nupkg
label: PAMU CDS DLL

- - "@semantic-release/exec"
- publishCmd: "dotnet nuget push ..\\..\\artifacts\\PAMU_CDSce.*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${process.env.CI_NUGET_API_KEY}"
89 changes: 89 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Release

on:
push:
branches:
- dev
- main

jobs:
test:
name: Testing
runs-on: windows-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

# - name: Add nuget Source
# env:
# GH_TOKEN: ${{ secrets.GH_TOKEN }}
# run: nuget sources Add -Name Github -Source https://nuget.pkg.github.com/thygesteffensen/index.json -UserName thygesteffensen -Password $env:GH_TOKEN

# - name: Set Github nuget API
# env:
# GH_TOKEN: ${{ secrets.GH_TOKEN }}
# run: nuget setapikey $env:GH_TOKEN -Source https://nuget.pkg.github.com/thygesteffensen/index.json

- name: Run tests
run: dotnet test --verbosity normal --configuration Release

release:
name: Releasing
runs-on: windows-latest
needs:
- test
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3

- name: Add plugin for conventional commits
run: npm install conventional-changelog-conventionalcommits
working-directory: ./.github/workflows

- name: Add plugin for executing bash commands
run: npm install @semantic-release/exec -D
working-directory: ./.github/workflows

- name: Dry Run Semantic to get next Version nummber
working-directory: ./.github/workflows
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: thygesteffensen
GIT_AUTHOR_EMAIL: [email protected]
run: |
echo "RELEASE_VERSION=$((npx semantic-release --dry-run).Where({ $_ -like '*Release note*' }) | Out-String | Select-String '[0-9]+\.[0-9]+\.[0-9]+([-][a-zA-z]+[.][0-9]*)?' | % { $_.Matches } | % { $_.Value })" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Print release verison
run: echo ${env:RELEASE_VERSION}

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1

# - name: Add nuget Source
# env:
# GH_TOKEN: ${{ secrets.GH_TOKEN }}
# run: nuget sources Add -Name Github -Source https://nuget.pkg.github.com/thygesteffensen/index.json -UserName thygesteffensen -Password $env:GH_TOKEN

# - name: Set Github nuget API
# env:
# GH_TOKEN: ${{ secrets.GH_TOKEN }}
# run: nuget setapikey $env:GH_TOKEN -Source https://nuget.pkg.github.com/thygesteffensen/index.json

- name: Restore NuGet packages
run: dotnet restore PAMU_CDS.sln /p:Configuration=Release

- name: Package PAMU
run: msbuild /t:pack /p:PackageVersion=${env:RELEASE_VERSION} /p:Configuration=Release /p:OutputPath=..\\artifacts
if: ${{ env.RELEASE_VERSION }}

- name: Release to GitHub
working-directory: .\\.github\\workflows
env:
CI_NUGET_API_KEY: ${{ secrets.NUGETAPIKEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: thygesteffensen
GIT_AUTHOR_EMAIL: [email protected]
run: npx semantic-release
2 changes: 1 addition & 1 deletion PAMU_CDS/Actions/DeleteRecordAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace PAMU_CDS.Actions
{
public class DeleteRecordAction : OpenApiConnectionActionExecutorBase
{
public static readonly string[] OperationId = {"CreateRecord"};
public static readonly string[] OperationId = {"DeleteRecord"};

private readonly IOrganizationService _organizationService;

Expand Down
30 changes: 30 additions & 0 deletions PAMU_CDS/Auxiliary/EntityExtension.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Xrm.Sdk;
using Parser.ExpressionParser;

Expand All @@ -26,6 +28,12 @@ public static Entity CreateEntityFromParameters(this Entity entity,
foreach (KeyValuePair<string, ValueContainer> keyValuePair in items
.GetValue<Dictionary<string, ValueContainer>>())
{
if (keyValuePair.Key.Contains("@odata.bind"))
{
entity.AddLookupAttribute(keyValuePair.Key, keyValuePair.Value);
continue;
}

// TODO: Figure out how to determine which value is expected.
entity.Attributes[keyValuePair.Key] = keyValuePair.Value.GetValue<string>();
}
Expand All @@ -34,6 +42,28 @@ public static Entity CreateEntityFromParameters(this Entity entity,
return entity;
}

private static void AddLookupAttribute(
this Entity entity,
string key,
ValueContainer valueContainer)
{
var attribute = key.Split('_').FirstOrDefault();
if (attribute == null) throw new Exception($"Unable to parse attribute from key {key}");

var valueRegex = Regex.Match(valueContainer.GetValue<string>(), "([^(]*)\\(([^)]*)\\)");
if (!valueRegex.Success) throw new Exception("Invalid format for lookup, expected something like accounts(030cae85-afa4-4cd2-96a8-a18b6301a6fa)");
var logicalPlural = valueRegex.Groups[1].Value;
if (!Guid.TryParse(valueRegex.Groups[2].Value, out Guid id)) throw new Exception($"Unable to parse id from {valueRegex.Groups[2].Value}");

entity.Attributes.Add(
attribute,
new EntityReference(
logicalPlural.Substring(0,logicalPlural.Length-1),
id
)
);
}

public static ValueContainer ToValueContainer(this Entity entity)
{
var triggerOutputs = new Dictionary<string, ValueContainer>();
Expand Down
20 changes: 10 additions & 10 deletions PAMU_CDS/PAMU_CDS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

<ItemGroup>
<!--<FrameworkReference Include="Microsoft.AspNetCore.App" />-->
<PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="9.0.2.29"/>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0"/>
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
<PackageReference Include="Sprache" Version="2.3.1"/>
<PackageReference Include="XrmMockup365" Version="1.7.1"/>
<PackageReference Include="PowerAutomateMockUp" Version="2.0.0"/>
<PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="9.0.2.29" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Sprache" Version="2.3.1" />
<PackageReference Include="XrmMockup365" Version="1.12.1" />
<PackageReference Include="PowerAutomateMockUp" Version="2.0.0-alpha.2" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions PAMU_CDS/PamuCdsDependencyExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public static void AddPamuCds(this IServiceCollection services)

services.AddFlowActionByApiIdAndOperationsName<DisAndAssociateEntitiesAction>(apiId,
DisAndAssociateEntitiesAction.OperationId);

services.AddFlowActionByApiIdAndOperationsName<ScopeActionExecutor>(apiId,
new[] {"ExecuteChangeset"});
}
}
}
}
20 changes: 19 additions & 1 deletion Test/PureCdSceFullFlowTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Linq;

namespace Test
{
Expand All @@ -20,5 +21,22 @@ public void TestCreateContact()
Assert.IsNotNull(retrievedContact);
Assert.AreEqual("Technical Supervisor", retrievedContact.Attributes["jobtitle"]);
}

[TestMethod]
public void TestCreateAccountLookupBackFromContact()
{
var account = new Entity("account");

account.Id = OrgAdminService.Create(account);

var retrievedContact = OrgAdminService.RetrieveMultiple(new QueryExpression("contact")
{
ColumnSet = new ColumnSet(true)
}).Entities.FirstOrDefault();

Assert.IsNotNull(retrievedContact);
Assert.AreEqual(account.Id, retrievedContact.GetAttributeValue<EntityReference>("parentcustomerid")?.Id);

}
}
}
}
21 changes: 13 additions & 8 deletions Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@

<ItemGroup>
<!--<PackageReference Include="bd1fe5ca33fd455dafb99d34768b8de4" Version="1.3.3-dev.10.0" />-->
<PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="9.0.2.29"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/>
<PackageReference Include="Moq" Version="4.15.2"/>
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2"/>
<PackageReference Include="MSTest.TestFramework" Version="2.1.2"/>
<PackageReference Include="PowerAutomateMockUp" Version="2.0.0"/>
<PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="9.0.2.29" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Moq" Version="4.15.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="PowerAutomateMockUp" Version="2.0.0-alpha.2" />
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="XrmMockup365" Version="1.7.1"/>
<PackageReference Include="XrmMockup365" Version="1.12.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PAMU_CDS\PAMU_CDS.csproj"/>
<ProjectReference Include="..\PAMU_CDS\PAMU_CDS.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="TestFlows\LookupFlow.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFlows\Pure_CDS_ce.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -42,4 +45,6 @@
</None>
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties testflows_4lookupflow_1json__JsonSchema="{" /></VisualStudio></ProjectExtensions>

</Project>
74 changes: 74 additions & 0 deletions Test/TestFlows/LookupFlow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"properties": {
"connectionReferences": {
"shared_commondataserviceforapps": {
"runtimeSource": "embedded",
"connection": {
"connectionReferenceLogicalName": "demo_sharedcommondataserviceforapps_232e6"
},
"api": {
"name": "shared_commondataserviceforapps"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
},
"$authentication": {
"defaultValue": {},
"type": "SecureObject"
}
},
"triggers": {
"Create_account": {
"metadata": {
"operationMetadataId": "10031c6a-2d9a-4c03-bb5e-296bfaa145a7"
},
"type": "OpenApiConnectionWebhook",
"inputs": {
"host": {
"connectionName": "shared_commondataserviceforapps",
"operationId": "SubscribeWebhookTrigger",
"apiId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"
},
"parameters": {
"subscriptionRequest/message": 1,
"subscriptionRequest/entityname": "account",
"subscriptionRequest/scope": 4
},
"authentication": "@parameters('$authentication')"
}
}
},
"actions": {
"Create_contact": {
"runAfter": {},
"metadata": {
"operationMetadataId": "440263ff-5e40-4e1c-b4a6-3e16d0226cf0"
},
"type": "OpenApiConnection",
"inputs": {
"host": {
"connectionName": "shared_commondataserviceforapps",
"operationId": "CreateRecord",
"apiId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"
},
"parameters": {
"entityName": "contacts",
"item/lastname": "Default",
"item/[email protected]": "accounts(@{triggerOutputs()?['body/accountid']})"
},
"authentication": "@parameters('$authentication')"
}
}
}
},
"templateName": ""
},
"schemaVersion": "1.0.0.0"
}

0 comments on commit 1fd0838

Please sign in to comment.