Skip to content

Commit

Permalink
Implemented multitargeting | update CI | update version
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomez90 committed Feb 16, 2022
1 parent 92ebb43 commit b2d108b
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 179 deletions.
45 changes: 32 additions & 13 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,41 @@ on:
jobs:
build:
env:
VERSION: 0.1.0
NUGET_API_KEY: ${{secrets.NUGET_API_KEY}}

runs-on: ubuntu-latest
NUGET_API_KEY:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore /property:Version=$VERSION.$GITHUB_RUN_NUMBER
uses: actions/setup-dotnet@v1

- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Publish Nuget
run: dotnet nuget push TeamsHook.NET/bin/Release/TeamsHook.NET.$VERSION.$GITHUB_RUN_NUMBER.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json

- name: Publish Nuget on version change
uses: rohith/publish-nuget@v2
with:
# Filepath of the project to be packaged, relative to root of repository
PROJECT_FILE_PATH: TeamsHook.NET/TeamsHook.NET.csproj

# Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH
# VERSION_FILE_PATH: Directory.Build.props

# Regex pattern to extract version info in a capturing group
VERSION_REGEX: ^\s*<Version>(.*)<\/Version>\s*$

# Flag to toggle git tagging, enabled by default
TAG_COMMIT: true

# Format of the git tag, [*] gets replaced with actual version
TAG_FORMAT: v*

# API key to authenticate with NuGet server
NUGET_KEY: ${{secrets.NUGET_API_KEY}}

# NuGet server uri hosting the packages, defaults to https://api.nuget.org
# NUGET_SOURCE: https://api.nuget.org

# Flag to toggle pushing symbols along with nuget package to the server, disabled by default
# INCLUDE_SYMBOLS: false
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,7 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

#Jetbrains Rider
.idea/
11 changes: 4 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.1.0.0-pre</Version>
<Version>0.2.0-pre</Version>
<Product>TeamsHook.NET</Product>
<Description>.NET Client for sending messages to Microsoft Teams via Webhooks</Description>
<Company>Rafael Gómez</Company>
Expand All @@ -11,11 +11,8 @@
<PackageProjectUrl>https://github.com/rgomez90/TeamsHook.NET</PackageProjectUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>Latest</LangVersion>
<Features>strict</Features>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup>
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>
94 changes: 0 additions & 94 deletions TeamsHook.NET.Tests/NewtonsoftTests.cs

This file was deleted.

10 changes: 5 additions & 5 deletions TeamsHook.NET.Tests/SystemTextJsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void JsonTestActionsMessageCard()
{
Title = "SectionTitle",
Text = "SectionText",
ActivityText = "11 Vorgänge gefunden",
ActivityText = "11 Vorg�nge gefunden",
ActivitySubtitle = DateTime.Now.ToString("G"),
ActivityTitle = "Offene FE",
Facts = new List<MessageFact>()
Expand All @@ -67,7 +67,7 @@ public void JsonTestActionsMessageCard()
{
Title = "SectionTitle",
Text = "<table bordercolor='black' border= '2'><thead><tr style = 'background-color : Teal; color: White'><th>Task</th><th>Status</th><th>Start Time</th><th>End Time</th></tr></thead></thead><tbody ><tr><td>xxx</td><td>yyy</td><td>14:25</td></tr><tr><td>xxx</td><td>yyy</td><td>15:25</td><td>16:25</td></tr></tbody></table>",
ActivityText = "11 Vorgänge gefunden",
ActivityText = "11 Vorg�nge gefunden",
ActivitySubtitle = DateTime.Now.ToString("G"),
ActivityTitle = "Offene FE",
Facts = new List<MessageFact>()
Expand All @@ -90,7 +90,7 @@ public void JsonTestActionsMessageCard()
}
}
};
var json = JsonSerializer.Serialize(card, TeamsHookSystemTextSerializationOptions.Instance);
var json = JsonSerializer.Serialize(card, TeamsHookJsonSettings.Default());
string expectedJson = "";
//Assert.True(json == expectedJson);
}
Expand Down Expand Up @@ -155,9 +155,9 @@ public void JsonTestMessageCard()
}
}
};
var json = JsonSerializer.Serialize(card, TeamsHookSystemTextSerializationOptions.Instance);
var json = JsonSerializer.Serialize(card, TeamsHookJsonSettings.Default());
string expectedJson = "";
//Assert.True(json == expectedJson);
}
}
}
}
3 changes: 0 additions & 3 deletions TeamsHook.NET/IMessageAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace TeamsHook.NET
{
Expand All @@ -10,8 +9,6 @@ protected MessageAction(MessageActionType type)
Type = type;
}

[JsonPropertyName("@type")]
[JsonProperty("@type")]
public MessageActionType Type { get; private set; }
}
}
13 changes: 6 additions & 7 deletions TeamsHook.NET/Input.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace TeamsHook.NET
namespace TeamsHook.NET
{
public abstract class Input
{
Expand All @@ -11,11 +8,13 @@ protected Input(MessageInputType type)
}

public string Id { get; set; }

public bool IsRequired { get; set; }

public string Title { get; set; }
[JsonPropertyName("@type")]
[JsonProperty("@type")]
public MessageInputType Type { get; }

public MessageInputType Type { get; private set; }

public string Value { get; set; }
}
}
6 changes: 3 additions & 3 deletions TeamsHook.NET/MessageCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public MessageCard() : base(CardType.MessageCard)
{
}

public Guid CorrelationId { get; set; }
public Guid CorrelationId { get; set; }
public string[] ExpectedActors { get; set; }
public bool HideOriginalBody { get; set; }
public string Originator { get; set; }
public IList<MessageAction> PotentialAction { get; set; }
public IList<Section> Sections { get; set; }
public IList<MessageAction> PotentialAction { get; set; } = new List<MessageAction>();
public IList<Section> Sections { get; set; } = new List<Section>();
public string Summary { get; set; }
public string Text { get; set; }
public string ThemeColor { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion TeamsHook.NET/MultiChoiceInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public MultiChoiceInput() : base(MessageInputType.MultiChoiceInput)
{
}

public IList<Choice> Choices { get; set; }
public IList<Choice> Choices { get; set; } = new List<Choice>();
public bool IsMultiSelect { get; set; }
public string Style { get; set; }
}
Expand Down
7 changes: 2 additions & 5 deletions TeamsHook.NET/TeamsCard.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace TeamsHook.NET
{
Expand All @@ -11,12 +10,10 @@ protected TeamsCard(CardType cardType)
Context = "http://schema.org/extensions";
}

[JsonPropertyName("@type")]
[JsonProperty("@type")]
[JsonPropertyName("type")]
public CardType CardType { get; private set; }

[JsonPropertyName("@context")]
[JsonProperty("@context")]
[JsonPropertyName("context")]
public string Context { get; private set; }
}
}
8 changes: 4 additions & 4 deletions TeamsHook.NET/TeamsHook.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TargetFrameworks>net5.0;net6.0;netcoreapp3.1;netstandard2.0</TargetFrameworks>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="System.Text.Json" Version="5.0.0-preview.7.20364.11" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>
</Project>
6 changes: 4 additions & 2 deletions TeamsHook.NET/TeamsHookClient.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace TeamsHook.NET
{
public class TeamsHookClient
{
private readonly HttpClient _client;
private readonly JsonSerializerOptions _jsonSettings;

public TeamsHookClient(HttpClient client = null)
{
_client = client ?? new HttpClient();
_jsonSettings = TeamsHookJsonSettings.Default();
}

public Task<HttpResponseMessage> PostAsync(string webhookUrl, TeamsCard card)
{
var payload = JsonConvert.SerializeObject(card, new TeamsNewtonsoftSerializationOptions());
var payload = JsonSerializer.Serialize(card, _jsonSettings);
return _client.PostAsync(webhookUrl, new StringContent(payload, Encoding.UTF8, "application/json"));
}
}
Expand Down
18 changes: 18 additions & 0 deletions TeamsHook.NET/TeamsHookJsonSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace TeamsHook.NET;

public static class TeamsHookJsonSettings
{
public static JsonSerializerOptions Default()
{
var settings = new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false,
};
settings.Converters.Add(new JsonStringEnumConverter());
return settings;
}
};
Loading

0 comments on commit b2d108b

Please sign in to comment.