Skip to content

Commit

Permalink
Use git version (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam authored Nov 18, 2023
1 parent e510382 commit 714940c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
7.0.x
8.0.x
- uses: actions/checkout@v4
- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow
- name: Restore
run: dotnet restore --nologo
- name: Build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
7.0.x
8.0.x
- uses: actions/checkout@v4
- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow
- name: Restore
run: dotnet restore --nologo
- name: Build
Expand Down
11 changes: 5 additions & 6 deletions src/PayPal.Sdk.Checkout/Core/PayPayEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using PayPal.Sdk.Checkout.Core.MessageSerializers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
Expand All @@ -18,15 +17,15 @@ public class PayPayEncoder : IPayPayEncoder

public PayPayEncoder()
{
_messageSerializers = new Collection<IMessageSerializer>
_messageSerializers = new IMessageSerializer[]
{
new FormEncodedSerializer(),
new JsonMessageSerializer(),
new TextSerializer(),
};
}

public async Task<HttpContent> SerializeRequestAsync<TRequestBody>(
public Task<HttpContent> SerializeRequestAsync<TRequestBody>(
TRequestBody body,
JsonTypeInfo<TRequestBody>? requestBodyJsonTypeInfo,
string contentType,
Expand All @@ -38,7 +37,7 @@ CancellationToken cancellationToken

if (serializer != null)
{
return await serializer.SerializeAsync(
return serializer.SerializeAsync(
body,
requestBodyJsonTypeInfo,
contentType,
Expand All @@ -49,7 +48,7 @@ CancellationToken cancellationToken
throw new ArgumentException($"Not found serializer for message {contentType}");
}

public async Task<TResponse> DeserializeResponseAsync<TResponse>(
public Task<TResponse> DeserializeResponseAsync<TResponse>(
HttpContent httpContent,
JsonTypeInfo<TResponse>? responseJsonTypeInfo,
MediaTypeHeaderValue mediaTypeHeaderValue,
Expand All @@ -63,7 +62,7 @@ CancellationToken cancellationToken

if (serializer != null)
{
return await serializer.DeserializeAsync(
return serializer.DeserializeAsync(
httpContent,
responseJsonTypeInfo,
mediaTypeHeaderValue,
Expand Down
22 changes: 21 additions & 1 deletion src/PayPal.Sdk.Checkout/Core/UserAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,27 @@ internal static class UserAgent
public static string GetUserAgentHeader()
{
var header = new StringBuilder("PayPalSDK/PayPal-NET-SDK ");
header.Append(Version.VERSION);
if (
GitInfo.TagMajor is { } major
&& GitInfo.TagMinor is { } minor
&& GitInfo.TagBuild is { } build
)
{
header.Append(major);
header.Append('.');
header.Append(minor);
header.Append('.');
header.Append(build);
}
else if (GitInfo.Tag is { } tag)
{
header.Append(tag);
}
else
{
header.Append(GitInfo.CommitHash);
}

header.Append(" (");
header.Append(string.Join(";", new[]
{
Expand Down
9 changes: 0 additions & 9 deletions src/PayPal.Sdk.Checkout/Core/Version.cs

This file was deleted.

19 changes: 18 additions & 1 deletion src/PayPal.Sdk.Checkout/PayPal.Sdk.Checkout.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,29 @@
<AVI_EJC_DefaultEnumDeserializationStrategy>UseBackingType|UseEnumName</AVI_EJC_DefaultEnumDeserializationStrategy>
</PropertyGroup>

<PropertyGroup Label="Configure GitInfo">
<GitInfo_RootDirectory>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'PayPal.Sdk.Checkout.sln'))\.git</GitInfo_RootDirectory>

<GitInfo_Namespace>PayPal.Sdk.Checkout</GitInfo_Namespace>

<!-- optional, default value 9 -->
<GitInfo_CommitAbbreviatedLength>9</GitInfo_CommitAbbreviatedLength>

<!-- optional, default value true -->
<GitInfo_UseCache>true</GitInfo_UseCache>

<!-- optional, default value false -->
<!-- it check only cache existence, not that HEAD equals HEAD in cache -->
<GitInfo_UseAggressiveCache>false</GitInfo_UseAggressiveCache>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aviationexam.GeneratedJsonConverters.SourceGenerator" Version="0.1.13" PrivateAssets="All" />
<PackageReference Include="Aviationexam.GeneratedJsonConverters.SourceGenerator" Version="0.1.13" PrivateAssets="all" />
<PackageReference Include="GitReader.SourceGenerator" Version="0.1.8" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<VersionPrefix>1.0.0</VersionPrefix>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 714940c

Please sign in to comment.