Skip to content

Commit

Permalink
(cake-contribGH-18) added depcheck to the pipeline
Browse files Browse the repository at this point in the history
Depcheck will raise warnings. if unused packages are referenced
in packages.json.

configuration:
 * shouldRunDepcheck (bool) configures whether to run depcheck at all.
Default: true
 * shouldFailOnDepcheckError (bool) configures whether depcheck errors
will break the build or only raise warnings. Default: true.
 *  depcheckArguments (string) arguments to pass to the call of depcheck.
 Default: ""
  • Loading branch information
nils-a committed Dec 21, 2020
1 parent b8651d9 commit 1d70a03
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Cake.VsCode.Recipe/Content/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ BuildParameters.Tasks.UpdateProjectJsonVersionTask = Task("Update-Project-Json-V
});

BuildParameters.Tasks.PackageExtensionTask = Task("Package-Extension")
.IsDependentOn("Depcheck")
.IsDependentOn("Export-Release-Notes")
.IsDependentOn("Update-Project-Json-Version")
.IsDependentOn("Npm-Install")
Expand Down Expand Up @@ -217,6 +218,31 @@ BuildParameters.Tasks.AppVeyorTask = Task("AppVeyor")
}
});

BuildParameters.Tasks.DepcheckTask = Task("Depcheck")
.WithCriteria(() => BuildParameters.ShouldRunDepcheck)
.Does(() =>
{
// install depcheck
var settings = new NpmInstallSettings {
Global = true,
LogLevel = NpmLogLevel.Silent
};
settings.AddPackage("depcheck");
NpmInstall(settings);
// run
var proc = "depcheck";
if(BuildParameters.IsRunningOnWindows) {
proc += ".cmd";
}
var ret = StartProcess(proc, BuildParameters.DepcheckArguments);
if(ret != 0) {
Error("There are unused dependencies.");
// TODO: break the build? Call out to cake.issues.recipe?
}
});

BuildParameters.Tasks.ReleaseNotesTask = Task("ReleaseNotes")
.IsDependentOn("Create-Release-Notes");

Expand Down
13 changes: 12 additions & 1 deletion Cake.VsCode.Recipe/Content/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public static class BuildParameters
public static string WebLinkRoot { get; private set; }
public static string WebBaseEditUrl { get; private set; }

public static bool ShouldRunDepcheck { get; private set; }
public static string DepcheckArguments { get; private set; }

public static IBuildProvider BuildProvider { get; private set; }

static BuildParameters()
Expand Down Expand Up @@ -265,6 +268,9 @@ public static class BuildParameters
context.Information("MarketplacePublisher: {0}", MarketplacePublisher);
context.Information("ChocolateyPackagingFolderName: {0}", ChocolateyPackagingFolderName);
context.Information("ChocolateyPackagingPackageId: {0}", ChocolateyPackagingPackageId);

context.Information("ShouldRunDepcheck: {0}", ShouldRunDepcheck);
context.Information("DepcheckArguments: {0}", DepcheckArguments);
}

public static void SetParameters(
Expand Down Expand Up @@ -309,7 +315,9 @@ public static class BuildParameters
string vsceVersionNumber = "1.43.0",
string marketPlacePublisher = "gep13",
string chocolateyPackagingFolderName = "chocolatey",
string chocolateyPackagingPackageId = null
string chocolateyPackagingPackageId = null,
bool shouldRunDepcheck = true,
string depcheckArguments = null
)
{
if (context == null)
Expand Down Expand Up @@ -378,6 +386,9 @@ public static class BuildParameters
!string.IsNullOrWhiteSpace(BuildProvider.Repository.Tag.Name)
);
TreatWarningsAsErrors = treatWarningsAsErrors;
ShouldRunDepcheck = shouldRunDepcheck;
DepcheckArguments = depcheckArguments ?? "";

GitHub = GetGitHubCredentials(context);
MicrosoftTeams = GetMicrosoftTeamsCredentials(context);
Gitter = GetGitterCredentials(context);
Expand Down
1 change: 1 addition & 0 deletions Cake.VsCode.Recipe/Content/tasks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class BuildTasks
public CakeTaskBuilder ShowInfoTask { get; set; }
public CakeTaskBuilder CleanTask { get; set; }
public CakeTaskBuilder DefaultTask { get; set; }
public CakeTaskBuilder DepcheckTask { get; set; }
public CakeTaskBuilder AppVeyorTask { get; set; }
public CakeTaskBuilder ReleaseNotesTask { get; set; }
public CakeTaskBuilder LabelsTask { get; set; }
Expand Down

0 comments on commit 1d70a03

Please sign in to comment.