From ce49acf7fb4fe2dfb054a155bbb9c0547bfe35b5 Mon Sep 17 00:00:00 2001 From: Christo du Toit Date: Wed, 27 Dec 2023 16:31:06 +0000 Subject: [PATCH] FOUNDATIONS: Created Job To Check PR Title --- .github/workflows/dotnet.yml | 68 ++++++++++ ADotNet.Infrastructure.Build/Program.cs | 7 +- .../DotNets/CheckPRTitleJob.cs | 120 ++++++++++++++++++ 3 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 ADotNet/Models/Pipelines/GithubPipelines/DotNets/CheckPRTitleJob.cs diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 73bddd0..398cee5 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -27,8 +27,76 @@ env: ) }} jobs: + check_pr_title: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Check PR Title + run: >- + PR_TITLE="${{ github.event.pull_request.title }}" + + + # Define the list of prefixes + + PREFIXES=( + "ACCEPTANCE" + "AGGREGATION" + "BASE" + "BROKER" + "BUSINESS" + "CODE RUB" + "COMPONENT" + "CONFIG" + "CONTROLLER" + "COORDINATION" + "CLIENT" + "DATA" + "DESIGN" + "DOCUMENTATION" + "EXPOSER" + "FOUNDATION" + "INFRA" + "INTEGRATION" + "MAJORFIX" + "MANAGEMENT" + "MEDIUMFIX" + "MINORFIX" + "ORCHESTRATION" + "PAGE" + "PROCESSING" + "PROVISION" + "RELEASE" + "STANDARD" + "VIEW" + ) + + + # Check if the PR title starts with any of the prefixes + + PREFIX_MATCH=false + + for PREFIX in "${PREFIXES[@]}" + + do + if [[ "${PR_TITLE}" == "${PREFIX}"* ]]; then + PREFIX_MATCH=true + break + fi + done + + + # Fail the workflow if no prefix match is found + + if [ "${PREFIX_MATCH}" == false ]; then + echo "error: The PR title must start with one of THE STANDARD specified prefixes. Current PR Title: '${{ github.event.pull_request.title }}'" + echo "See https://github.com/hassanhabib/The-Standard-Team/blob/main/4%20Practices/4%20Practices.md#4113-category-list for the complete category list" + exit 1 + fi build: runs-on: ubuntu-latest + needs: + - check_pr_title steps: - name: Check out uses: actions/checkout@v3 diff --git a/ADotNet.Infrastructure.Build/Program.cs b/ADotNet.Infrastructure.Build/Program.cs index bbfde8f..0be9e4e 100644 --- a/ADotNet.Infrastructure.Build/Program.cs +++ b/ADotNet.Infrastructure.Build/Program.cs @@ -9,7 +9,6 @@ using ADotNet.Clients; using ADotNet.Models.Pipelines.GithubPipelines.DotNets; using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks; -using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV1s; using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV3s; namespace ADotNet.Infrastructure.Build @@ -46,11 +45,17 @@ static void Main(string[] args) Jobs = new Dictionary { + { + "check_pr_title", + new CheckPrTitleJob( + runsOn: BuildMachines.UbuntuLatest) + }, { "build", new Job { RunsOn = BuildMachines.UbuntuLatest, + Needs = new string[] { "check_pr_title" }, Steps = new List { diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/CheckPRTitleJob.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/CheckPRTitleJob.cs new file mode 100644 index 0000000..f16ddc6 --- /dev/null +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/CheckPRTitleJob.cs @@ -0,0 +1,120 @@ +// --------------------------------------------------------------------------- +// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved. +// Licensed under the MIT License. +// See License.txt in the project root for license information. +// --------------------------------------------------------------------------- + +using System.Collections.Generic; +using System.ComponentModel; +using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks; +using YamlDotNet.Serialization; + +namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets +{ + public sealed class CheckPrTitleJob : Job + { + public CheckPrTitleJob( + string runsOn) + { + RunsOn = runsOn; + + Steps = new List + { + new CheckoutTaskV3 + { + Name = "Checkout code", + }, + + new GithubTask() + { + Name = "Check PR Title", + Run = @"PR_TITLE=""${{ github.event.pull_request.title }}"" + +# Define the list of prefixes +PREFIXES=( + ""ACCEPTANCE"" + ""AGGREGATION"" + ""BASE"" + ""BROKER"" + ""BUSINESS"" + ""CODE RUB"" + ""COMPONENT"" + ""CONFIG"" + ""CONTROLLER"" + ""COORDINATION"" + ""CLIENT"" + ""DATA"" + ""DESIGN"" + ""DOCUMENTATION"" + ""EXPOSER"" + ""FOUNDATION"" + ""INFRA"" + ""INTEGRATION"" + ""MAJORFIX"" + ""MANAGEMENT"" + ""MEDIUMFIX"" + ""MINORFIX"" + ""ORCHESTRATION"" + ""PAGE"" + ""PROCESSING"" + ""PROVISION"" + ""RELEASE"" + ""STANDARD"" + ""VIEW"" +) + +# Check if the PR title starts with any of the prefixes +PREFIX_MATCH=false +for PREFIX in ""${PREFIXES[@]}"" +do + if [[ ""${PR_TITLE}"" == ""${PREFIX}""* ]]; then + PREFIX_MATCH=true + break + fi +done + +# Fail the workflow if no prefix match is found +if [ ""${PREFIX_MATCH}"" == false ]; then + echo ""error: The PR title must start with one of THE STANDARD specified prefixes. Current PR Title: '${{ github.event.pull_request.title }}'"" + echo ""See https://github.com/hassanhabib/The-Standard-Team/blob/main/4%20Practices/4%20Practices.md#4113-category-list for the complete category list"" + exit 1 +fi" + }, + }; + } + + [YamlMember(Order = 0, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new string Name { get; set; } + + [YamlMember(Order = 1, Alias = "runs-on")] + public new string RunsOn { get; set; } + + [YamlMember(Order = 2, Alias = "needs", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new string[] Needs { get; set; } + + [YamlMember(Order = 3, Alias = "if", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new string If { get; set; } + + [YamlMember(Order = 4, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new string Environment { get; set; } + + [YamlMember(Order = 5, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new DefaultValues Defaults { get; set; } + + [YamlMember(Order = 6)] + public new List Steps { get; set; } + + [DefaultValue(0)] + [YamlMember(Order = 7, Alias = "timeout-minutes", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new int TimeoutInMinutes { get; set; } + + [YamlMember(Order = 8, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new Strategy Strategy { get; set; } + + [YamlMember(Order = 9, Alias = "env", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new Dictionary EnvironmentVariables { get; set; } + + [YamlMember(Order = 10, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new Dictionary Outputs { get; set; } + } +}