Skip to content
Open
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
16 changes: 7 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on:
- synchronize
- reopened
- closed
branches:
- main
env:
IS_RELEASE_CANDIDATE: >-
${{
Expand All @@ -31,11 +29,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check Out
uses: actions/checkout@v3
uses: actions/checkout@v5
- name: Setup Dot Net Version
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.302
dotnet-version: 10.x
Comment on lines 33 to +36
- name: Restore
run: dotnet restore
- name: Build
Expand All @@ -58,7 +56,7 @@ jobs:
contains(github.event.pull_request.labels.*.name, 'RELEASES')
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v5
with:
token: ${{ secrets.PAT_FOR_TAGGING }}
- name: Configure Git
Expand Down Expand Up @@ -130,11 +128,11 @@ jobs:
if: needs.add_tag.result == 'success'
steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v5
- name: Setup .Net
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v5
with:
dotnet-version: 7.0.201
dotnet-version: 10.0.100
- name: Restore
run: dotnet restore
- name: Build
Expand Down
97 changes: 97 additions & 0 deletions .github/workflows/prLinter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: PR Linter
on:
pull_request:
types:
- opened
- synchronize
- reopened
- edited
- closed
jobs:
require_issue_or_task:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v5
- name: Get PR Information
id: get_pr_info
uses: actions/github-script@v8
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: ${{ !contains(',,', format(',{0},', steps.get_pr_info.outputs.prOwner)) }}
env:
PR_BODY: ${{ steps.get_pr_info.outputs.description }}
run: >2-
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

NORMALIZED_PR_BODY=$(printf '%s' "$PR_BODY" | tr '\r\n' ' ' | tr -s ' ')

if printf '%s' "$NORMALIZED_PR_BODY" | grep -Piq "(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s*(\[#[0-9]+\]|#[0-9]+|\[AB#[0-9]+\]|AB#[0-9]+)"; 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
set_author_as_pr_assignee:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- name: Set Author As PR Assignee
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: >
const pr = context.payload.pull_request;

if (!pr) {
console.log('No pull request context available.');
return;
}


const author = pr.user.login;

if (author.endsWith('[bot]')) {
console.log(`Skipping bot author: ${author}`);
return;
}


console.log(`Assigning PR to author: ${author}`);


try {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
assignees: [author]
});
} catch (error) {
console.log(`Unable to assign ${author} as PR assignee: ${error.message}`);
}
permissions:
contents: read
issues: write
pull-requests: write
3 changes: 3 additions & 0 deletions NHSISL.LibPostalClient.Infrastructure/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ internal class Program
{
static void Main(string[] args)
{
Environment.CurrentDirectory = AppContext.BaseDirectory;

var scriptGenerationService = new ScriptGenerationService();
scriptGenerationService.GenerateBuildScript();
scriptGenerationService.GeneratePrLinterScript();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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 ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV5s;

namespace NHSISL.LibPostalClient.Infrastructure.Services
{
Expand Down Expand Up @@ -33,8 +33,7 @@

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

Expand All @@ -43,7 +42,6 @@
{ "IS_RELEASE_CANDIDATE", EnvironmentVariables.IsGitHubReleaseCandidate() }
},


Jobs = new Dictionary<string, Job>
{
{
Expand All @@ -54,18 +52,18 @@

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

new SetupDotNetTaskV3
new SetupDotNetTaskV5
{
Name = "Setup Dot Net Version",

With = new TargetDotNetVersionV3
With = new TargetDotNetVersionV5
{
DotNetVersion = "8.0.302"
DotNetVersion = "10.x"
}
},

Expand All @@ -88,7 +86,7 @@
},
{
"add_tag",
new TagJob(
new TagJobV2(
runsOn: BuildMachines.UbuntuLatest,
dependsOn: "build",
projectRelativePath: "NHSISL.LibPostalClient/NHSISL.LibPostalClient.csproj",
Expand All @@ -97,25 +95,66 @@
},
{
"publish",
new PublishJob(
new PublishJobV4(
runsOn: BuildMachines.UbuntuLatest,
dependsOn: "add_tag",
nugetApiKey: "${{ secrets.NUGET_ACCESS }}")
nugetApiKey: "${{ secrets.NUGET_ACCESS }}",
dotNetVersion: "10.0.100")
}
}
};

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

Check warning on line 108 in NHSISL.LibPostalClient.Infrastructure/Services/ScriptGenerationService.cs

View workflow job for this annotation

GitHub Actions / Build

Converting null literal or possible null value to non-nullable type.

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

Check warning on line 112 in NHSISL.LibPostalClient.Infrastructure/Services/ScriptGenerationService.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 'path' in 'DirectoryInfo Directory.CreateDirectory(string path)'.
}

this.adotNetClient.SerializeAndWriteToFile(
githubPipeline,
path: buildScriptPath);
}

public void GeneratePrLinterScript()
{
var githubPipeline = new GithubPipeline
{
Name = "PR Linter",

OnEvents = new Events
{
PullRequest = new PullRequestEvent
{
Types = new string[] { "opened", "synchronize", "reopened", "edited", "closed" }
}
},

Jobs = new Dictionary<string, Job>
{
{
"require_issue_or_task",
new RequireIssueOrTaskJobV2()
},
{
"set_author_as_pr_assignee",
new SetAuthorAsPrAssigneeJobV2(BuildMachines.UbuntuLatest)
}
}
};

string prLinterScriptPath = "../../../../.github/workflows/prLinter.yml";
string directoryPath = Path.GetDirectoryName(prLinterScriptPath);

Check warning on line 148 in NHSISL.LibPostalClient.Infrastructure/Services/ScriptGenerationService.cs

View workflow job for this annotation

GitHub Actions / Build

Converting null literal or possible null value to non-nullable type.

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

Check warning on line 152 in NHSISL.LibPostalClient.Infrastructure/Services/ScriptGenerationService.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 'path' in 'DirectoryInfo Directory.CreateDirectory(string path)'.
}

this.adotNetClient.SerializeAndWriteToFile(
githubPipeline,
path: prLinterScriptPath);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Comment on lines 3 to 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.10" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Tynamix.ObjectFiller" Version="1.5.9" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="xunit.analyzers" Version="1.27.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xeption" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand All @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="CompareNETObjects" Version="4.82.0" />
<PackageReference Include="DeepCloner" Version="0.10.4" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FluentAssertions" Version="[7.2.2]" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
Comment on lines 13 to 17
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.10" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Tynamix.ObjectFiller" Version="1.5.9" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="xunit.analyzers" Version="1.27.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xeption" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion NHSISL.LibPostalNet/NHSISL.LibPostalNet.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Library</OutputType>
Comment on lines 2 to 4
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
Loading