Skip to content

Commit

Permalink
Merge pull request #128 from The-Standard-Organization/users/cjdutoit…
Browse files Browse the repository at this point in the history
…/minorfoundations-requireissueortask

FOUNDATIONS:   Require Issue Or Task
  • Loading branch information
hassanhabib authored Jan 8, 2025
2 parents 7c84783 + 88c34ea commit c71dc5e
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 198 deletions.
93 changes: 2 additions & 91 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,96 +11,7 @@ on:
- closed
branches:
- main
env:
IS_RELEASE_CANDIDATE: >-
${{
(
github.event_name == 'pull_request' &&
startsWith(github.event.pull_request.title, 'RELEASES:') &&
contains(github.event.pull_request.labels.*.name, 'RELEASES')
)
||
(
github.event_name == 'push' &&
startsWith(github.event.head_commit.message, 'RELEASES:') &&
startsWith(github.ref_name, 'RELEASE')
)
}}
jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Apply Label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: >-
const prefixes = [
'INFRA:',
'PROVISIONS:',
'RELEASES:',
'DATA:',
'BROKERS:',
'FOUNDATIONS:',
'PROCESSINGS:',
'ORCHESTRATIONS:',
'COORDINATIONS:',
'MANAGEMENTS:',
'AGGREGATIONS:',
'CONTROLLERS:',
'CLIENTS:',
'EXPOSERS:',
'PROVIDERS:',
'BASE:',
'COMPONENTS:',
'VIEWS:',
'PAGES:',
'ACCEPTANCE:',
'INTEGRATIONS:',
'CODE RUB:',
'MINOR FIX:',
'MEDIUM FIX:',
'MAJOR FIX:',
'DOCUMENTATION:',
'CONFIG:',
'STANDARD:',
'DESIGN:',
'BUSINESS:'
];
const pullRequest = context.payload.pull_request;
if (!pullRequest) {
console.log('No pull request context available.');
return;
}
const title = context.payload.pull_request.title;
const existingLabels = context.payload.pull_request.labels.map(label => label.name);
for (const prefix of prefixes) {
if (title.startsWith(prefix)) {
const label = prefix.slice(0, -1);
if (!existingLabels.includes(label)) {
console.log(`Applying label: ${label}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: [label]
});
}
break;
}
}
permissions:
contents: read
pull-requests: write
build:
runs-on: ubuntu-latest
steps:
Expand All @@ -109,7 +20,7 @@ jobs:
- name: Setup .Net
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.201
dotnet-version: 9.0.100
- name: Restore
run: dotnet restore
- name: Build
Expand Down Expand Up @@ -208,7 +119,7 @@ jobs:
- name: Setup .Net
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.201
dotnet-version: 9.0.100
- name: Restore
run: dotnet restore
- name: Build
Expand Down
138 changes: 138 additions & 0 deletions .github/workflows/prLinter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: PR Linter
on:
push:
branches:
- main
pull_request:
types:
- opened
- edited
- synchronize
- reopened
- closed
branches:
- main
jobs:
label:
name: Label
runs-on: ubuntu-latest
steps:
- name: Apply Label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: >-
const prefixes = [
'INFRA:',
'PROVISIONS:',
'RELEASES:',
'DATA:',
'BROKERS:',
'FOUNDATIONS:',
'PROCESSINGS:',
'ORCHESTRATIONS:',
'COORDINATIONS:',
'MANAGEMENTS:',
'AGGREGATIONS:',
'CONTROLLERS:',
'CLIENTS:',
'EXPOSERS:',
'PROVIDERS:',
'BASE:',
'COMPONENTS:',
'VIEWS:',
'PAGES:',
'ACCEPTANCE:',
'INTEGRATIONS:',
'CODE RUB:',
'MINOR FIX:',
'MEDIUM FIX:',
'MAJOR FIX:',
'DOCUMENTATION:',
'CONFIG:',
'STANDARD:',
'DESIGN:',
'BUSINESS:'
];
const pullRequest = context.payload.pull_request;
if (!pullRequest) {
console.log('No pull request context available.');
return;
}
const title = context.payload.pull_request.title;
const existingLabels = context.payload.pull_request.labels.map(label => label.name);
for (const prefix of prefixes) {
if (title.startsWith(prefix)) {
const label = prefix.slice(0, -1);
if (!existingLabels.includes(label)) {
console.log(`Applying label: ${label}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: [label]
});
}
break;
}
}
permissions:
contents: read
pull-requests: write
requireIssueOrTask:
name: Require Issue Or Task Association
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Get PR Information
id: get_pr_info
uses: actions/github-script@v6
with:
script: >2-
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const prOwner = pr.data.user.login || "";
const prBody = pr.data.body || "";
core.setOutput("prOwner", prOwner);
core.setOutput("description", prBody);
console.log(`PR Owner: ${prOwner}`);
console.log(`PR Body: ${prBody}`);
- name: Check For Associated Issues Or Tasks
id: check_for_issues_or_tasks
if: ${{ steps.get_pr_info.outputs.prOwner != 'dependabot[bot]' }}
run: >2-
PR_BODY="${{ steps.get_pr_info.outputs.description }}"
echo "::notice::Raw PR Body: $PR_BODY"
if [[ -z "$PR_BODY" ]]; then
echo "Error: PR description does not contain any links to issue(s)/task(s) (e.g., 'closes #123' / 'closes AB#123' / 'fixes #123' / 'fixes AB#123')."
exit 1
fi
PR_BODY=$(echo "$PR_BODY" | tr -s '\r\n' ' ' | tr '\n' ' ' | xargs)
echo "::notice::Normalized PR Body: $PR_BODY"
if echo "$PR_BODY" | grep -Piq "((close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s*(\[#\d+\]|\#\d+)|(?:close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s*(\[AB#\d+\]|AB#\d+))"; then
echo "Valid PR description."
else
echo "Error: PR description does not contain any links to issue(s)/task(s) (e.g., 'closes #123' / 'closes AB#123' / 'fixes #123' / 'fixes AB#123')."
exit 1
fi
shell: bash
permissions:
contents: read
pull-requests: read
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
111 changes: 7 additions & 104 deletions ADotNet.Infrastructure.Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,119 +4,22 @@
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using System.Collections.Generic;
using System.IO;
using ADotNet.Clients;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV3s;
using ISL.ReIdentification.Infrastructure.Services;

namespace ADotNet.Infrastructure.Build
{
internal class Program
{
static void Main(string[] args)
{
string branchName = "main";
var aDotNetClient = new ADotNetClient();
var scriptGenerationService = new ScriptGenerationService();

var githubPipeline = new GithubPipeline
{
Name = "Build",
scriptGenerationService.GenerateBuildScript(
branchName: "main",
projectName: "ADotNet",
dotNetVersion: "9.0.100");

OnEvents = new Events
{
Push = new PushEvent
{
Branches = new string[] { branchName }
},

PullRequest = new PullRequestEvent
{
Types = new string[] { "opened", "synchronize", "reopened", "closed" },
Branches = new string[] { branchName }
}
},

EnvironmentVariables = new Dictionary<string, string>
{
{ "IS_RELEASE_CANDIDATE", EnvironmentVariables.IsGitHubReleaseCandidate() }
},

Jobs = new Dictionary<string, Job>
{
{
"label",
new LabelJobV2(runsOn: BuildMachines.UbuntuLatest)
},
{
"build",
new Job
{
RunsOn = BuildMachines.UbuntuLatest,

Steps = new List<GithubTask>
{
new CheckoutTaskV3
{
Name = "Check out"
},

new SetupDotNetTaskV3
{
Name = "Setup .Net",

With = new TargetDotNetVersionV3
{
DotNetVersion = "7.0.201"
}
},

new RestoreTask
{
Name = "Restore"
},

new DotNetBuildTask
{
Name = "Build"
},

new TestTask
{
Name = "Test"
}
}
}
},
{
"add_tag",
new TagJob(
runsOn: BuildMachines.UbuntuLatest,
dependsOn: "build",
projectRelativePath: "ADotNet/ADotNet.csproj",
githubToken: "${{ secrets.PAT_FOR_TAGGING }}",
branchName: branchName)
},
{
"publish",
new PublishJob(
runsOn: BuildMachines.UbuntuLatest,
dependsOn: "add_tag",
nugetApiKey: "${{ secrets.NUGET_ACCESS }}")
}
}
};

string buildScriptPath = "../../../../.github/workflows/build.yml";
string directoryPath = Path.GetDirectoryName(buildScriptPath);

if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}

aDotNetClient.SerializeAndWriteToFile(githubPipeline, path: buildScriptPath);
scriptGenerationService.GeneratePrLintScript(branchName: "main");
}
}
}
Loading

0 comments on commit c71dc5e

Please sign in to comment.