Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Actions to project #22

Merged
merged 13 commits into from
Jan 9, 2024
Merged
7 changes: 7 additions & 0 deletions .github/.github.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>False</IsPackable>
</PropertyGroup>

</Project>
14 changes: 14 additions & 0 deletions .github/add-license-headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
script_path=$(dirname $(realpath $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"
45 changes: 45 additions & 0 deletions .github/check-license-headers.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .github/license-header.txt
Original file line number Diff line number Diff line change
@@ -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
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Always be deploying

on:
pull_request:
paths-ignore:
- 'README.md'
- '.editorconfig'
push:
paths-ignore:
- 'README.md'
- '.editorconfig'
branches:
- main
tags:
- "*.*.*"

jobs:
test-windows:
runs-on: windows-latest
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: |
8.0.x
6.0.x
source-url: https://nuget.pkg.github.com/elastic/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- run: build.bat test
shell: cmd
name: Test

build:
runs-on: ubuntu-latest
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: |
6.0.x
8.0.x
source-url: https://nuget.pkg.github.com/elastic/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- run: ./build.sh release
name: Release

- 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: false && github.event_name == 'push' && startswith(github.ref, 'refs/heads')

- 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: false && github.event_name == 'push' && startswith(github.ref, 'refs/tags')
15 changes: 15 additions & 0 deletions .github/workflows/license.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Elastic.OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{AAD39891
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.OpenTelemetry.Tests", "tests\Elastic.OpenTelemetry.Tests\Elastic.OpenTelemetry.Tests.csproj", "{22BF9223-3A6D-4197-8527-3E4E43A98A81}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = ".github", ".github\.github.csproj", "{B701E33D-D777-4BD4-A4EC-1F63FE69AF7A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -52,6 +54,10 @@ Global
{22BF9223-3A6D-4197-8527-3E4E43A98A81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22BF9223-3A6D-4197-8527-3E4E43A98A81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22BF9223-3A6D-4197-8527-3E4E43A98A81}.Release|Any CPU.Build.0 = Release|Any CPU
{B701E33D-D777-4BD4-A4EC-1F63FE69AF7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B701E33D-D777-4BD4-A4EC-1F63FE69AF7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B701E33D-D777-4BD4-A4EC-1F63FE69AF7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B701E33D-D777-4BD4-A4EC-1F63FE69AF7A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
dotnet run --project build/scripts -- %*
@echo off
dotnet run --project build -c debug -- %*

2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail
dotnet run --project build -- "$@"
dotnet run --project build -c release -- "$@"
2 changes: 1 addition & 1 deletion build/build.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<NoWarn>$(NoWarn);NU1701</NoWarn>
<IsPackable>false</IsPackable>
Expand Down
16 changes: 12 additions & 4 deletions build/scripts/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ open Proc.Fs
open BuildInformation

let private clean _ =
exec { run "dotnet" "clean" }
Shell.cleanDir Paths.ArtifactFolder.FullName
exec { run "dotnet" "clean" "-c" "release" }
let removeArtifacts folder = Shell.cleanDir (Paths.ArtifactPath folder).FullName
removeArtifacts "package"
removeArtifacts "release-notes"
removeArtifacts "tests"

let private build _ = exec { run "dotnet" "build" "-c" "Release" }
let private build _ = exec { run "dotnet" "build" "-c" "release" }

let private release _ = printfn "release"

Expand All @@ -42,9 +45,14 @@ let private test _ =
let junitOutput = Path.Combine(testOutputPath.FullName, "junit-{assembly}-{framework}-test-results.xml")
let loggerPathArgs = $"LogFilePath=%s{junitOutput}"
let loggerArg = $"--logger:\"junit;%s{loggerPathArgs}\""
let githubActionsLogger = $"--logger:\"GitHubActions;summary.includePassedTests=true\""
let tfmArgs = if OS.Current = OS.Windows then [] else ["-f"; "net8.0"]
exec {
run "dotnet" (["test"; "-c"; "Release"; loggerArg] @ tfmArgs)
run "dotnet" (
["test"; "-c"; "release"; loggerArg; githubActionsLogger]
@ tfmArgs
@ ["--"; "RunConfiguration.CollectSourceInformation=true"]
)
}

let private validatePackages _ =
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>False</IsPackable>
</PropertyGroup>

Expand Down
3 changes: 3 additions & 0 deletions examples/Example.Elastic.OpenTelemetry/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using Example.Elastic.OpenTelemetry;

Console.WriteLine("Starting sample application.");
Expand Down
3 changes: 3 additions & 0 deletions examples/Example.Elastic.OpenTelemetry/Usage.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using System.Diagnostics;
using Elastic.OpenTelemetry;
using Elastic.OpenTelemetry.Extensions;
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/Agent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using OpenTelemetry;
using System.Reflection;

Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/AgentBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using Elastic.OpenTelemetry.Extensions;
using Elastic.OpenTelemetry.Resources;
using OpenTelemetry;
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/Exporters/BatchExporter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using OpenTelemetry;

using System.Diagnostics;
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/Extensions/ActivityExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using System.Diagnostics;

using Elastic.OpenTelemetry.Processors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using OpenTelemetry.Metrics;

namespace Elastic.OpenTelemetry.Extensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using Elastic.OpenTelemetry.SemanticConventions;

using OpenTelemetry.Resources;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using Elastic.OpenTelemetry.Processors;
using OpenTelemetry.Exporter;
using OpenTelemetry.Trace;
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/IAgent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
namespace Elastic.OpenTelemetry;

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/Processors/Composite.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
namespace Elastic.OpenTelemetry.Processors;

// TODO - Consider a struct, but consider if this would get copied too much
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using Elastic.OpenTelemetry.Extensions;

using OpenTelemetry;
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/Processors/SpanCounterProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using OpenTelemetry;

using System.Diagnostics;
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/Processors/StackTraceProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using OpenTelemetry;
using System.Diagnostics;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using OpenTelemetry;
using System.Diagnostics;

Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.OpenTelemetry/Resources/DefaultServiceDetector.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using System.Diagnostics;
using Elastic.OpenTelemetry.SemanticConventions;
using OpenTelemetry.Resources;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
using Elastic.OpenTelemetry.SemanticConventions;
using OpenTelemetry.Resources;
namespace Elastic.OpenTelemetry.Resources;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
namespace Elastic.OpenTelemetry.SemanticConventions;

internal static class ResourceSemanticConventions
Expand Down
1 change: 1 addition & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(ProjectName), '^(.*)Tests$'))">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />

<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" PrivateAssets="All" />
<PackageReference Include="JunitXml.TestLogger" Version="3.0.114" PrivateAssets="All" />
<PackageReference Include="Nullean.VsTest.Pretty.TestLogger" Version="0.3.0" PrivateAssets="All" />

Expand Down
3 changes: 3 additions & 0 deletions tests/Elastic.OpenTelemetry.Tests/BasicAgentTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
namespace Elastic.OpenTelemetry.Tests;

public class TransactionIdProcessorTests
Expand Down
3 changes: 3 additions & 0 deletions tests/Elastic.OpenTelemetry.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 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
global using Xunit;
global using System.Diagnostics;
global using Elastic.OpenTelemetry.Processors;
Expand Down
Loading