Skip to content

Commit

Permalink
Adding schema validation (dotnet#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros committed Jul 14, 2020
1 parent b2d7cb2 commit a419a83
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 178 deletions.
103 changes: 52 additions & 51 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trigger:
- release/*

pr:
autoCancel: false
autoCancel: true
branches:
include:
- '*'
Expand All @@ -44,57 +44,58 @@ stages:
enableTelemetry: true
mergeTestResults: true
jobs:
- job: Windows
pool:
${{ if eq(variables['System.TeamProject'], 'public') }}:
name: NetCorePublic-Pool
queue: BuildPool.Server.Amd64.VS2019.Open
${{ if ne(variables['System.TeamProject'], 'public') }}:
name: NetCoreInternal-Pool
queue: BuildPool.Server.Amd64.VS2019
variables:

- ${{ if and(eq(variables['System.TeamProject'], 'internal'), notin(variables['Build.Reason'], 'PullRequest')) }}:
- job: Windows
pool:
${{ if eq(variables['System.TeamProject'], 'public') }}:
name: NetCorePublic-Pool
queue: BuildPool.Server.Amd64.VS2019.Open
${{ if ne(variables['System.TeamProject'], 'public') }}:
name: NetCoreInternal-Pool
queue: BuildPool.Server.Amd64.VS2019
variables:


# Only enable publishing in official builds.
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
# Publish-Build-Assets provides: MaestroAccessToken, BotAccount-dotnet-maestro-bot-PAT
- group: Publish-Build-Assets
- name: _OfficialBuildArgs
value: /p:DotNetSignType=$(_SignType)
/p:TeamName=$(_TeamName)
/p:DotNetPublishUsingPipelines=$(_PublishUsingPipelines)
/p:OfficialBuildId=$(BUILD.BUILDNUMBER)
- name: _SignType
value: real
# else
- ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
- name: _OfficialBuildArgs
value: ''
- name: _SignType
value: test

steps:
- checkout: self
clean: true
- script: eng\common\cibuild.cmd -configuration $(_BuildConfig) -prepareMachine $(_OfficialBuildArgs)
displayName: Build and Publish
- task: PublishBuildArtifacts@1
displayName: Upload TestResults
condition: always()
continueOnError: true
inputs:
pathtoPublish: artifacts/TestResults/$(_BuildConfig)/
artifactName: $(Agent.Os)_$(Agent.JobName) TestResults
artifactType: Container
parallel: true
- task: PublishBuildArtifacts@1
displayName: Upload package artifacts
condition: and(succeeded(), eq(variables['system.pullrequest.isfork'], false), eq(variables['_BuildConfig'], 'Release'))
inputs:
pathtoPublish: artifacts/packages/
artifactName: artifacts
artifactType: Container
parallel: true
# Only enable publishing in official builds.
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
# Publish-Build-Assets provides: MaestroAccessToken, BotAccount-dotnet-maestro-bot-PAT
- group: Publish-Build-Assets
- name: _OfficialBuildArgs
value: /p:DotNetSignType=$(_SignType)
/p:TeamName=$(_TeamName)
/p:DotNetPublishUsingPipelines=$(_PublishUsingPipelines)
/p:OfficialBuildId=$(BUILD.BUILDNUMBER)
- name: _SignType
value: real
# else
- ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
- name: _OfficialBuildArgs
value: ''
- name: _SignType
value: test
steps:
- checkout: self
clean: true
- script: eng\common\cibuild.cmd -configuration $(_BuildConfig) -prepareMachine $(_OfficialBuildArgs)
displayName: Build and Publish
- task: PublishBuildArtifacts@1
displayName: Upload TestResults
condition: always()
continueOnError: true
inputs:
pathtoPublish: artifacts/TestResults/$(_BuildConfig)/
artifactName: $(Agent.Os)_$(Agent.JobName) TestResults
artifactType: Container
parallel: true
- task: PublishBuildArtifacts@1
displayName: Upload package artifacts
condition: and(succeeded(), eq(variables['system.pullrequest.isfork'], false), eq(variables['_BuildConfig'], 'Release'))
inputs:
pathtoPublish: artifacts/packages/
artifactName: artifacts
artifactType: Container
parallel: true

- job: Ubuntu_16_04
displayName: 'Ubuntu 16.04'
Expand Down
103 changes: 48 additions & 55 deletions src/Microsoft.Crank.Controller/JobConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public JobConnection(Job definition, Uri serverUri)
public Job Job { get; private set; }

public async Task<string> StartAsync(
string jobName,
CommandOption _outputArchiveOption,
CommandOption _buildArchiveOption
string jobName
)
{
_jobName = jobName;
Expand Down Expand Up @@ -152,80 +150,75 @@ CommandOption _buildArchiveOption
}

// Upload custom package contents
if (_outputArchiveOption.HasValue())
foreach (var outputArchiveValue in Job.Options.OutputArchives)
{
foreach (var outputArchiveValue in _outputArchiveOption.Values)
{
var outputFileSegments = outputArchiveValue.Split(';', 2, StringSplitOptions.RemoveEmptyEntries);
var outputFileSegments = outputArchiveValue.Split(';', 2, StringSplitOptions.RemoveEmptyEntries);

string localArchiveFilename = outputFileSegments[0];
string localArchiveFilename = outputFileSegments[0];

var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

if (Directory.Exists(tempFolder))
{
Directory.Delete(tempFolder, true);
}
if (Directory.Exists(tempFolder))
{
Directory.Delete(tempFolder, true);
}

Directory.CreateDirectory(tempFolder);
Directory.CreateDirectory(tempFolder);

_temporaryFolders.Add(tempFolder);
_temporaryFolders.Add(tempFolder);

// Download the archive, while pinging the server to keep the job alive
if (outputArchiveValue.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
localArchiveFilename = await DownloadTemporaryFileAsync(localArchiveFilename, _serverJobUri);
}
// Download the archive, while pinging the server to keep the job alive
if (outputArchiveValue.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
localArchiveFilename = await DownloadTemporaryFileAsync(localArchiveFilename, _serverJobUri);
}

ZipFile.ExtractToDirectory(localArchiveFilename, tempFolder);
ZipFile.ExtractToDirectory(localArchiveFilename, tempFolder);

if (outputFileSegments.Length > 1)
{
Job.Options.OutputFiles.Add(Path.Combine(tempFolder, "*.*") + ";" + outputFileSegments[1]);
}
else
{
Job.Options.OutputFiles.Add(Path.Combine(tempFolder, "*.*"));
}
if (outputFileSegments.Length > 1)
{
Job.Options.OutputFiles.Add(Path.Combine(tempFolder, "*.*") + ";" + outputFileSegments[1]);
}
else
{
Job.Options.OutputFiles.Add(Path.Combine(tempFolder, "*.*"));
}
}


// Upload custom build package contents
if (_buildArchiveOption.HasValue())
foreach (var buildArchiveValue in Job.Options.BuildArchives)
{
foreach (var buildArchiveValue in _buildArchiveOption.Values)
{
var buildFileSegments = buildArchiveValue.Split(';', 2, StringSplitOptions.RemoveEmptyEntries);
var buildFileSegments = buildArchiveValue.Split(';', 2, StringSplitOptions.RemoveEmptyEntries);

string localArchiveFilename = buildFileSegments[0];
string localArchiveFilename = buildFileSegments[0];

var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

if (Directory.Exists(tempFolder))
{
Directory.Delete(tempFolder, true);
}
if (Directory.Exists(tempFolder))
{
Directory.Delete(tempFolder, true);
}

Directory.CreateDirectory(tempFolder);
Directory.CreateDirectory(tempFolder);

_temporaryFolders.Add(tempFolder);
_temporaryFolders.Add(tempFolder);

// Download the archive, while pinging the server to keep the job alive
if (buildArchiveValue.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
localArchiveFilename = await DownloadTemporaryFileAsync(localArchiveFilename, _serverJobUri);
}
// Download the archive, while pinging the server to keep the job alive
if (buildArchiveValue.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
localArchiveFilename = await DownloadTemporaryFileAsync(localArchiveFilename, _serverJobUri);
}

ZipFile.ExtractToDirectory(localArchiveFilename, tempFolder);
ZipFile.ExtractToDirectory(localArchiveFilename, tempFolder);

if (buildFileSegments.Length > 1)
{
Job.Options.BuildFiles.Add(Path.Combine(tempFolder, "*.*") + ";" + buildFileSegments[1]);
}
else
{
Job.Options.BuildFiles.Add(Path.Combine(tempFolder, "*.*"));
}
if (buildFileSegments.Length > 1)
{
Job.Options.BuildFiles.Add(Path.Combine(tempFolder, "*.*") + ";" + buildFileSegments[1]);
}
else
{
Job.Options.BuildFiles.Add(Path.Combine(tempFolder, "*.*"));
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/Microsoft.Crank.Controller/JsonTypeResolution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Globalization;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;

namespace Microsoft.Crank.Controller
{
/// Provides types resolution for YAML
/// Without this booleans and numbers are parsed as strings
public class JsonTypeResolver : INodeTypeResolver
{
public bool Resolve(NodeEvent nodeEvent, ref Type currentType)
{
if (nodeEvent is Scalar scalar && scalar.IsPlainImplicit)
{
if (decimal.TryParse(scalar.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
{
currentType = typeof(decimal);
return true;
}
else if (bool.TryParse(scalar.Value, out var b))
{
currentType = typeof(bool);
return true;
}
}

return false;
}
}
}
11 changes: 9 additions & 2 deletions src/Microsoft.Crank.Controller/Microsoft.Crank.Controller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
<PackageReference Include="CsvHelper" Version="12.1.2" />
<PackageReference Include="Fluid.Core" Version="1.0.0-beta-9608" />
<PackageReference Include="YamlDotNet" Version="8.0.0" />
<PackageReference Include="Fluid.Core" Version="1.0.0-beta-9660" />
<PackageReference Include="YamlDotNet" Version="8.1.2" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.13" />
<PackageReference Include="NuGet.Versioning" Version="5.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Crank.Models\Microsoft.Crank.Models.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="benchmarks.schema.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Remove="benchmarks.schema.json" />
</ItemGroup>


</Project>
Loading

0 comments on commit a419a83

Please sign in to comment.