|
| 1 | +namespace Sigtran.NET.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Describes maintained external peer lab CI execution policy. |
| 5 | +/// </summary> |
| 6 | +public sealed class SigtranMaintainedPeerLabCiProfile |
| 7 | +{ |
| 8 | + /// <summary>Creates a maintained external peer lab CI profile.</summary> |
| 9 | + /// <param name="name">The CI profile name.</param> |
| 10 | + /// <param name="manualDispatchOnly">Whether the lab is manual-dispatch only.</param> |
| 11 | + /// <param name="requiresSelfHostedLinux">Whether a self-hosted Linux runner is required.</param> |
| 12 | + /// <param name="requiredEnvironmentVariables">The required environment variables.</param> |
| 13 | + /// <param name="artifactPatterns">The retained artifact upload patterns.</param> |
| 14 | + public SigtranMaintainedPeerLabCiProfile( |
| 15 | + string name, |
| 16 | + bool manualDispatchOnly, |
| 17 | + bool requiresSelfHostedLinux, |
| 18 | + IReadOnlyList<string> requiredEnvironmentVariables, |
| 19 | + IReadOnlyList<string> artifactPatterns) |
| 20 | + { |
| 21 | + ArgumentNullException.ThrowIfNull(requiredEnvironmentVariables); |
| 22 | + ArgumentNullException.ThrowIfNull(artifactPatterns); |
| 23 | + |
| 24 | + Name = string.IsNullOrWhiteSpace(name) ? throw new ArgumentException("CI profile name is required.", nameof(name)) : name; |
| 25 | + ManualDispatchOnly = manualDispatchOnly; |
| 26 | + RequiresSelfHostedLinux = requiresSelfHostedLinux; |
| 27 | + RequiredEnvironmentVariables = requiredEnvironmentVariables.Count == 0 |
| 28 | + ? throw new ArgumentException("At least one environment variable is required.", nameof(requiredEnvironmentVariables)) |
| 29 | + : requiredEnvironmentVariables.ToArray(); |
| 30 | + ArtifactPatterns = artifactPatterns.Count == 0 |
| 31 | + ? throw new ArgumentException("At least one artifact pattern is required.", nameof(artifactPatterns)) |
| 32 | + : artifactPatterns.ToArray(); |
| 33 | + } |
| 34 | + |
| 35 | + /// <summary>The CI profile name.</summary> |
| 36 | + public string Name { get; } |
| 37 | + |
| 38 | + /// <summary>Whether the lab is manual-dispatch only.</summary> |
| 39 | + public bool ManualDispatchOnly { get; } |
| 40 | + |
| 41 | + /// <summary>Whether a self-hosted Linux runner is required.</summary> |
| 42 | + public bool RequiresSelfHostedLinux { get; } |
| 43 | + |
| 44 | + /// <summary>The required environment variables.</summary> |
| 45 | + public IReadOnlyList<string> RequiredEnvironmentVariables { get; } |
| 46 | + |
| 47 | + /// <summary>The retained artifact upload patterns.</summary> |
| 48 | + public IReadOnlyList<string> ArtifactPatterns { get; } |
| 49 | + |
| 50 | + /// <summary>Whether this profile is safe to run in default pull request CI.</summary> |
| 51 | + public bool SafeForDefaultCi => !RequiresSelfHostedLinux && !ManualDispatchOnly; |
| 52 | + |
| 53 | + /// <summary>Formats a compact CI profile summary.</summary> |
| 54 | + /// <returns>The CI profile summary.</returns> |
| 55 | + public string Describe() |
| 56 | + { |
| 57 | + return $"name={Name} manual={ManualDispatchOnly} selfHostedLinux={RequiresSelfHostedLinux} env={RequiredEnvironmentVariables.Count} artifacts={ArtifactPatterns.Count}"; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +/// <summary> |
| 62 | +/// Provides maintained external peer lab CI profile helpers. |
| 63 | +/// </summary> |
| 64 | +public static class SigtranMaintainedPeerLabCi |
| 65 | +{ |
| 66 | + /// <summary>Creates the default maintained external peer lab CI profile.</summary> |
| 67 | + /// <returns>The default maintained external peer lab CI profile.</returns> |
| 68 | + public static SigtranMaintainedPeerLabCiProfile CreateDefault() |
| 69 | + { |
| 70 | + return new( |
| 71 | + "maintained-peer-lab", |
| 72 | + manualDispatchOnly: true, |
| 73 | + requiresSelfHostedLinux: true, |
| 74 | + requiredEnvironmentVariables: |
| 75 | + [ |
| 76 | + SigtranMaintainedPeerLabBindings.PeerIdEnvironmentVariable, |
| 77 | + SigtranMaintainedPeerLabBindings.PackageEnvironmentVariable, |
| 78 | + SigtranMaintainedPeerLabBindings.PackageVersionEnvironmentVariable, |
| 79 | + SigtranMaintainedPeerLabBindings.ArtifactRootEnvironmentVariable, |
| 80 | + "LOCAL_IP", |
| 81 | + "LOCAL_SCTP_PORT", |
| 82 | + "REMOTE_IP", |
| 83 | + "REMOTE_SCTP_PORT", |
| 84 | + "ROUTING_CONTEXT" |
| 85 | + ], |
| 86 | + artifactPatterns: |
| 87 | + [ |
| 88 | + "artifacts/external-peer/**/pcap/*.pcap", |
| 89 | + "artifacts/external-peer/**/logs/*.log", |
| 90 | + "artifacts/external-peer/**/config/*.env", |
| 91 | + "artifacts/external-peer/**/trace/*.jsonl", |
| 92 | + "artifacts/external-peer/**/comparison/*.md", |
| 93 | + "artifacts/external-peer/**/reports/*.md" |
| 94 | + ]); |
| 95 | + } |
| 96 | +} |
0 commit comments