Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/1.9.0'
Browse files Browse the repository at this point in the history
* release/1.9.0:
  (build) Fixed unit test relying on env variables
  (maint) Updated dependencies to latest version
  (build) Update build dependencies
  (docs) Corrected CI providers table
  (GH-93) Update documentation for azure pipelines
  (build) Increase logging verbosity during GH action build
  Use the correct 'branch' property
  Use the correct 'job' and 'build' properties
  Add empty Directory.Build.props and Directory.Build.targets
  Set all properties for Azure Pipelines uploads
  • Loading branch information
AdmiringWorm committed Nov 14, 2019
2 parents 43b34f1 + 57c2e2f commit 599d2ed
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build

on: [push]
on: [push, pull_request]

jobs:
build:
Expand All @@ -17,5 +17,5 @@ jobs:
with:
dotnet-version: 2.2.108
- name: Build with cake
run: ./build.ps1
run: ./build.ps1 -Verbosity Diagnostic
shell: powershell
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
2 changes: 2 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ The following CI providers are supported:
| Company | Supported | Token Required |
| --------------- | ------------------------- | ---------------- |
| AppVeyor | Yes | Private only |
| Azure Pipelines | Yes | Public & Private |
| Azure Pipelines | Yes | Private |
| Git | Yes (as a fallback) | Public & Private |
| GitHub Actions | Partial (git as fallback) | Public & Private |
| Jenkins | Yes | Public & Private |
| TeamCity | Yes | Public & Private |
| Travis CI | Yes (See below) | Private only |
| TeamCity | Yes (See below) | Public & Private |
| Travis CI | Yes | Private only |
### TeamCity
Expand Down
6 changes: 3 additions & 3 deletions Source/Codecov.Tests/Codecov.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.6.3">
<PackageReference Include="coverlet.msbuild" Version="2.7.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="FluentAssertions" Version="5.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Codecov.Services.ContinuousIntegrationServers;
using FluentAssertions;
using Xunit;
Expand All @@ -7,10 +8,34 @@ namespace Codecov.Tests.Services.ContiniousIntegrationServers
{
public class AzurePipelinesTests
{
public static IEnumerable<object[]> Build_Url_Empty_Data
{
get
{
var possibleDomains = new[]{ null, string.Empty, "https://dev.azure.com/", "http://localhost:5234/" };
var possibleDummies = new[] { null, string.Empty, "foo", "bar" };

foreach (var domain in possibleDomains)
{
foreach (var project in possibleDummies)
{
foreach (var build in possibleDummies)
{
if (string.IsNullOrEmpty(domain) || string.IsNullOrEmpty(project) || string.IsNullOrEmpty(build))
{
yield return new object[] { domain, project, build };
}
}
}
}
}
}

[Fact]
public void Branch_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exits()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_PULLREQUEST_TARGETBRANCH", null);
Environment.SetEnvironmentVariable("BUILD_SOURCEBRANCHNAME", null);
var pipelines = new AzurePipelines();

Expand All @@ -22,9 +47,25 @@ public void Branch_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exi
}

[Fact]
public void Branch_Should_Be_Set_When_Enviornment_Variable_Exits()
public void Branch_Should_Be_Set_When_PR_Enviornment_Variable_Exits()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_PULLREQUEST_TARGETBRANCH", "develop");
Environment.SetEnvironmentVariable("BUILD_SOURCEBRANCHNAME", null);
var pipelines = new AzurePipelines();

// When
var branch = pipelines.Branch;

// Then
branch.Should().Be("develop");
}

[Fact]
public void Branch_Should_Be_Set_When_Branch_Enviornment_Variable_Exits()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_PULLREQUEST_TARGETBRANCH", null);
Environment.SetEnvironmentVariable("BUILD_SOURCEBRANCHNAME", "develop");
var pipelines = new AzurePipelines();

Expand All @@ -35,11 +76,26 @@ public void Branch_Should_Be_Set_When_Enviornment_Variable_Exits()
branch.Should().Be("develop");
}

[Fact]
public void Branch_Should_Prefer_Pull_Request()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_PULLREQUEST_TARGETBRANCH", "pr");
Environment.SetEnvironmentVariable("BUILD_SOURCEBRANCHNAME", "master");
var pipelines = new AzurePipelines();

// When
var branch = pipelines.Branch;

// Then
branch.Should().Be("pr");
}

[Fact]
public void Build_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exits()
{
// Given
Environment.SetEnvironmentVariable("BUILD_BUILDID", null);
Environment.SetEnvironmentVariable("BUILD_BUILDNUMBER", null);
var pipelines = new AzurePipelines();

// When
Expand All @@ -53,7 +109,7 @@ public void Build_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exit
public void Build_Should_Be_Set_When_Enviornment_Variable_Exits()
{
// Given
Environment.SetEnvironmentVariable("BUILD_BUILDID", "123");
Environment.SetEnvironmentVariable("BUILD_BUILDNUMBER", "123");
var pipelines = new AzurePipelines();

// When
Expand Down Expand Up @@ -105,12 +161,63 @@ public void Detecter_Should_Be_False_When_TfBuild_Enviornment_Variable_Does_Not_
detecter.Should().BeFalse();
}

[Theory, InlineData(null, null), InlineData("", ""), InlineData("foo", ""), InlineData("", "foo")]
[Theory, MemberData(nameof(Build_Url_Empty_Data))]
public void BuildUrl_Should_Be_Empty_String_When_Environment_Variables_Do_Not_Exist(string serverUrl, string project, string build)
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONSERVERURI", serverUrl);
Environment.SetEnvironmentVariable("SYSTEM_TEAMPROJECT", project);
Environment.SetEnvironmentVariable("BUILD_BUILDID", build);

var pipelines = new AzurePipelines();

// When
var buildUrl = pipelines.BuildUrl;

// Then
buildUrl.Should().BeEmpty();
}

[Fact]
public void BuildUrl_Should_Not_Empty_String_When_Environment_Variable_Exists()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONSERVERURI", "https://dev.azure.com/");
Environment.SetEnvironmentVariable("SYSTEM_TEAMPROJECT", "project");
Environment.SetEnvironmentVariable("BUILD_BUILDID", "build");

var pipelines = new AzurePipelines();

// When
var buildUrl = pipelines.BuildUrl;

// Then
buildUrl.Should().Be("https://dev.azure.com/project/_build/results?buildId=build");
}

[Theory, InlineData("http://"), InlineData("http://."), InlineData("http://.."), InlineData("http://../"), InlineData("http://?"), InlineData("http://??"), InlineData("http://#"), InlineData("http://##"), InlineData("//"), InlineData("//a"), InlineData("///a"), InlineData("///"), InlineData("foo.com"), InlineData("rdar://1234"), InlineData("h://test"), InlineData("http:// shouldfail.com"), InlineData(":// should fail"), InlineData("ftps://foo.bar/"), InlineData("http://.www.foo.bar/")]
public void BuildUrl_Should_Be_Empty_When_Appveyor_Url_Is_Invalid_Domain(string urlData)
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONSERVERURI", urlData);
Environment.SetEnvironmentVariable("SYSTEM_TEAMPROJECT", "project");
Environment.SetEnvironmentVariable("BUILD_BUILDID", "build");

var pipelines = new AzurePipelines();

// When
var buildUrl = pipelines.BuildUrl;

// Then
buildUrl.Should().BeEmpty();
}

[Theory, InlineData(null, null), InlineData("", ""), InlineData("foo", "")]
public void Job_Should_Be_Empty_String_When_Enviornment_Variables_Do_Not_Exit(string slugData, string versionData)
{
// Given
Environment.SetEnvironmentVariable("BUILD_REPOSITORY_NAME", slugData);
Environment.SetEnvironmentVariable("BUILD_BUILDNUMBER", versionData);
Environment.SetEnvironmentVariable("BUILD_BUILDID", versionData);

var pipelines = new AzurePipelines();

Expand All @@ -126,14 +233,14 @@ public void Job_Should_Not_Be_Empty_String_When_Enviornment_Variables_Exit()
{
// Given
Environment.SetEnvironmentVariable("BUILD_REPOSITORY_NAME", "foo/bar");
Environment.SetEnvironmentVariable("BUILD_BUILDNUMBER", "bang");
Environment.SetEnvironmentVariable("BUILD_BUILDID", "bang");
var pipelines = new AzurePipelines();

// When
var job = pipelines.Job;

// Then
job.Should().Be("foo/bar/bang");
job.Should().Be("bang");
}

[Fact]
Expand Down Expand Up @@ -164,6 +271,62 @@ public void Pr_Should_Be_Set_When_Enviornment_Variable_Exits()
pr.Should().Be("123");
}

[Fact]
public void Project_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exits()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_TEAMPROJECT", null);
var pipelines = new AzurePipelines();

// When
var project = pipelines.Project;

// Then
project.Should().BeEmpty();
}

[Fact]
public void Project_Should_Be_Set_When_Enviornment_Variable_Exits()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_TEAMPROJECT", "123");
var pipelines = new AzurePipelines();

// When
var project = pipelines.Project;

// Then
project.Should().Be("123");
}

[Fact]
public void ServerUri_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exits()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONSERVERURI", null);
var pipelines = new AzurePipelines();

// When
var serverUri = pipelines.ServerUri;

// Then
serverUri.Should().BeEmpty();
}

[Fact]
public void ServerUri_Should_Be_Set_When_Enviornment_Variable_Exits()
{
// Given
Environment.SetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONSERVERURI", "123");
var pipelines = new AzurePipelines();

// When
var serverUri = pipelines.ServerUri;

// Then
serverUri.Should().Be("123");
}

[Fact]
public void Service_Should_Be_Set_To_AzurePipelines()
{
Expand Down
36 changes: 36 additions & 0 deletions Source/Codecov.Tests/Url/QueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public void Should_Escape_Hash_Token_In_Branch()
public void Should_Return_Defaults()
{
// Given
Environment.SetEnvironmentVariable("CODECOV_SLUG", null);
Environment.SetEnvironmentVariable("CODECOV_TOKEN", null);
var queryOptions = Substitute.For<IQueryOptions>();
var repository = Substitute.For<IEnumerable<IRepository>>();
var build = Substitute.For<IBuild>();
Expand Down Expand Up @@ -217,6 +219,38 @@ public void Should_Set_From_Repository()
repository.Branch.Returns("develop");
repository.Commit.Returns("3c075f8d15aea3b3b40cea0bcf441a30bfd5c5d2");
repository.Pr.Returns("123");
repository.Project.Returns(string.Empty);
repository.ServerUri.Returns(string.Empty);
repository.Tag.Returns("v1.0");
repository.Slug.Returns("larz/codecov-exe");
var build = Substitute.For<IBuild>();
var yaml = Substitute.For<IYaml>();
var query = new Query(queryOptions, new[] { repository }, build, yaml);

// When
var getQuery = query.GetQuery.Split('&');

// Then
getQuery.FirstOrDefault(x => x.StartsWith("branch=")).Should().Be("branch=develop");
getQuery.FirstOrDefault(x => x.StartsWith("commit=")).Should().Be("commit=3c075f8d15aea3b3b40cea0bcf441a30bfd5c5d2");
getQuery.FirstOrDefault(x => x.StartsWith("pr=")).Should().Be("pr=123");
getQuery.FirstOrDefault(x => x.StartsWith("project=")).Should().Be(null);
getQuery.FirstOrDefault(x => x.StartsWith("server_uri=")).Should().Be(null);
getQuery.FirstOrDefault(x => x.StartsWith("tag=")).Should().Be("tag=v1.0");
getQuery.FirstOrDefault(x => x.StartsWith("slug=")).Should().Be("slug=larz%2Fcodecov-exe");
}

[Fact]
public void Should_Set_From_Repository_WithProject()
{
// Given
var queryOptions = Substitute.For<IQueryOptions>();
var repository = Substitute.For<IRepository>();
repository.Branch.Returns("develop");
repository.Commit.Returns("3c075f8d15aea3b3b40cea0bcf441a30bfd5c5d2");
repository.Pr.Returns("123");
repository.Project.Returns("projectA");
repository.ServerUri.Returns("https://dev.azure.com/");
repository.Tag.Returns("v1.0");
repository.Slug.Returns("larz/codecov-exe");
var build = Substitute.For<IBuild>();
Expand All @@ -230,6 +264,8 @@ public void Should_Set_From_Repository()
getQuery.FirstOrDefault(x => x.StartsWith("branch=")).Should().Be("branch=develop");
getQuery.FirstOrDefault(x => x.StartsWith("commit=")).Should().Be("commit=3c075f8d15aea3b3b40cea0bcf441a30bfd5c5d2");
getQuery.FirstOrDefault(x => x.StartsWith("pr=")).Should().Be("pr=123");
getQuery.FirstOrDefault(x => x.StartsWith("project=")).Should().Be("project=projectA");
getQuery.FirstOrDefault(x => x.StartsWith("server_uri=")).Should().Be("server_uri=https://dev.azure.com/");
getQuery.FirstOrDefault(x => x.StartsWith("tag=")).Should().Be("tag=v1.0");
getQuery.FirstOrDefault(x => x.StartsWith("slug=")).Should().Be("slug=larz%2Fcodecov-exe");
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Codecov/Codecov.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<AdditionalFiles Include="$(MSBuildThisFileDirectory)\stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.5.0" />
<PackageReference Include="Glob" Version="1.1.3" />
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="Glob" Version="1.1.4" />
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
<PackageReference Include="Serilog" Version="2.8.0" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Sinks.ColoredConsole" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
Expand Down
Loading

0 comments on commit 599d2ed

Please sign in to comment.