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

Commit

Permalink
(GH-100) Fixed github actions not properly detected
Browse files Browse the repository at this point in the history
fixes #100
  • Loading branch information
AdmiringWorm committed Jun 9, 2020
1 parent 24d67dd commit 62af77d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Codecov.Services.ContinuousIntegrationServers;
using Codecov.Services.ContinuousIntegrationServers;
using FluentAssertions;
using Moq;
using Xunit;
Expand Down Expand Up @@ -68,8 +67,24 @@ public void Commit_Should_Be_Set_When_Enviornment_Variable_Exits()
commit.Should().Be("123");
}

[Fact]
public void Detecter_Should_Be_False_When_Action_Environment_Variable_Is_Null_Or_Empty()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTION")).Returns(string.Empty);
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTIONS")).Returns(string.Empty);
var githubAction = ga.Object;

// When
var detecter = githubAction.Detecter;

// Then
detecter.Should().BeFalse();
}

[Theory, InlineData(null), InlineData(""), InlineData("False"), InlineData("false"), InlineData("foo")]
public void Detecter_Should_Be_False_When_Actions_Environment_Variable_Does_Not_Exist_Or_Is_Not_True(string environmentData)
public void Detecter_Should_Be_False_When_Actions_And_Action_Environment_Variable_Does_Not_Exist_Or_Is_Not_True(string environmentData)
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
Expand All @@ -83,6 +98,21 @@ public void Detecter_Should_Be_False_When_Actions_Environment_Variable_Does_Not_
detecter.Should().BeFalse();
}

[Fact]
public void Detecter_Should_Be_True_When_Action_Environment_Variable_Exist_And_Is_Not_Empty()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTION")).Returns("my-awesome-github-action");
var githubActions = ga.Object;

// When
var detecter = githubActions.Detecter;

// Then
detecter.Should().BeTrue();
}

[Theory, InlineData("True"), InlineData("true")]
public void Detecter_Should_Be_True_When_Actions_Environment_Variable_Exist_And_Is_True(string environmentData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public GitHubAction()
{
_branch = new Lazy<string>(LoadBranch);
_commit = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_SHA"));
_detecter = new Lazy<bool>(() => CheckEnvironmentVariables("GITHUB_ACTIONS"));
_detecter = new Lazy<bool>(() => CheckEnvironmentVariables("GITHUB_ACTIONS") || !string.IsNullOrWhiteSpace(GetEnvironmentVariable("GITHUB_ACTION")));
_slug = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_REPOSITORY"));
}

Expand Down

0 comments on commit 62af77d

Please sign in to comment.