Skip to content

Commit

Permalink
Builds: Various fixes (#47)
Browse files Browse the repository at this point in the history
 - Use centralized package versioning
 - Update packages to latest
 - Fix build warnings / errors from package updates
 - Move to net6 SDK in global.json and GitHub Actions
 - Move benchmarks/samples/test projects to net6.0
 - Kill appveyor Builds
 - Determinstic Builds
 - Add support for builds on `main` branch

Co-authored-by: Nick Craver <[email protected]>
  • Loading branch information
deanward81 and NickCraver authored Jan 5, 2022
1 parent 199994e commit abd634a
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 75 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build & Test
on:
pull_request:
branches:
- master
- main
paths-ignore:
- 'docs/**' # Don't run workflow when files are only in the /docs directory

Expand All @@ -16,9 +16,8 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.201'
- name: Install .NET SDK
uses: actions/setup-dotnet@v1
- name: .NET Build
run: dotnet build Build.csproj -c Release --nologo /p:CI=true
- name: .NET Test
Expand All @@ -31,6 +30,8 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install .NET SDK
uses: actions/setup-dotnet@v1
- name: .NET Build
run: dotnet build Build.csproj -c Release --nologo /p:CI=true
- name: .NET Test
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build, Test & Package
on:
push:
branches:
- master
- main
paths-ignore:
- 'docs/**' # Don't run workflow when files are only in the /docs directory

Expand All @@ -16,9 +16,8 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.201'
- name: Install .NET SDK
uses: actions/setup-dotnet@v1
- name: .NET Build
run: dotnet build Build.csproj -c Release --nologo /p:CI=true
- name: .NET Test
Expand Down
17 changes: 12 additions & 5 deletions Directory.build.props → Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project>
<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
<Copyright>2019 Stack Exchange, Inc.</Copyright>
<Copyright>2021 Stack Exchange, Inc.</Copyright>
<LibTargetFrameworks>netstandard2.0</LibTargetFrameworks>
<PackageId>$(AssemblyName)</PackageId>
<Features>strict</Features>
<Authors>Stack Exchange, Inc., Bret Copeland</Authors>
<Authors>Stack Exchange, Inc., Bret Copeland, Dean Ward</Authors>
<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)Shared.ruleset</CodeAnalysisRuleset>
<MSBuildWarningsAsMessages>NETSDK1069</MSBuildWarningsAsMessages>
<NoWarn>NU5105</NoWarn>
Expand All @@ -16,15 +16,22 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<DefaultLanguage>en-US</DefaultLanguage>
<IncludeSymbols>false</IncludeSymbols>
<IncludeSymbols>true</IncludeSymbols>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Switches on global package management using Directory.Packages.props -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Include="DynamicDependentFile" />
<ProjectCapability Include="DynamicFileNesting" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.71" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All"/>
</ItemGroup>
</Project>
30 changes: 30 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project>
<!--
Note: this is *setting* the versions only, not including any actual packages.
There's a <PackageVersion Include="..." /> in the place it's actually needed only
(e.g. the .csproj or a Directory.Build.props), then this central spot updates all of
those includes to the same version just before the package restore step runs.
That means this central file defines all versions used, and serves to sync them all up.
-->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.1" />
<PackageVersion Include="coverlet.collector" Version="3.1.0" />
<PackageVersion Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.61701" />
<PackageVersion Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.55" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.4.244" />
<PackageVersion Include="Pipelines.Sockets.Unofficial" Version="2.2.2" />
<PackageVersion Include="System.Buffers" Version="4.5.1" />
<PackageVersion Include="System.Collections.Immutable" Version="6.0.0" />
<PackageVersion Include="System.Text.Json" Version="6.0.1" />
<PackageVersion Include="xunit" Version="2.4.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion StackExchange.Metrics.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.gitattributes = .gitattributes
.gitignore = .gitignore
appveyor.yml = appveyor.yml
build.cmd = build.cmd
build.ps1 = build.ps1
Directory.build.props = Directory.build.props
Expand Down
29 changes: 0 additions & 29 deletions appveyor.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\StackExchange.Metrics\StackExchange.Metrics.csproj" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" IncludeAssets="runtime;build;native;contentfiles;analyzers" />
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="all" IncludeAssets="runtime;build;native;contentfiles;analyzers" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.100",
"version": "6.0.101",
"rollForward": "latestMajor",
"allowPrerelease": false
}
Expand Down
15 changes: 5 additions & 10 deletions samples/StackExchange.Metrics.SampleHost/MyCustomHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ namespace StackExchange.Metrics.SampleHost
{
/// <summary>
/// A simple handler that serializes metrics as plain text in the format:
/// &lt;metric_name&gt;,&ltmetric_value&gt;\n
/// &lt;metric_name&gt;,&lt;metric_value&gt;\n
/// </summary>
public class MyCustomHandler : BufferedHttpMetricHandler
{
private static readonly MediaTypeHeaderValue _plainText = new MediaTypeHeaderValue("text/plain");

private Uri _uri;

/// <summary>
/// Constructs a new handler pointing at the specified <see cref="System.Uri" />.
/// </summary>
Expand All @@ -35,10 +33,7 @@ public MyCustomHandler(Uri uri)
/// <summary>
/// Gets or sets the URI used by the handler.
/// </summary>
public Uri Uri
{
get; set;
}
public Uri Uri { get; }

// no pre or post-amble for this handler
protected override int GetPostambleLength(PayloadType payloadType) => 0;
Expand All @@ -57,9 +52,9 @@ protected override HttpClient CreateHttpClient()
return httpClient;
}

protected override ValueTask SendCounterAsync(ReadOnlySequence<byte> sequence) => SendAsync(_uri, HttpMethod.Post, PayloadType.Counter, _plainText, sequence);
protected override ValueTask SendCumulativeCounterAsync(ReadOnlySequence<byte> sequence) => SendAsync(_uri, HttpMethod.Post, PayloadType.CumulativeCounter, _plainText, sequence);
protected override ValueTask SendGaugeAsync(ReadOnlySequence<byte> sequence) => SendAsync(_uri, HttpMethod.Post, PayloadType.Gauge, _plainText, sequence);
protected override ValueTask SendCounterAsync(ReadOnlySequence<byte> sequence) => SendAsync(Uri, HttpMethod.Post, PayloadType.Counter, _plainText, sequence);
protected override ValueTask SendCumulativeCounterAsync(ReadOnlySequence<byte> sequence) => SendAsync(Uri, HttpMethod.Post, PayloadType.CumulativeCounter, _plainText, sequence);
protected override ValueTask SendGaugeAsync(ReadOnlySequence<byte> sequence) => SendAsync(Uri, HttpMethod.Post, PayloadType.Gauge, _plainText, sequence);
// this implementation doesn't support metadata
protected override ValueTask SendMetadataAsync(ReadOnlySequence<byte> sequence) => default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Metrics/Handlers/BosunMetricHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public BosunMetricHandler(Uri baseUri)
_counterValues = new Dictionary<MetricKey, double>(MetricKeyComparer.Default);
_jsonOptions = new JsonSerializerOptions
{
IgnoreNullValues = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters =
{
new JsonEpochConverter(),
Expand Down
30 changes: 30 additions & 0 deletions src/StackExchange.Metrics/Infrastructure/MemoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,40 @@

namespace StackExchange.Metrics.Infrastructure
{
/// <summary>
/// Extension methods for <see cref="Memory{T}" />, <see cref="ReadOnlyMemory{T}"/> and <see cref="ReadOnlySequence{T}"/>.
/// </summary>
public static class MemoryExtensions
{
#pragma warning disable RCS1231 // Make parameter ref read-only.
/// <summary>
/// Tries to return the underlying <see cref="ArraySegment{T}"/> representing a single segment
/// <see cref="Memory{T}"/>.
/// </summary>
/// <param name="buffer">
/// A <see cref="Memory{T}"/> instance.
/// </param>
/// <exception cref="InvalidOperationException">
/// Could not obtain the underlying <see cref="ArraySegment{T}"/> from the <see cref="Memory{T}"/>
/// </exception>
/// <returns>
/// An <see cref="ArraySegment{T}"/>.
/// </returns>
public static ArraySegment<byte> GetArray(this Memory<byte> buffer) => GetArray((ReadOnlyMemory<byte>)buffer);

/// <summary>
/// Tries to return the underlying <see cref="ArraySegment{T}"/> representing a single segment
/// <see cref="ReadOnlyMemory{T}"/>.
/// </summary>
/// <param name="buffer">
/// A <see cref="ReadOnlyMemory{T}"/> instance.
/// </param>
/// <exception cref="InvalidOperationException">
/// Could not obtain the underlying <see cref="ArraySegment{T}"/> from the <see cref="ReadOnlyMemory{T}"/>
/// </exception>
/// <returns>
/// An <see cref="ArraySegment{T}"/>.
/// </returns>
public static ArraySegment<byte> GetArray(this ReadOnlyMemory<byte> buffer)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{
Expand Down
19 changes: 10 additions & 9 deletions src/StackExchange.Metrics/StackExchange.Metrics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.61701" Condition="'$(TargetFramework)'=='netcoreapp3.1'" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.55" Condition="'$(TargetFramework)'=='netcoreapp3.1'" />
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="2.1.11" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.1" />
<PackageReference Include="Microsoft.Diagnostics.NETCore.Client" Condition="'$(TargetFramework)'=='netcoreapp3.1'" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Condition="'$(TargetFramework)'=='netcoreapp3.1'" />
<PackageReference Include="Pipelines.Sockets.Unofficial" />
<PackageReference Include="System.Buffers" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\StackExchange.Metrics\StackExchange.Metrics.csproj" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.0",
"assemblyVersion": "2.0",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$",
"^refs/tags/v\\d+\\.\\d+"
],
"nugetPackageVersion": {
Expand Down

0 comments on commit abd634a

Please sign in to comment.