Skip to content

Commit

Permalink
feat(): add support for DateOnly and TimeOnly #680 (#734)
Browse files Browse the repository at this point in the history
* feat(): add .net6 and .net8 to core project and get it to compile #680

Signed-off-by: Joe Feser <[email protected]>

* feat(): add support for DateOnly and TimeOnly from .net 6 #680

Signed-off-by: Joe Feser <[email protected]>

* PR Comments

Signed-off-by: Joe Feser <[email protected]>

* PR Comments

Signed-off-by: Joe Feser <[email protected]>

* modified the added section of changelog.md

Signed-off-by: Joe Feser <[email protected]>

* Fix compilation/indentation error

Signed-off-by: Thomas Farr <[email protected]>

* Fix code conventions unit test

Signed-off-by: Thomas Farr <[email protected]>

* Fix remaining `#if`s

Signed-off-by: Thomas Farr <[email protected]>

* Fix changelog ordering

Signed-off-by: Thomas Farr <[email protected]>

* Fix CI errors

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Joe Feser <[email protected]>
Signed-off-by: Thomas Farr <[email protected]>
Co-authored-by: Thomas Farr <[email protected]>
  • Loading branch information
joefeser and Xtansia authored Jul 31, 2024
1 parent fbfb823 commit f3bae74
Show file tree
Hide file tree
Showing 32 changed files with 238 additions and 137 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/code-gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ jobs:
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- name: Cache Nuget Packages
uses: actions/cache@v3
Expand Down Expand Up @@ -59,11 +60,12 @@ jobs:
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- name: Cache Nuget Packages
uses: actions/cache@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/integration-yaml-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
Expand Down Expand Up @@ -96,6 +97,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
Expand Down Expand Up @@ -86,6 +87,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
Expand Down Expand Up @@ -67,6 +68,7 @@ jobs:
dotnet-version: |
5.0.x
6.0.x
8.0.x
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added
- Added support for `MinScore` on `ScriptScoreQuery` ([#624](https://github.com/opensearch-project/opensearch-net/pull/624))
- Added support for the `Cat.PitSegments` and `Cat.SegmentReplication` APIs ([#527](https://github.com/opensearch-project/opensearch-net/pull/527))
- Added support for serializing the `DateOnly` and `TimeOnly` types ([#734](https://github.com/opensearch-project/opensearch-net/pull/734))

### Removed
- Removed support for the `net461` target ([#256](https://github.com/opensearch-project/opensearch-net/pull/256))
Expand Down Expand Up @@ -198,4 +199,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
[1.6.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
61 changes: 31 additions & 30 deletions build/scripts/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ open Fake.IO.Globbing.Operators

module Main =

let private target name action = Targets.Target(name, Action(action))
let private target name action = Targets.Target(name, Action(action))
let private skip name = printfn "SKIPPED target '%s' evaluated not to run" name |> ignore
let private conditional name optional action = target name (if optional then action else (fun _ -> skip name))
let private conditional name optional action = target name (if optional then action else (fun _ -> skip name))
let private command name (dependencies: IEnumerable<string>) action = Targets.Target(name, dependencies, Action(action))
let private conditionalCommand name dependencies optional action = command name dependencies (if optional then action else (fun _ -> skip name))
let private conditionalCommand name dependencies optional action = command name dependencies (if optional then action else (fun _ -> skip name))

/// <summary>Sets command line environments indicating we are building from the command line</summary>
let setCommandLineEnvVars () =
Environment.setEnvironVar"OSC_COMMAND_LINE_BUILD" "1"

let sourceDir = Paths.TestsSource("Tests.Configuration");
let defaultYaml = Path.Combine(sourceDir, "tests.default.yaml");
let userYaml = Path.Combine(sourceDir, "tests.yaml");
Expand All @@ -56,59 +56,60 @@ module Main =
| (true, _) -> Environment.setEnvironVar "OSC_YAML_FILE" (Path.GetFullPath(userYaml))
| (_, true) -> Environment.setEnvironVar "OSC_YAML_FILE" (Path.GetFullPath(defaultYaml))
| _ -> failwithf "Expected to find a tests.default.yaml or tests.yaml in %s" sourceDir
let [<EntryPoint>] main args =


let [<EntryPoint>] main args =
async {
do! Async.SwitchToThreadPool ()

setCommandLineEnvVars ()

let parsed = Commandline.parse (args |> Array.toList)

let buildVersions = Versioning.BuildVersioning parsed
let artifactsVersion = Versioning.ArtifactsVersion buildVersions
Versioning.Validate parsed.Target buildVersions

let isCanary = parsed.Target = "canary";

Tests.SetTestEnvironmentVariables parsed

let testChain = ["clean"; "version"; "restore"; "full-build"; ]
let buildChain = ["test"; "inherit-doc" ]
let releaseChain =
[
[
"build";
"nuget-pack";
"nuget-pack-versioned";
// "nuget-pack-versioned";
"validate-artifacts";
"generate-release-notes"
]
let canaryChain = [ "version"; "release"; "test-nuget-package";]
// the following are expected to be called as targets directly
conditional "clean" (parsed.ReleaseBuild || parsed.Target = "clean") <| fun _ -> Build.Clean parsed

// the following are expected to be called as targets directly
conditional "clean" (parsed.ReleaseBuild || parsed.Target = "clean") <| fun _ -> Build.Clean parsed
target "version" <| fun _ -> printfn "Artifacts Version: %O" artifactsVersion
target "restore" Build.Restore

target "restore" Build.Restore
target "full-build" <| fun _ -> Build.Compile parsed artifactsVersion

//TEST
conditionalCommand "test" testChain (not parsed.SkipTests && not isCanary) <| fun _ -> Tests.RunUnitTests parsed

target "inherit-doc" <| InheritDoc.PatchInheritDocs

//BUILD
command "build" buildChain <| fun _ -> printfn "STARTING BUILD"

target "nuget-pack" <| fun _ -> Build.Pack artifactsVersion

conditional "nuget-pack-versioned" (isCanary) <| fun _ -> Build.VersionedPack artifactsVersion
// TODO: Re-enable once assembly-rewriter supports .NET 8.0
// conditional "nuget-pack-versioned" (isCanary) <| fun _ -> Build.VersionedPack artifactsVersion

conditional "generate-release-notes" (not isCanary) <| fun _ -> ReleaseNotes.GenerateNotes buildVersions

target "validate-artifacts" <| fun _ -> Versioning.ValidateArtifacts artifactsVersion

//RELEASE
command "release" releaseChain <| fun _ ->
let outputPath = match parsed.CommandArguments with | Commandline.SetVersion c -> c.OutputLocation | _ -> None
Expand All @@ -124,18 +125,18 @@ module Main =
printfn "Finished Release Build %O, output copied to: %s" artifactsVersion path

conditional "test-nuget-package" (not parsed.SkipTests) <| fun _ -> Tests.RunReleaseUnitTests artifactsVersion parsed

//CANARY
command "canary" canaryChain <| fun _ -> printfn "Finished Release Build %O" artifactsVersion

// ADDITIONAL COMMANDS

command "cluster" [ "restore"; "full-build" ] <| fun _ ->
ReposTooling.LaunchCluster parsed

command "codegen" [ ] <| fun _ ->
ReposTooling.GenerateApi parsed.RemainingArguments

command "rest-spec-tests" [ ] <| fun _ ->
ReposTooling.RestSpecTests parsed.RemainingArguments

Expand All @@ -145,5 +146,5 @@ module Main =

do! Targets.RunTargetsAndExitAsync([parsed.Target], (fun e -> e.GetType() = typeof<ProcExecException>)) |> Async.AwaitTask
} |> Async.RunSynchronously

0
10 changes: 5 additions & 5 deletions dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
"isRoot": true,
"tools": {
"assembly-rewriter": {
"version": "0.12.0",
"version": "0.13.0",
"commands": [
"assembly-rewriter"
]
},
"assembly-differ": {
"version": "0.13.0",
"version": "0.15.0",
"commands": [
"assembly-differ"
]
},
"nupkg-validator": {
"version": "0.4.0",
"version": "0.6.0",
"commands": [
"nupkg-validator"
]
},
"release-notes": {
"version": "0.3.1",
"version": "0.6.0",
"commands": [
"release-notes"
]
}
}
}
}
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.403",
"version": "8.0.107",
"rollForward": "latestFeature",
"allowPrerelease": false
},
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSearch.Net/Configuration/RequestMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal bool TryAddMetaData (string key, string value)
{
_metaDataItems ??= new Dictionary<string, string>();

#if NETSTANDARD2_1
#if NETSTANDARD2_1 || NET6_0_OR_GREATER
return _metaDataItems.TryAdd(key, value);
#else
if (_metaDataItems.ContainsKey(key))
Expand All @@ -55,7 +55,7 @@ internal bool TryAddMetaData (string key, string value)
_metaDataItems.Add(key, value);
return true;
#endif
}
}

public IReadOnlyDictionary<string, string> Items => _metaDataItems ?? EmptyReadOnly<string, string>.Dictionary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private HttpMessageHandler CreateHandler(int key, RequestData requestData)
{
if (requestData == null) throw new ArgumentNullException(nameof(requestData));

#if NETSTANDARD2_1
#if NETSTANDARD2_1 || NET6_0_OR_GREATER
var entry = _activeHandlers.GetOrAdd(key, (k, r) => _entryFactory(k, r), requestData).Value;
#else
var entry = _activeHandlers.GetOrAdd(key, (k) => _entryFactory(k, requestData)).Value;
Expand Down
4 changes: 4 additions & 0 deletions src/OpenSearch.Net/Connection/MetaData/RuntimeVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ private static string GetNetCoreVersion()

private static bool TryGetVersionFromAssemblyPath(Assembly assembly, out string runtimeVersion)
{
#if NET6_0_OR_GREATER
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
#else
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
#endif
var netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override void Reseed(IEnumerable<Node> nodes)
{
_readerWriter.EnterWriteLock();
var sortedNodes = SortNodes(nodesArray)
.DistinctBy(n => n.Uri)
.DistinctByInternal(n => n.Uri)
.ToList();

InternalNodes = sortedNodes;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch.Net/ConnectionPool/StaticConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void Initialize(IEnumerable<Node> nodes, IDateTimeProvider dateTimeProvi
}

InternalNodes = SortNodes(nodesProvided)
.DistinctBy(n => n.Uri)
.DistinctByInternal(n => n.Uri)
.ToList();
LastUpdate = DateTimeProvider.Now();
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch.Net/Extensions/UtilExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal static void ThrowIfNull<T>(this T value, string name) where T : class

internal static bool IsNullOrEmpty(this string value) => string.IsNullOrEmpty(value);

internal static IEnumerable<T> DistinctBy<T, TKey>(this IEnumerable<T> items, Func<T, TKey> property) =>
internal static IEnumerable<T> DistinctByInternal<T, TKey>(this IEnumerable<T> items, Func<T, TKey> property) =>
items.GroupBy(property).Select(x => x.First());

internal static string ToTimeUnit(this TimeSpan timeSpan)
Expand Down
4 changes: 3 additions & 1 deletion src/OpenSearch.Net/OpenSearch.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>

<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
Expand Down
6 changes: 3 additions & 3 deletions src/OpenSearch.Net/Providers/RecyclableMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public int SafeRead(byte[] buffer, int offset, int count, ref int streamPosition
return amountRead;
}

#if NETCOREAPP2_1 || NETSTANDARD2_1
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
/// <summary>
/// Reads from the current position into the provided buffer
/// </summary>
Expand Down Expand Up @@ -649,7 +649,7 @@ public override void Write(byte[] buffer, int offset, int count)
_length = Math.Max(_position, _length);
}

#if NETCOREAPP2_1 || NETSTANDARD2_1
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
/// <summary>
/// Writes the buffer to the stream
/// </summary>
Expand Down Expand Up @@ -866,7 +866,7 @@ private int InternalRead(byte[] buffer, int offset, int count, int fromPosition)
return amountToCopy;
}

#if NETCOREAPP2_1 || NETSTANDARD2_1
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
private int InternalRead(Span<byte> buffer, int fromPosition)
{
if (_length - fromPosition <= 0) return 0;
Expand Down
Loading

0 comments on commit f3bae74

Please sign in to comment.