Beispiel #1
0
        public static void Check(
            this ICakeContext context,
            Action <CheckSettings> configSettings)
        {
            var settings = new CheckSettings();

            configSettings(settings);
            context.Check(settings);
        }
Beispiel #2
0
        public static void Check(this ICakeContext context, CheckSettings checkSettings)
        {
            var anyErrors    = false;
            var errorMessage = new StringBuilder();

            checkSettings.GitRoot = checkSettings.GitRoot
                                    ?? context.GitFindRootFromPath(
                new DirectoryPath(".").MakeAbsolute(context.Environment));

            var checks = new List <CheckAction> {
                CheckStagedChanges,
                CheckUncommittedChanges,
                CheckUntrackedFiles,
                CheckReleaseNotesFileExists,
                CheckReleaseNotesVNextFileExists,
                CheckNewReleaseNotes
            };

            foreach (var check in checks)
            {
                var result = check(context, checkSettings);

                switch (result)
                {
                case CheckSkipped _:
                    context.Log.Information($"Skipped: {result.Source}");
                    break;

                case CheckPassed _:
                    context.Log.Information($"Passed: {result.Source}");
                    break;

                case CheckFailed failure:
                    var message = $"Failed: {result.Source} - {failure.Message}";
                    context.Log.Error(message);
                    errorMessage.AppendLine(message);
                    anyErrors = true;
                    break;
                }
            }

            if (anyErrors)
            {
                throw new InvalidOperationException(errorMessage.ToString());
            }
        }
Beispiel #3
0
        public static ICheckResult CheckNewReleaseNotes(
            this ICakeContext context,
            CheckSettings checkSettings)
        {
            if (!checkSettings.RequireReleaseNotes)
            {
                return(new CheckSkipped());
            }

            if (context.AnyReleaseNotes(checkSettings.ReleaseNotesVNextFile))
            {
                return(new CheckPassed());
            }

            return(CheckFailed.WithReason(
                       $"No new release notes found in {checkSettings.ReleaseNotesVNextFile}"));
        }
Beispiel #4
0
        public static ICheckResult CheckReleaseNotesVNextFileExists(
            this ICakeContext context,
            CheckSettings checkSettings)
        {
            if (!checkSettings.RequireReleaseNotes)
            {
                return(new CheckSkipped());
            }

            if (context.FileExists(checkSettings.ReleaseNotesVNextFile))
            {
                return(new CheckPassed());
            }

            return(CheckFailed.WithReason(
                       $"Unable to find release notes file: {checkSettings.ReleaseNotesVNextFile}"));
        }
Beispiel #5
0
        public static ICheckResult CheckUntrackedFiles(
            this ICakeContext context,
            CheckSettings checkSettings)
        {
            if (!checkSettings.UntrackedFiles)
            {
                return(new CheckSkipped());
            }

            if (!context.GitHasUntrackedFiles(checkSettings.GitRoot))
            {
                return(new CheckPassed());
            }

            return(CheckFailed.WithReason(
                       "Git has untracked files, please commit or ignore files before building"));
        }
Beispiel #6
0
        public static ICheckResult CheckStagedChanges(
            this ICakeContext context,
            CheckSettings checkSettings)
        {
            if (!checkSettings.StagedChanges)
            {
                return(new CheckSkipped());
            }

            if (!context.GitHasStagedChanges(checkSettings.GitRoot))
            {
                return(new CheckPassed());
            }

            return(CheckFailed.WithReason(
                       "Git has staged changed, please commit all files before building"));
        }