|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +namespace PSRule.Tool.Adapters; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// This is an adapter for handling Azure Pipelines specific functionality |
| 8 | +/// for the official PSRule Azure Pipelines task. |
| 9 | +/// </summary> |
| 10 | +internal sealed class AzurePipelinesAdapter : CIAdapter |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// Load in environment variables from the Azure Pipelines task context. |
| 14 | + /// </summary> |
| 15 | + protected override string[] GetArgs(string[] args) |
| 16 | + { |
| 17 | + var result = new List<string>(args); |
| 18 | + |
| 19 | + if (Environment.TryString("INPUT_INCLUDEPATH", out var includePath) && !string.IsNullOrWhiteSpace(includePath)) |
| 20 | + { |
| 21 | + result.Add("--path"); |
| 22 | + result.Add(includePath); |
| 23 | + WriteInput("IncludePath", includePath); |
| 24 | + } |
| 25 | + |
| 26 | + if (Environment.TryString("INPUT_BASELINE", out var baseline) && !string.IsNullOrWhiteSpace(baseline)) |
| 27 | + { |
| 28 | + result.Add("--baseline"); |
| 29 | + result.Add(baseline); |
| 30 | + WriteInput("Baseline", baseline); |
| 31 | + } |
| 32 | + |
| 33 | + if (Environment.TryStringArray("INPUT_CONVENTIONS", [COMMA], out var conventions) && conventions != null) |
| 34 | + { |
| 35 | + foreach (var convention in conventions) |
| 36 | + { |
| 37 | + if (string.IsNullOrWhiteSpace(convention)) |
| 38 | + continue; |
| 39 | + |
| 40 | + result.Add("--convention"); |
| 41 | + result.Add(convention); |
| 42 | + |
| 43 | + WriteInput("Convention", convention); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + if (Environment.TryString("INPUT_INPUTPATH", out var inputPath) && !string.IsNullOrWhiteSpace(inputPath)) |
| 48 | + { |
| 49 | + result.Add("--input-path"); |
| 50 | + result.Add(inputPath); |
| 51 | + WriteInput("InputPath", inputPath); |
| 52 | + } |
| 53 | + |
| 54 | + else if (Environment.TryStringArray("INPUT_FORMATS", [COMMA], out var formats) && formats != null) |
| 55 | + { |
| 56 | + foreach (var format in formats) |
| 57 | + { |
| 58 | + if (string.IsNullOrWhiteSpace(format)) |
| 59 | + continue; |
| 60 | + |
| 61 | + WriteInput("Format", format); |
| 62 | + } |
| 63 | + |
| 64 | + result.Add("--formats"); |
| 65 | + result.Add(string.Join(" ", formats)); |
| 66 | + } |
| 67 | + |
| 68 | + if (Environment.TryString("INPUT_OPTION", out var option) && !string.IsNullOrWhiteSpace(option)) |
| 69 | + { |
| 70 | + result.Add("--option"); |
| 71 | + result.Add(option); |
| 72 | + WriteInput("Option", option); |
| 73 | + } |
| 74 | + |
| 75 | + if (Environment.TryString("INPUT_OUTCOME", out var outcome) && !string.IsNullOrWhiteSpace(outcome)) |
| 76 | + { |
| 77 | + result.Add("--outcome"); |
| 78 | + result.Add(outcome); |
| 79 | + WriteInput("Outcome", outcome); |
| 80 | + } |
| 81 | + |
| 82 | + if (Environment.TryString("INPUT_OUTPUTFORMAT", out var outputFormat) && !string.IsNullOrWhiteSpace(outputFormat)) |
| 83 | + { |
| 84 | + result.Add("--output"); |
| 85 | + result.Add(outputFormat); |
| 86 | + WriteInput("OutputFormat", outputFormat); |
| 87 | + } |
| 88 | + |
| 89 | + if (Environment.TryString("INPUT_OUTPUTPATH", out var outputPath) && !string.IsNullOrWhiteSpace(outputPath)) |
| 90 | + { |
| 91 | + result.Add("--output-path"); |
| 92 | + result.Add(outputPath); |
| 93 | + WriteInput("OutputPath", outputPath); |
| 94 | + } |
| 95 | + |
| 96 | + if (Environment.TryString("INPUT_SUMMARY", out var summary) && !string.IsNullOrWhiteSpace(summary) && summary == "true") |
| 97 | + { |
| 98 | + // Azure Pipelines doesn't have a built-in job summary path like GitHub Actions |
| 99 | + // We'll use a default path for now |
| 100 | + var jobSummaryPath = "reports/summary.md"; |
| 101 | + result.Add("--job-summary-path"); |
| 102 | + result.Add(jobSummaryPath); |
| 103 | + WriteInput("Summary", summary); |
| 104 | + } |
| 105 | + |
| 106 | + if (Environment.TryStringArray("INPUT_MODULES", [COMMA], out var modules) && modules != null) |
| 107 | + { |
| 108 | + foreach (var module in modules) |
| 109 | + { |
| 110 | + if (string.IsNullOrWhiteSpace(module)) |
| 111 | + continue; |
| 112 | + |
| 113 | + var m = module.Trim(); |
| 114 | + |
| 115 | + result.Add("--module"); |
| 116 | + result.Add(m); |
| 117 | + |
| 118 | + WriteInput("Module", m); |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + return [.. result]; |
| 123 | + } |
| 124 | +} |
0 commit comments