Skip to content

Commit

Permalink
Refactoring pipeline for NuGet release (#12)
Browse files Browse the repository at this point in the history
* Added MIT LICENSE.md

* Updated solution properties

- Updated TargetFrameworks to netstandard2.0;net6.0
- Enabled NuGet source link
- Enabled nullable

* Fix nullable warnings

* Updated GH action, added AZ pipeline

* Fix nullable warnings

* Refactoring disposable and app+version args
  • Loading branch information
albertospelta committed Apr 24, 2022
1 parent 745cd13 commit d436287
Show file tree
Hide file tree
Showing 32 changed files with 419 additions and 265 deletions.
80 changes: 80 additions & 0 deletions .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
parameters:
- name: verbosity
displayName: Verbosity
type: string
default: minimal
values:
- minimal
- normal
- detailed
- diagnostic

trigger: none

pool:
vmImage: 'windows-latest'

variables:
configuration: 'Release'
assemblyVersion: '$(AppVersionMajor).0.0.0'
semanticVersion: '$(AppVersionMajor).$(AppVersionMinor).$(AppVersionPatch)'

steps:
- task: PowerShell@2
displayName: 'Set variables'
inputs:
targetType: 'inline'
script: |
$versionSuffix = "$(AppVersionSuffix)"
if ($versionSuffix -match "\S") { $versionSuffix = "-$versionSuffix" }
Write-Host "##vso[task.setvariable variable=versionSuffix;]$versionSuffix"
Write-Host "VersionSuffix $versionSuffix"
$packageVersion = "$(semanticVersion)$versionSuffix"
if ("$(isReleaseBuild)" -ne "true") { $packageVersion += "-CI-$(Build.BuildNumber)" }
Write-Host "Set PackageVersion and BuildNumber to '$packageVersion'"
Write-Host "##vso[task.setvariable variable=packageVersion;]$packageVersion"
Write-Host "##vso[build.updatebuildnumber]$packageVersion"
- task: DownloadSecureFile@1
name: signKey
displayName: 'Download sign key'
inputs:
secureFile: 'DaxFormatter.snk'
- task: UseDotNet@2
displayName: '.NET setup'
inputs:
packageType: sdk
version: 6.0.x
- task: DotNetCoreCLI@2
displayName: '.NET restore'
inputs:
command: 'restore'
projects: 'src/**/*.csproj'
feedsToUse: 'select'
verbosityRestore: '${{ parameters.verbosity }}'
- task: DotNetCoreCLI@2
displayName: '.NET build'
inputs:
command: 'build'
projects: 'src/**/*.csproj'
arguments: '--configuration "$(configuration)" --no-restore --verbosity ${{ parameters.verbosity }} /p:AssemblyVersion="$(assemblyVersion)" /p:FileVersion="$(semanticVersion)" /p:VersionPrefix="$(semanticVersion)" /p:VersionSuffix="$(versionSuffix)" /p:ContinuousIntegrationBuild="true" /p:AdditionalConstants="SIGNED" /p:SignAssembly="true" /p:AssemblyOriginatorKeyFile="$(signKey.secureFilePath)" /m'
- task: DotNetCoreCLI@2
displayName: '.NET test'
inputs:
command: 'test'
projects: 'src/*Tests/*.csproj'
arguments: '--no-restore --no-build --verbosity ${{ parameters.verbosity }} --logger "trx;LogFilePrefix=testResults" --collect "Code coverage"'
- task: DotNetCoreCLI@2
displayName: '.NET pack'
inputs:
command: 'pack'
packagesToPack: 'src/Dax.Formatter/Dax.Formatter.csproj'
nobuild: true
versioningScheme: 'byEnvVar'
versionEnvVar: 'packageVersion'
verbosityPack: '${{ parameters.verbosity }}'
- task: PublishPipelineArtifact@1
displayName: 'Publish artifacts'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'drop'
publishLocation: 'pipeline'
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
env:
CONFIGURATION: 'Release'
jobs:
build-and-test:
name: build-and-test--${{ matrix.os-version }}
runs-on: ${{ matrix.os-version }}
strategy:
matrix:
os-version: [windows-latest] #, ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- name: .NET setup
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: .NET info
run: dotnet --info
- name: .NET restore
run: dotnet restore ./src
- name: .NET build
run: dotnet build ./src/Dax.Formatter.sln --configuration ${{ env.CONFIGURATION }} --no-restore
- name: .NET test
run: dotnet test ./src/Dax.Formatter.Tests/Dax.Formatter.Tests.csproj --configuration ${{ env.CONFIGURATION }} --no-build --verbosity normal
- name: .NET pack
run: dotnet pack ./src/Dax.Formatter/Dax.Formatter.csproj --configuration ${{ env.CONFIGURATION }} --no-build --no-restore --verbosity normal
29 changes: 0 additions & 29 deletions .github/workflows/dotnet.yml

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) SQLBI Corporation

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.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Dax Formatter [![NuGet](https://github.com/sql-bi/DaxFormatter/actions/workflows/dotnet.yml/badge.svg)](https://github.com/sql-bi/DaxFormatter/actions/workflows/dotnet.yml)
# Dax Formatter [![CI](https://github.com/sql-bi/DaxFormatter/actions/workflows/ci.yml/badge.svg)](https://github.com/sql-bi/DaxFormatter/actions/workflows/ci.yml)

DAX Formatter is a service available at https://www.daxformatter.com.
The service receives DAX expressions and format them according to rules for [DAX code formatting](https://www.sqlbi.com/articles/rules-for-dax-code-formatting/).
Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "6.0.100",
"allowPrerelease": false,
"rollForward": "latestFeature"
}
}
7 changes: 7 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
File renamed without changes
19 changes: 13 additions & 6 deletions src/Dax.Formatter.Tests/Dax.Formatter.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<TargetFrameworks>net461;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0-preview-20220401-08" />
<PackageReference Include="xunit" Version="2.4.2-pre.12" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
59 changes: 23 additions & 36 deletions src/Dax.Formatter.Tests/DaxFormatterClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DaxFormatterClientFixture
{
public DaxFormatterClient Client { get; private set; }

public DaxFormatterClientFixture() => Client = new DaxFormatterClient();
public DaxFormatterClientFixture() => Client = new DaxFormatterClient(application: "Dax.Formatter.Tests", version: "develop");
}

public class DaxFormatterClientTests : IClassFixture<DaxFormatterClientFixture>
Expand All @@ -27,11 +27,8 @@ public DaxFormatterClientTests(DaxFormatterClientFixture formatter)
[InlineData(DaxFormatterSpacingStyle.NoSpaceAfterFunction, "[X]=IF(1=1,TRUE(),FALSE())", "[X] =\r\nIF( 1 = 1, TRUE(), FALSE() )\r\n")]
public async Task DaxFormatterClient_FormatAsync_SpacingStyleIsHonored(DaxFormatterSpacingStyle spacingStyle, string expression, string expectedExpression)
{
var request = new DaxFormatterSingleRequest
{
Dax = expression,
SkipSpaceAfterFunctionName = spacingStyle
};
var request = DaxFormatterSingleRequest.CreateFrom(expression);
request.SkipSpaceAfterFunctionName = spacingStyle;

var response = await _fixture.Client.FormatAsync(request);
Assert.NotNull(response);
Expand All @@ -45,11 +42,8 @@ public async Task DaxFormatterClient_FormatAsync_SpacingStyleIsHonored(DaxFormat
[InlineData(DaxFormatterLineStyle.ShortLine, "[X]:=IF(1=1,1,0)", "[X] :=\r\nIF (\r\n 1 = 1,\r\n 1,\r\n 0\r\n)\r\n")]
public async Task DaxFormatterClient_FormatAsync_LineStyleIsHonored(DaxFormatterLineStyle lineStyle, string expression, string expectedExpression)
{
var request = new DaxFormatterSingleRequest
{
Dax = expression,
MaxLineLength = lineStyle
};
var request = DaxFormatterSingleRequest.CreateFrom(expression);
request.MaxLineLength = lineStyle;

var response = await _fixture.Client.FormatAsync(request);
Assert.NotNull(response);
Expand Down Expand Up @@ -85,9 +79,7 @@ public async Task DaxFormatterClient_FormatAsync_SingleExpressionFails(string ex
[InlineData("[X] := CALCULATE(SUM(Sales[Sales Amount]), USERELATIONSHIP(Sales[DueDateKey],'Date'[DateKey]))", "[X] :=\r\nCALCULATE (\r\n SUM ( Sales[Sales Amount] ),\r\n USERELATIONSHIP ( Sales[DueDateKey], 'Date'[DateKey] )\r\n)\r\n")]
public async Task DaxFormatterClient_FormatAsync_SingleRequestSucceded(string expression, string expectedExpression)
{
var request = new DaxFormatterSingleRequest();
request.Dax = expression;

var request = DaxFormatterSingleRequest.CreateFrom(expression);
var response = await _fixture.Client.FormatAsync(request);

AssertSingleSucceded(response, expectedExpression);
Expand All @@ -98,9 +90,7 @@ public async Task DaxFormatterClient_FormatAsync_SingleRequestSucceded(string ex
[InlineData("EVALUATE( Table ) ORDER Table[Column]", 0, 24)]
public async Task DaxFormatterClient_FormatAsync_SingleRequestFails(string expression, int expectedErrorLine, int expectedErrorColumn)
{
var request = new DaxFormatterSingleRequest();
request.Dax = expression;

var request = DaxFormatterSingleRequest.CreateFrom(expression);
var response = await _fixture.Client.FormatAsync(request);

AssertSingleFails(response, expectedErrorLine, expectedErrorColumn);
Expand All @@ -113,9 +103,7 @@ public async Task DaxFormatterClient_FormatAsync_SingleRequestFails(string expre
public async Task DaxFormatterClient_FormatAsync_MultipleRequestSucceded(string expression, string expectedExpression, int repeat)
{
var expressions = Enumerable.Repeat(expression, repeat);
var request = new DaxFormatterMultipleRequest();
request.Dax.AddRange(expressions);

var request = DaxFormatterMultipleRequest.CreateFrom(expressions);
var response = await _fixture.Client.FormatAsync(request);

AssertMultipleSucceded(response, expectedExpression, repeat);
Expand All @@ -127,9 +115,7 @@ public async Task DaxFormatterClient_FormatAsync_MultipleRequestSucceded(string
public async Task DaxFormatterClient_FormatAsync_MultipleRequestFails(string expression, int repeat, int expectedErrorLine, int expectedErrorColumn)
{
var expressions = Enumerable.Repeat(expression, repeat);
var request = new DaxFormatterMultipleRequest();
request.Dax.AddRange(expressions);

var request = DaxFormatterMultipleRequest.CreateFrom(expressions);
var response = await _fixture.Client.FormatAsync(request);

AssertMultipleFails(response, repeat, expectedErrorLine, expectedErrorColumn);
Expand All @@ -149,30 +135,30 @@ public async Task DaxFormatterClient_FormatAsync_ParallelSingleExpressionSuccede
[InlineData("evaluate('Table')", "EVALUATE\r\n( 'Table' )\r\n", 10)]
public async Task DaxFormatterClient_FormatAsync_ParallelSingleRequestSucceded(string expression, string expectedExpression, int repeat)
{
var request = new DaxFormatterSingleRequest();
request.Dax = expression;

var request = DaxFormatterSingleRequest.CreateFrom(expression);
var tasks = Enumerable.Repeat(request, repeat).AsParallel().Select((r) => _fixture.Client.FormatAsync(r));
var responses = await Task.WhenAll(tasks);

AssertParallelSingleSucceded(responses, expectedExpression, repeat);
}

private static void AssertSingleSucceded(DaxFormatterResponse response, string expectedExpression)
private static void AssertSingleSucceded(DaxFormatterResponse? response, string expectedExpression)
{
Assert.NotNull(response);

Assert.NotNull(response.Formatted);
Assert.NotNull(response.Errors);
Assert.NotEmpty(response.Formatted);
Assert.Empty(response.Errors);

var actualExpression = response.Formatted;
Assert.Equal(expectedExpression, actualExpression);
}

private static void AssertSingleFails(DaxFormatterResponse response, int expectedErrorLine, int expectedErrorColumn)
private static void AssertSingleFails(DaxFormatterResponse? response, int expectedErrorLine, int expectedErrorColumn)
{
Assert.NotNull(response);

Assert.NotNull(response.Formatted);
Assert.NotNull(response.Errors);
Assert.Empty(response.Formatted);
Assert.Single(response.Errors);

Expand All @@ -183,10 +169,11 @@ private static void AssertSingleFails(DaxFormatterResponse response, int expecte

private static void AssertMultipleSucceded(IReadOnlyList<DaxFormatterResponse> responses, string expectedExpression, int repeat)
{
Assert.NotNull(responses);
Assert.NotNull(responses);
Assert.Equal(repeat, responses.Count);
Assert.DoesNotContain(responses, (r) => r.Errors is null);

var errors = responses.SelectMany((r) => r.Errors);
var errors = responses.SelectMany((r) => r.Errors!);
Assert.Empty(errors);

var formattedExpressions = responses.Select((r) => r.Formatted).Distinct();
Expand All @@ -200,8 +187,9 @@ private static void AssertMultipleFails(IReadOnlyList<DaxFormatterResponse> resp
{
Assert.NotNull(responses);
Assert.Equal(repeat, responses.Count);
Assert.DoesNotContain(responses, (r) => r.Errors is null);

var errors = responses.SelectMany((r) => r.Errors).ToList();
var errors = responses.SelectMany((r) => r.Errors!).ToList();
Assert.Equal(repeat, errors.Count);

var errorLines = errors.Select((e) => e.Line).Distinct();
Expand All @@ -223,11 +211,10 @@ private static void AssertMultipleFails(IReadOnlyList<DaxFormatterResponse> resp
Assert.Equal(string.Empty, actualExpression);
}

private static void AssertParallelSingleSucceded(DaxFormatterResponse[] responses, string expectedExpression, int repeat)
private static void AssertParallelSingleSucceded(DaxFormatterResponse?[] responses, string expectedExpression, int repeat)
{
Assert.NotNull(responses);
Assert.Equal(repeat, responses.Length);
Assert.Empty(responses.SelectMany((r) => r.Errors));
Assert.Single(responses.Select((r) => r.Formatted).Distinct());

foreach (var response in responses)
AssertSingleSucceded(response, expectedExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public void DaxFormatterSingleRequest_MaxLineLengthSerialization(DaxFormatterLin
Assert.Equal(expectedLineStyle, currentLineStyle);
}


[Theory]
[InlineData(DaxFormatterSpacingStyle.NoSpaceAfterFunction, true)]
[InlineData(DaxFormatterSpacingStyle.SpaceAfterFunction, false)]
Expand Down
Loading

0 comments on commit d436287

Please sign in to comment.