Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOUNDATIONS: Check PR Title Job #95

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,82 @@ 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 }}"


echo "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"
echo ""
echo "Please update the PR Title to the correct category, then navigate to the Actions tab and click on the Re-run jobs button"
echo "P.S. if the job fails again with the wrong title, give it a few minutes to allow the PR Title Change event to propagate through the system."
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
125 changes: 125 additions & 0 deletions ADotNet/Models/Pipelines/GithubPipelines/DotNets/CheckPRTitleJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// ---------------------------------------------------------------------------
// 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 }}""

echo ""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""
echo """"
echo ""Please update the PR Title to the correct category, then navigate to the Actions tab and click on the Re-run jobs button""
echo ""P.S. if the job fails again with the wrong title, give it a few minutes to allow the PR Title Change event to propagate through the system.""
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; }
}
}
Loading