Skip to content

Commit

Permalink
Merge pull request cake-contrib#1002 from AdmiringWorm/codecov-update
Browse files Browse the repository at this point in the history
(cake-contrib#1001) Remove tokenless support for Codecov
  • Loading branch information
gep13 authored Aug 1, 2024
2 parents e5211f5 + 924d726 commit 65a4f51
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Source/Cake.Recipe/Content/addins.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ADDINS
///////////////////////////////////////////////////////////////////////////////

#addin nuget:?package=Cake.Codecov&version=1.0.1
#addin nuget:?package=Cake.Codecov&version=2.0.0
#addin nuget:?package=Cake.Coveralls&version=1.1.0
#addin nuget:?package=Cake.Coverlet&version=2.5.4
#addin nuget:?package=Portable.BouncyCastle&version=1.8.5
Expand Down
3 changes: 2 additions & 1 deletion Source/Cake.Recipe/Content/appveyor.cake
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public class AppVeyorBuildProvider : IBuildProvider

public IBuildInfo Build { get; }

public bool SupportsTokenlessCodecov { get; } = true;
[System.Obsolete("Codecov CLI no longer officially supports tokenless uploads.")]
public bool SupportsTokenlessCodecov { get; } = false;

public BuildProviderType Type { get; } = BuildProviderType.AppVeyor;

Expand Down
3 changes: 2 additions & 1 deletion Source/Cake.Recipe/Content/azurepipelines.cake
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public class AzurePipelinesBuildProvider : IBuildProvider

public IBuildInfo Build { get; }

public bool SupportsTokenlessCodecov { get; } = true;
[System.Obsolete("Codecov CLI no longer officially supports tokenless uploads.")]
public bool SupportsTokenlessCodecov { get; } = false;

public BuildProviderType Type { get; } = BuildProviderType.AzurePipelines;

Expand Down
1 change: 1 addition & 0 deletions Source/Cake.Recipe/Content/buildProvider.cake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public interface IBuildProvider

IBuildInfo Build { get; }

[System.Obsolete("Codecov CLI no longer officially supports tokenless uploads.")]
bool SupportsTokenlessCodecov { get; }

IEnumerable<string> PrintVariables { get; }
Expand Down
5 changes: 3 additions & 2 deletions Source/Cake.Recipe/Content/codecov.cake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
BuildParameters.Tasks.UploadCodecovReportTask = Task("Upload-Codecov-Report")
.WithCriteria(() => BuildParameters.IsMainRepository, "Skipping because not running from the main repository")
.WithCriteria(() => BuildParameters.ShouldRunCodecov, "Skipping because uploading to codecov is disabled")
.WithCriteria(() => BuildParameters.CanPublishToCodecov, "Skipping because repo token is missing, or not running on appveyor")
.WithCriteria(() => BuildParameters.CanPublishToCodecov, "Skipping because repo token is missing, or not running on GitHub CI")
.Does<BuildVersion>((context, buildVersion) => RequireTool(BuildParameters.IsDotNetCoreBuild ? ToolSettings.CodecovGlobalTool : ToolSettings.CodecovTool, () => {
var coverageFiles = GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/coverlet/*.xml");
if (FileExists(BuildParameters.Paths.Files.TestCoverageOutputFilePath))
Expand All @@ -17,7 +17,8 @@ BuildParameters.Tasks.UploadCodecovReportTask = Task("Upload-Codecov-Report")
{
var settings = new CodecovSettings {
Files = coverageFiles.Select(f => f.FullPath),
Required = true
NonZero = true,
Token = BuildParameters.Codecov.RepoToken
};
if (buildVersion != null &&
!string.IsNullOrEmpty(buildVersion.FullSemVersion) &&
Expand Down
17 changes: 15 additions & 2 deletions Source/Cake.Recipe/Content/credentials.cake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public class CodecovCredentials : CoverallsCredentials

public class CoverallsCredentials
{
public bool HasCredentials
{
get { return !string.IsNullOrEmpty(RepoToken); }
}

public string RepoToken { get; private set; }

public CoverallsCredentials(string repoToken)
Expand Down Expand Up @@ -187,8 +192,16 @@ public static AppVeyorCredentials GetAppVeyorCredentials(ICakeContext context)

public static CodecovCredentials GetCodecovCredentials(ICakeContext context)
{
return new CodecovCredentials(
context.EnvironmentVariable(Environment.CodecovRepoTokenVariable));
var token = context.EnvironmentVariable(Environment.CodecovRepoTokenVariable);

if (string.IsNullOrEmpty(token))
{
// Fallback to attempt to check for the conventional CODECOV_TOKEN which
// the CLI tools read automatically.
token = context.EnvironmentVariable("CODECOV_TOKEN");
}

return new CodecovCredentials(token);
}

public static CoverallsCredentials GetCoverallsCredentials(ICakeContext context)
Expand Down
3 changes: 2 additions & 1 deletion Source/Cake.Recipe/Content/github-actions.cake
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public class GitHubActionBuildProvider : IBuildProvider
public IPullRequestInfo PullRequest { get; }
public IRepositoryInfo Repository { get; }

public bool SupportsTokenlessCodecov { get; } = true;
[System.Obsolete("Codecov CLI no longer officially supports tokenless uploads.")]
public bool SupportsTokenlessCodecov { get; } = false;

public BuildProviderType Type { get; } = BuildProviderType.GitHubActions;

Expand Down
1 change: 1 addition & 0 deletions Source/Cake.Recipe/Content/localbuild.cake
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public class LocalBuildBuildProvider : IBuildProvider

public IBuildInfo Build { get; }

[System.Obsolete("Codecov CLI no longer officially supports tokenless uploads.")]
public bool SupportsTokenlessCodecov { get; } = false;

public BuildProviderType Type { get; } = BuildProviderType.Local;
Expand Down
7 changes: 2 additions & 5 deletions Source/Cake.Recipe/Content/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,15 @@ public static class BuildParameters
{
get
{
return ShouldRunCodecov && (
BuildProvider.SupportsTokenlessCodecov ||
!string.IsNullOrEmpty(Codecov.RepoToken)
);
return ShouldRunCodecov && Codecov.HasCredentials;
}
}

public static bool CanPublishToCoveralls
{
get
{
return ShouldRunCoveralls && !string.IsNullOrEmpty(BuildParameters.Coveralls.RepoToken);
return ShouldRunCoveralls && Coveralls.HasCredentials;
}
}

Expand Down
1 change: 1 addition & 0 deletions Source/Cake.Recipe/Content/teamcity.cake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class TeamCityBuildProvider : IBuildProvider

public IBuildInfo Build { get; }

[System.Obsolete("Codecov CLI no longer officially supports tokenless uploads.")]
public bool SupportsTokenlessCodecov { get; } = false;

public BuildProviderType Type { get; } = BuildProviderType.TeamCity;
Expand Down
5 changes: 3 additions & 2 deletions Source/Cake.Recipe/Content/toolsettings.cake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class ToolSettings
public static string ReportGeneratorTool { get; private set; }
public static string ReportUnitTool { get; private set; }

[System.Obsolete("The Global Tool of Codecov is no longer supported. Use the Normal codecovTool going forward.")]
public static string CodecovGlobalTool { get; private set; }
public static string CoverallsGlobalTool { get; private set; }
public static string GitReleaseManagerGlobalTool { get; private set; }
Expand All @@ -37,7 +38,7 @@ public static class ToolSettings
public static string KuduSyncGlobalTool { get; private set; }

public static void SetToolPreprocessorDirectives(
string codecovTool = "#tool nuget:?package=codecov&version=1.13.0",
string codecovTool = "#tool nuget:?package=CodecovUploader&version=0.7.3",
// This is specifically pinned to 0.7.0 as later versions of same package publish .Net Global Tool, rather than full framework version
string coverallsTool = "#tool nuget:?package=coveralls.net&version=0.7.0",
string gitReleaseManagerTool = "#tool nuget:?package=GitReleaseManager&version=0.18.0",
Expand All @@ -52,7 +53,7 @@ public static class ToolSettings
string openCoverTool = "#tool nuget:?package=OpenCover&version=4.7.1221",
string reportGeneratorTool = "#tool nuget:?package=ReportGenerator&version=5.3.8",
string reportUnitTool = "#tool nuget:?package=ReportUnit&version=1.2.1",
string codecovGlobalTool = "#tool dotnet:?package=Codecov.Tool&version=1.13.0",
string codecovGlobalTool = "#tool nuget:?package=CodecovUploader&version=0.7.3",
string coverallsGlobalTool = "#tool dotnet:?package=coveralls.net&version=1.0.0",
string gitReleaseManagerGlobalTool = "#tool dotnet:?package=GitReleaseManager.Tool&version=0.18.0",
string gitVersionGlobalTool = "#tool dotnet:?package=GitVersion.Tool&version=5.12.0",
Expand Down
3 changes: 2 additions & 1 deletion Source/Cake.Recipe/Content/travis-ci.cake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public class TravisCiBuildProvider : IBuildProvider
public IPullRequestInfo PullRequest { get; }
public IRepositoryInfo Repository { get; }

public bool SupportsTokenlessCodecov { get; } = true;
[System.Obsolete("Codecov CLI no longer officially supports tokenless uploads.")]
public bool SupportsTokenlessCodecov { get; } = false;

public BuildProviderType Type { get; } = BuildProviderType.Travis;

Expand Down
10 changes: 2 additions & 8 deletions docs/input/docs/fundamentals/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,7 @@ In addition to this environment variable being present, and correct, the control

### CODECOV_REPO_TOKEN

API token for uploading coverage reports to codecov.io.

:::{.alert .alert-info}
**NOTE:**

This token is entirely optional for public repositories building on AppVeyor, and is recommended to only be used on private repositories*
:::
API token for uploading coverage reports to [Codecov](https://about.codecov.io/).

## Coveralls

Expand All @@ -175,7 +169,7 @@ In addition to this environment variable being present, and correct, the control

### COVERALLS_REPO_TOKEN

API token for uploading coverage reports to codecov.io.
API token for uploading coverage reports to [Coveralls](https://coveralls.io/).

## Transifex

Expand Down
11 changes: 10 additions & 1 deletion docs/input/docs/upgrading/3.x-to-4.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ Cake.Recipe is now using 2.3.0 of Cake, and as such, we recommend that any build

In this release of Cake.Recipe we have upgraded to 2.0.0 of Cake.Issues.Recipe. If in your build scripts you have extended the built in usage of Cake.Issues.Recipe you may need to check the release notes to confirm if there are any additional changes that need to be made.

[Check out the blog post here for additional information](https://cakeissues.net/news/cake-issues-v2.0.0-released).
[Check out the blog post here for additional information](https://cakeissues.net/news/cake-issues-v2.0.0-released).

### Codecov Coverage Uploads

In this release of Cake.Recipe we have updated the support for Codecov to now
require a token to be specified. If in your build scripts you have Codecov
enabled by default, you will see this task being skipped if you have not already
specified a token.

[Check out Codecov documentation for adding a token](https://docs.codecov.com/docs/adding-the-codecov-token)

0 comments on commit 65a4f51

Please sign in to comment.