diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..935e327 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,147 @@ +root=true + +[*.cs] +trim_trailing_whitespace=true +insert_final_newline=true +end_of_line = lf + +[*] +charset = utf-8 +indent_style = tab +indent_size = 4 + +[*.cshtml] +indent_style = tab +indent_size = 4 +end_of_line = lf + +[*.{fs,fsx,yml}] +indent_style = space +indent_size = 4 +end_of_line = lf + +[*.{md,markdown,json,js,csproj,fsproj,targets,targets,props}] +indent_style = space +indent_size = 2 +end_of_line = lf + +# Dotnet code style settings: +[*.{cs,vb}] + +# --- +# naming conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions +# currently not supported in Rider/Resharper so not using these for now +# --- + +# --- +# langugage conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#language-conventions + +# Sort using and Import directives with System.* appearing first +dotnet_sort_system_directives_first = true + +# Prefer this.X except for _fields +# TODO can we force _ for private fields? +# TODO elevate severity after code cleanup to warning minimum +# TODO use language latest +dotnet_style_qualification_for_field = false:error +dotnet_style_qualification_for_property = false:error +dotnet_style_qualification_for_method = false:error +dotnet_style_qualification_for_event = false:error + +# Use language keywords instead of framework type names for type references +dotnet_style_predefined_type_for_locals_parameters_members = true:error +dotnet_style_predefined_type_for_member_access = true:error + +# Suggest more modern language features when available +dotnet_style_object_initializer = true:error +dotnet_style_collection_initializer = true:error +dotnet_style_explicit_tuple_names = true:error +dotnet_style_prefer_inferred_anonymous_type_member_names = true:error +dotnet_style_prefer_inferred_tuple_names = true:error +dotnet_style_coalesce_expression = true:error +dotnet_style_null_propagation = true:error + +dotnet_style_require_accessibility_modifiers = for_non_interface_members:error +dotnet_style_readonly_field = true:error + +# CSharp code style settings: +[*.cs] +# Prefer "var" everywhere +csharp_style_var_for_built_in_types = true:error +csharp_style_var_when_type_is_apparent = true:error +csharp_style_var_elsewhere = true:error + +csharp_style_expression_bodied_methods = true:error +csharp_style_expression_bodied_constructors = true:error +csharp_style_expression_bodied_operators = true:error +csharp_style_expression_bodied_properties = true:error +csharp_style_expression_bodied_indexers = true:error +csharp_style_expression_bodied_accessors = true:error + +# Suggest more modern language features when available +csharp_style_pattern_matching_over_is_with_cast_check = true:error +csharp_style_pattern_matching_over_as_with_null_check = true:error +csharp_style_inlined_variable_declaration = true:error +csharp_style_deconstructed_variable_declaration = true:error +csharp_style_pattern_local_over_anonymous_function = true:error +csharp_style_throw_expression = true:error +csharp_style_conditional_delegate_call = true:error + +csharp_prefer_braces = false:warning +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error + +# --- +# formatting conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions + +# Newline settings (Allman yo!) +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true:error +csharp_new_line_before_catch = true:error +csharp_new_line_before_finally = true:error +csharp_new_line_before_members_in_object_initializers = true +# just a suggestion do to our JSON tests that use anonymous types to +# represent json quite a bit (makes copy paste easier). +csharp_new_line_before_members_in_anonymous_types = true:suggestion +csharp_new_line_between_query_expression_clauses = true:error + +# Indent +csharp_indent_case_contents = true:error +csharp_indent_switch_labels = true:error +csharp_space_after_cast = false:error +csharp_space_after_keywords_in_control_flow_statements = true:error +csharp_space_between_method_declaration_parameter_list_parentheses = false:error +csharp_space_between_method_call_parameter_list_parentheses = false:error + +#Wrap +csharp_preserve_single_line_statements = false:error +csharp_preserve_single_line_blocks = true:error + +csharp_style_namespace_declarations = file_scoped + +# Resharper +resharper_csharp_braces_for_lock=required_for_complex +resharper_csharp_braces_for_using=required_for_complex +resharper_csharp_braces_for_while=required_for_complex +resharper_csharp_braces_for_foreach=required_for_complex +resharper_csharp_braces_for_for=required_for_complex +resharper_csharp_braces_for_fixed=required_for_complex +resharper_csharp_braces_for_ifelse=required_for_complex + +resharper_csharp_accessor_owner_body=expression_body + +resharper_redundant_case_label_highlighting=do_not_show +resharper_redundant_argument_default_value_highlighting=do_not_show +# Do not penalize code that explicitly lists generic arguments +resharper_redundant_type_arguments_of_method_highlighting=do_not_show + +[Jenkinsfile] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{sh,bat,ps1}] +trim_trailing_whitespace=true +insert_final_newline=true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..08d9181 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,15 @@ +# Auto detect text files and perform LF normalization +* text=auto eol=lf + +# Set default behavior for command prompt diff. +# This gives output on command line taking C# language constructs into consideration (e.g showing class name) +*.cs text diff=csharp + +# Set windows specific files explicitly to crlf line ending +*.cmd eol=crlf +*.bat eol=crlf +*.ps1 eol=crlf + +# Mark files specifically as binary to avoid line ending conversion +*.snk binary +*.png binary \ No newline at end of file diff --git a/.github/add-license-headers.sh b/.github/add-license-headers.sh new file mode 100644 index 0000000..dfe67ef --- /dev/null +++ b/.github/add-license-headers.sh @@ -0,0 +1,14 @@ +#!/bin/bash +script_path=$(dirname $(realpath -s $0))/../ + +function add_license () { + (find "$script_path" -name $1 | grep -v "/bin/" | grep -v "/obj/" )|while read fname; do + line=$(sed -n '2p;3q' "$fname") + if ! [[ "$line" == " * Licensed to Elasticsearch B.V. under one or more contributor" ]] ; then + cat "${script_path}.github/license-header.txt" "$fname" > "${fname}.new" + mv "${fname}.new" "$fname" + fi + done +} + +add_license "*.cs" \ No newline at end of file diff --git a/.github/check-license-headers.sh b/.github/check-license-headers.sh new file mode 100755 index 0000000..d80c95a --- /dev/null +++ b/.github/check-license-headers.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# Check that source code files in this repo have the appropriate license +# header. + +if [ "$TRACE" != "" ]; then + export PS4='${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' + set -o xtrace +fi +set -o errexit +set -o pipefail + +TOP=$(cd "$(dirname "$0")/.." >/dev/null && pwd) +NLINES=$(wc -l .github/license-header.txt | awk '{print $1}') + +function check_license_header { + local f + f=$1 + if ! diff .github/license-header.txt <(head -$NLINES "$f") >/dev/null; then + echo "check-license-headers: error: '$f' does not have required license header, see 'diff -u .github/license-header.txt <(head -$NLINES $f)'" + return 1 + else + return 0 + fi +} + +cd "$TOP" +nErrors=0 +for f in $(git ls-files | grep '\.cs$'); do + if ! check_license_header $f; then + nErrors=$((nErrors+1)) + fi +done + +for f in $(git ls-files | grep '\.fs$'); do + if ! check_license_header $f; then + nErrors=$((nErrors+1)) + fi +done + +if [[ $nErrors -eq 0 ]]; then + exit 0 +else + exit 1 +fi \ No newline at end of file diff --git a/.github/license-header.txt b/.github/license-header.txt new file mode 100644 index 0000000..52c5ed5 --- /dev/null +++ b/.github/license-header.txt @@ -0,0 +1,3 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..55622ce --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +name: Always be deploying + +on: + pull_request: + paths-ignore: + - 'README.md' + - '.editorconfig' + push: + paths-ignore: + - 'README.md' + - '.editorconfig' + branches: + - main + tags: + - "*.*.*" + +jobs: + build: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - run: | + git fetch --prune --unshallow --tags + echo exit code $? + git tag --list + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: | + 5.0.x + 6.0.x + source-url: https://nuget.pkg.github.com/elastic/index.json + env: + NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + + - run: ./build.sh build -s true + name: Build + - run: ./build.sh test -s true + name: Test + - run: ./build.sh generatepackages -s true + name: Generate local nuget packages + - run: ./build.sh validatepackages -s true + name: "validate *.npkg files that were created" + - run: ./build.sh generateapichanges -s true + name: "Inspect public API changes" + + - name: publish canary packages github package repository + if: github.event_name == 'push' && startswith(github.ref, 'refs/heads') + shell: bash + run: | + until dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.GITHUB_TOKEN}} --skip-duplicate --no-symbols; do echo "Retrying"; sleep 1; done; + + # Github packages requires authentication, this is likely going away in the future so for now we publish to feedz.io + - run: dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.FEEDZ_IO_API_KEY}} -s https://f.feedz.io/elastic/all/nuget/index.json --skip-duplicate --no-symbols + name: publish canary packages to feedz.io + if: github.event_name == 'push' && startswith(github.ref, 'refs/heads') + + - run: ./build.sh generatereleasenotes -s true + name: Generate release notes for tag + if: github.event_name == 'push' && startswith(github.ref, 'refs/tags') + - run: ./build.sh createreleaseongithub -s true --token ${{secrets.GITHUB_TOKEN}} + if: github.event_name == 'push' && startswith(github.ref, 'refs/tags') + name: Create or update release for tag on github + + - run: dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.NUGET_ORG_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols + name: release to nuget.org + if: github.event_name == 'push' && startswith(github.ref, 'refs/tags') diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml new file mode 100644 index 0000000..c42f591 --- /dev/null +++ b/.github/workflows/license.yml @@ -0,0 +1,15 @@ +name: License headers + +on: [pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Check license headers + run: | + ./.github/check-license-headers.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32b2f99 --- /dev/null +++ b/.gitignore @@ -0,0 +1,82 @@ +*.userprefs +*.local.xml +*.sln.docstates +*.obj +*.swp +*.exe +*.pdb +*.user +*.aps +*.pch +*.tss +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +*.nupkg +*.ncrunchsolution +[Bb]in +[Dd]ebug/ +test-results +test-results/* +*.lib +*.sbr +*.DotSettings.user +obj/ +[Rr]elease*/ +_ReSharper*/ +_NCrunch*/ +[Tt]est[Rr]esult* + +.fake/* +.fake +packages/* +paket.exe +paket-files/*.cached + +build/* +!build/tools +!build/keys +build/tools/* +!build/tools/sn +!build/tools/sn/* +!build/tools/ilmerge +!build/*.fsx +!build/*.fsx +!build/*.ps1 +!build/*.nuspec +!build/*.png +!build/*.targets +!build/scripts + +!docs/build +docs/node_modules +doc/Help + +*.ncrunchproject +Cache +YamlCache +tests.yaml + +*.DS_Store +*.sln.ide + +launchSettings.json +project.lock.json +.vs +.vs/* + +.idea/ +*.sln.iml +/src/.vs/restore.dg +src/packages/ +BenchmarkDotNet.Artifacts + +/.ionide/symbolCache.db \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..f698c7b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +Location: https://www.elastic.co/community/codeofconduct \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..bcbb92c --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,26 @@ + + + + + $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.bat)) + + canary + 0.1 + + latest + true + False + false + true + $(SolutionRoot)\build\keys\keypair.snk + + $(DefineConstants);FULLFRAMEWORK + $(DefineConstants);DOTNETCORE + + + + + + + + \ No newline at end of file diff --git a/NOTICE.txt b/NOTICE.txt new file mode 100644 index 0000000..2dd2628 --- /dev/null +++ b/NOTICE.txt @@ -0,0 +1,31 @@ +Elastic .NET Ingestion Libraries +Copyright 2012-2021 Elasticsearch B.V. + +========== +Notice for: Microsoft.IO.RecyclableMemoryStream +---------- +Based on the Microsoft.IO.RecyclableMemoryStream project by Microsoft, +licensed under the MIT license. https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream/ + +MIT License + +Copyright (c) 2015-2016 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..186d991 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# `Elastic.Ingest` + + +## Usage + + +```c# +``` + + +### Projects + diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..64d090f --- /dev/null +++ b/build.bat @@ -0,0 +1,3 @@ +@echo off +dotnet run --project build/scripts -- %* + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..8c4d9c1 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +dotnet run --project build/scripts -- "$@" diff --git a/build/keys/keypair.snk b/build/keys/keypair.snk new file mode 100644 index 0000000..2cde087 Binary files /dev/null and b/build/keys/keypair.snk differ diff --git a/build/keys/public.snk b/build/keys/public.snk new file mode 100644 index 0000000..13f0427 Binary files /dev/null and b/build/keys/public.snk differ diff --git a/build/scripts/CommandLine.fs b/build/scripts/CommandLine.fs new file mode 100644 index 0000000..12a4cc5 --- /dev/null +++ b/build/scripts/CommandLine.fs @@ -0,0 +1,51 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +module CommandLine + +open Argu +open Microsoft.FSharp.Reflection + +type Arguments = + | [] Clean + | [] Build + | [] Test + + | [] PristineCheck + | [] GeneratePackages + | [] ValidatePackages + | [] GenerateReleaseNotes + | [] GenerateApiChanges + | [] Release + + | [] CreateReleaseOnGithub + | [] Publish + + | [] SingleTarget of bool + | [] Token of string + | [] CleanCheckout of bool +with + interface IArgParserTemplate with + member this.Usage = + match this with + | Clean _ -> "clean known output locations" + | Build _ -> "Run build" + | Test _ -> "Runs build then tests" + | Release _ -> "runs build, tests, and create and validates the packages shy of publishing them" + | Publish _ -> "Runs the full release" + + | SingleTarget _ -> "Runs the provided sub command without running their dependencies" + | Token _ -> "Token to be used to authenticate with github" + | CleanCheckout _ -> "Skip the clean checkout check that guards the release/publish targets" + + | PristineCheck + | GeneratePackages + | ValidatePackages + | GenerateReleaseNotes + | GenerateApiChanges + | CreateReleaseOnGithub + -> "Undocumented, dependent target" + member this.Name = + match FSharpValue.GetUnionFields(this, typeof) with + | case, _ -> case.Name.ToLowerInvariant() diff --git a/build/scripts/Paths.fs b/build/scripts/Paths.fs new file mode 100644 index 0000000..c0b858e --- /dev/null +++ b/build/scripts/Paths.fs @@ -0,0 +1,29 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +module Paths + +open System +open System.IO + +let ToolName = "elastic-transport-net" +let Repository = sprintf "elastic/%s" ToolName +let MainTFM = "netstandard2.0" +let SignKey = "069ca2728db333c1" + +let ValidateAssemblyName = false +let IncludeGitHashInInformational = true +let GenerateApiChanges = false + +let Root = + let mutable dir = DirectoryInfo(".") + while dir.GetFiles("*.sln").Length = 0 do dir <- dir.Parent + Environment.CurrentDirectory <- dir.FullName + dir + +let RootRelative path = Path.GetRelativePath(Root.FullName, path) + +let Output = DirectoryInfo(Path.Combine(Root.FullName, "build", "output")) + +let ToolProject = DirectoryInfo(Path.Combine(Root.FullName, "src", ToolName)) diff --git a/build/scripts/Program.fs b/build/scripts/Program.fs new file mode 100644 index 0000000..a574d9a --- /dev/null +++ b/build/scripts/Program.fs @@ -0,0 +1,36 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +module Program + +open Argu +open Bullseye +open ProcNet +open CommandLine + +[] +let main argv = + let parser = ArgumentParser.Create(programName = "./build.sh") + let parsed = + try + let parsed = parser.ParseCommandLine(inputs = argv, raiseOnUsage = true) + let arguments = parsed.GetSubCommand() + Some (parsed, arguments) + with e -> + printfn "%s" e.Message + None + + match parsed with + | None -> 2 + | Some (parsed, arguments) -> + + let target = arguments.Name + + Targets.Setup parsed arguments + let swallowTypes = [typeof; typeof] + + Targets.RunTargetsAndExit + ([target], (fun e -> swallowTypes |> List.contains (e.GetType()) ), ":") + 0 + diff --git a/build/scripts/Targets.fs b/build/scripts/Targets.fs new file mode 100644 index 0000000..bd5fd92 --- /dev/null +++ b/build/scripts/Targets.fs @@ -0,0 +1,170 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +module Targets + +open Argu +open System +open System.IO +open Bullseye +open CommandLine +open Fake.Tools.Git +open ProcNet + + +let exec binary args = + let r = Proc.Exec (binary, args |> List.map (fun a -> sprintf "\"%s\"" a) |> List.toArray) + match r.HasValue with | true -> r.Value | false -> failwithf "invocation of `%s` timed out" binary + +let private restoreTools = lazy(exec "dotnet" ["tool"; "restore"]) +let private currentVersion = + lazy( + restoreTools.Value |> ignore + let r = Proc.Start("dotnet", "minver", "--default-pre-release-phase", "canary", "-m", "0.1") + let o = r.ConsoleOut |> Seq.find (fun l -> not(l.Line.StartsWith("MinVer:"))) + o.Line + ) +let private currentVersionInformational = + lazy( + match Paths.IncludeGitHashInInformational with + | false -> currentVersion.Value + | true -> sprintf "%s+%s" currentVersion.Value (Information.getCurrentSHA1( ".")) + ) + +let private clean (arguments:ParseResults) = + if (Paths.Output.Exists) then Paths.Output.Delete (true) + exec "dotnet" ["clean"] |> ignore + +let private build (arguments:ParseResults) = exec "dotnet" ["build"; "-c"; "Release"] |> ignore + +let private pristineCheck (arguments:ParseResults) = + let doCheck = arguments.TryGetResult CleanCheckout |> Option.defaultValue true + match doCheck, Information.isCleanWorkingCopy "." with + | _, true -> printfn "The checkout folder does not have pending changes, proceeding" + | false, _ -> printf "Checkout is dirty but -c was specified to ignore this" + | _ -> failwithf "The checkout folder has pending changes, aborting" + +let private test (arguments:ParseResults) = + let junitOutput = Path.Combine(Paths.Output.FullName, "junit-{assembly}-{framework}-test-results.xml") + let loggerPathArgs = sprintf "LogFilePath=%s" junitOutput + let loggerArg = sprintf "--logger:\"junit;%s\"" loggerPathArgs + exec "dotnet" ["test"; "-c"; "RELEASE"; loggerArg] |> ignore + +let private generatePackages (arguments:ParseResults) = + let output = Paths.RootRelative Paths.Output.FullName + exec "dotnet" ["pack"; "-c"; "Release"; "-o"; output] |> ignore + +let private validatePackages (arguments:ParseResults) = + let output = Paths.RootRelative <| Paths.Output.FullName + let nugetPackages = + Paths.Output.GetFiles("*.nupkg") |> Seq.sortByDescending(fun f -> f.CreationTimeUtc) + |> Seq.map (fun p -> Paths.RootRelative p.FullName) + + let jenkinsOnWindowsArgs = + if Fake.Core.Environment.hasEnvironVar "JENKINS_URL" && Fake.Core.Environment.isWindows then ["-r"; "true"] else [] + + let args = ["-v"; currentVersionInformational.Value; "-k"; Paths.SignKey; "-t"; output] @ jenkinsOnWindowsArgs + nugetPackages |> Seq.iter (fun p -> exec "dotnet" (["nupkg-validator"; p] @ args) |> ignore) + + +let private generateApiChanges (arguments:ParseResults) = + let output = Paths.RootRelative <| Paths.Output.FullName + let currentVersion = currentVersion.Value + let nugetPackages = + Paths.Output.GetFiles("*.nupkg") |> Seq.sortByDescending(fun f -> f.CreationTimeUtc) + |> Seq.map (fun p -> Path.GetFileNameWithoutExtension(Paths.RootRelative p.FullName).Replace("." + currentVersion, "")) + nugetPackages + |> Seq.iter(fun p -> + let outputFile = + let f = sprintf "breaking-changes-%s.md" p + Path.Combine(output, f) + let args = + [ + "assembly-differ" + (sprintf "previous-nuget|%s|%s|%s" p currentVersion Paths.MainTFM); + (sprintf "directory|src/%s/bin/Release/%s" p Paths.MainTFM); + "-a"; "true"; "--target"; p; "-f"; "github-comment"; "--output"; outputFile + ] + + exec "dotnet" args |> ignore + ) + +let private generateReleaseNotes (arguments:ParseResults) = + let currentVersion = currentVersion.Value + let output = + Paths.RootRelative <| Path.Combine(Paths.Output.FullName, sprintf "release-notes-%s.md" currentVersion) + let tokenArgs = + match arguments.TryGetResult Token with + | None -> [] + | Some token -> ["--token"; token;] + let releaseNotesArgs = + (Paths.Repository.Split("/") |> Seq.toList) + @ ["--version"; currentVersion + "--label"; "enhancement"; "New Features" + "--label"; "bug"; "Bug Fixes" + "--label"; "documentation"; "Docs Improvements" + ] @ tokenArgs + @ ["--output"; output] + + exec "dotnet" (["release-notes"] @ releaseNotesArgs) |> ignore + +let private createReleaseOnGithub (arguments:ParseResults) = + let currentVersion = currentVersion.Value + let tokenArgs = + match arguments.TryGetResult Token with + | None -> [] + | Some token -> ["--token"; token;] + let releaseNotes = Paths.RootRelative <| Path.Combine(Paths.Output.FullName, sprintf "release-notes-%s.md" currentVersion) + let breakingChanges = + let breakingChangesDocs = Paths.Output.GetFiles("breaking-changes-*.md") + breakingChangesDocs + |> Seq.map(fun f -> ["--body"; Paths.RootRelative f.FullName]) + |> Seq.collect id + |> Seq.toList + let releaseArgs = + (Paths.Repository.Split("/") |> Seq.toList) + @ ["create-release" + "--version"; currentVersion + "--body"; releaseNotes; + ] @ breakingChanges @ tokenArgs + + exec "dotnet" (["release-notes"] @ releaseArgs) |> ignore + +let private release (arguments:ParseResults) = printfn "release" + +let private publish (arguments:ParseResults) = printfn "publish" + +let Setup (parsed:ParseResults) (subCommand:Arguments) = + let step (name:string) action = Targets.Target(name, new Action(fun _ -> action(parsed))) + + let cmd (name:string) commandsBefore steps action = + let singleTarget = (parsed.TryGetResult SingleTarget |> Option.defaultValue false) + let deps = + match (singleTarget, commandsBefore) with + | (true, _) -> [] + | (_, Some d) -> d + | _ -> [] + let steps = steps |> Option.defaultValue [] + Targets.Target(name, deps @ steps, Action(action)) + + step Clean.Name clean + cmd Build.Name None (Some [Clean.Name]) <| fun _ -> build parsed + + cmd Test.Name (Some [Build.Name;]) None <| fun _ -> test parsed + + step PristineCheck.Name pristineCheck + step GeneratePackages.Name generatePackages + step ValidatePackages.Name validatePackages + step GenerateReleaseNotes.Name generateReleaseNotes + step GenerateApiChanges.Name generateApiChanges + cmd Release.Name + (Some [PristineCheck.Name; Test.Name;]) + (Some [GeneratePackages.Name; ValidatePackages.Name; GenerateReleaseNotes.Name; GenerateApiChanges.Name]) + <| fun _ -> release parsed + + step CreateReleaseOnGithub.Name createReleaseOnGithub + cmd Publish.Name + (Some [Release.Name]) + (Some [CreateReleaseOnGithub.Name; ]) + <| fun _ -> publish parsed diff --git a/build/scripts/scripts.fsproj b/build/scripts/scripts.fsproj new file mode 100644 index 0000000..9adc9fe --- /dev/null +++ b/build/scripts/scripts.fsproj @@ -0,0 +1,22 @@ + + + + Exe + net5.0 + false + + + + + + + + + + + + + + + + diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..15392c1 --- /dev/null +++ b/contributing.md @@ -0,0 +1,73 @@ +# Contributing + +Contributing back to these projects is very much appreciated. Whether you feel the need to change a single character or have a go at implementing a new integration, no pull request (PR) is too small or too big. + +In fact many of our most awesome features/fixes have been provided to us by [these wonderful folks](https://github.com/elastic/elastic-ingest-dotnet/graphs/contributors) to which we are forever indebted. + +It's usually best to open an issue first to discuss a feature or bug, before opening a pull request. Doing so can save time and help further determine the fundamentals of an issue. + +## Code of Conduct + +Please read the Elastic [Community Code of Conduct](https://www.elastic.co/community/codeofconduct) to understand our stance on community engagement. + +## Sign the CLA + +We do ask that you sign the [Elasticsearch CLA](https://www.elastic.co/contributor-agreement) before we can accept pull requests from you. + +## Coding Styleguide + +Please install the [Editorconfig Visual Studio extension](https://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328) this will automatically switch to our indentation, whitespace, newlines settings while working on our project **while leaving your default settings intact**. + +In most cases we won't shun a PR just because it uses the wrong indentation settings, though it'll be **very** much appreciated if it is already done! + +## Tests + +PRs with tests are more likely to be reviewed faster because it makes the job of reviewing the PR much easier. That being said, +we respect that you may be fixing a bug for yourself and may not have the time or energy to submit a PR with complete tests. + +In those cases we tend to pull your code locally and write tests ourselves, but this may mean your PR might sit idle longer than you would like. + +# Building the solution + +The solution uses a number of awesome Open Source software tools to ease development: + +## Bullseye + +[Bullseye](https://github.com/adamralph/bullseye) is used as the build automation system for the solution. To get started after cloning the solution, it's best to run the build script in the root directory. + +for Windows + +``` +.\build.bat +``` + +for OSX/Linux + +``` +./build.sh +``` + +This will + +- Pull down all the dependencies for the build process as well as the solution +- Run the default build target for the solution + +You can also compile the solution within Visual Studio if you prefer, but the build script is going to be _much_ faster. + +For the full list of options available you are able to run: + +``` +.\build.bat help +``` + +## Tests + +The `tests` folder contains unit and integration tests. + +### Compile and run unit tests + +```bat +.\build.bat +``` + +...with no target will run the `build` target, compiling the solution and running unit tests. diff --git a/dotnet-tools.json b/dotnet-tools.json new file mode 100644 index 0000000..c0b6b3e --- /dev/null +++ b/dotnet-tools.json @@ -0,0 +1,30 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "minver-cli": { + "version": "2.5.0", + "commands": [ + "minver" + ] + }, + "assembly-differ": { + "version": "0.13.0", + "commands": [ + "assembly-differ" + ] + }, + "release-notes": { + "version": "0.3.0", + "commands": [ + "release-notes" + ] + }, + "nupkg-validator": { + "version": "0.5.0", + "commands": [ + "nupkg-validator" + ] + } + } +} \ No newline at end of file diff --git a/elastic-ingest-dotnet.sln b/elastic-ingest-dotnet.sln new file mode 100644 index 0000000..a55ff74 --- /dev/null +++ b/elastic-ingest-dotnet.sln @@ -0,0 +1,8 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/global.json b/global.json new file mode 100644 index 0000000..c317b00 --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "6.0.302", + "rollForward": "latestFeature", + "allowPrerelease": false + } +} \ No newline at end of file diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..25459fb --- /dev/null +++ b/license.txt @@ -0,0 +1,175 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use thes + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. \ No newline at end of file diff --git a/nuget-icon.png b/nuget-icon.png new file mode 100644 index 0000000..7fb2009 Binary files /dev/null and b/nuget-icon.png differ diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..3f0e003 --- /dev/null +++ b/nuget.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file