Skip to content

Commit

Permalink
FOUNDATIONS: Created Job To Check PR Title
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdutoit committed Dec 27, 2023
1 parent b99bf97 commit ce49acf
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 1 deletion.
68 changes: 68 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion ADotNet.Infrastructure.Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,11 +45,17 @@ static void Main(string[] args)

Jobs = new Dictionary<string, Job>
{
{
"check_pr_title",
new CheckPrTitleJob(
runsOn: BuildMachines.UbuntuLatest)
},
{
"build",
new Job
{
RunsOn = BuildMachines.UbuntuLatest,
Needs = new string[] { "check_pr_title" },

Steps = new List<GithubTask>
{
Expand Down
120 changes: 120 additions & 0 deletions ADotNet/Models/Pipelines/GithubPipelines/DotNets/CheckPRTitleJob.cs
Original file line number Diff line number Diff line change
@@ -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<GithubTask>
{
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<GithubTask> 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<string, string> EnvironmentVariables { get; set; }

[YamlMember(Order = 10, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public new Dictionary<string, string> Outputs { get; set; }
}
}

0 comments on commit ce49acf

Please sign in to comment.