Skip to content

Commit

Permalink
Merge pull request #19 from rcruzfreelance/users/rcruzfreelance/infra…
Browse files Browse the repository at this point in the history
…-build-project

INFRA: Build Project
  • Loading branch information
glhays authored Jul 28, 2024
2 parents fa7b131 + 046b209 commit 2c49fa9
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 1 deletion.
107 changes: 107 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
name: Build
runs-on: windows-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Setup .Net
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.302
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
add_tag:
name: Tag and Release
runs-on: ubuntu-latest
needs:
- build
if: >-
needs.build.result == 'success' &&
github.event.pull_request.merged &&
github.event.pull_request.base.ref == 'main' &&
startsWith(github.event.pull_request.title, 'RELEASES:') &&
contains(github.event.pull_request.labels.*.name, 'RELEASES')
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT_FOR_TAGGING }}
- name: Configure Git
run: >-
git config user.name "GitHub Action"
git config user.email "action@github.com"
- name: Extract Version
id: extract_version
run: >
# Running on Linux/Unix
sudo apt-get install xmlstarlet
version_number=$(xmlstarlet sel -t -v "//Version" -n STX.EFxceptions.PostgreSQL/STX.EFxceptions.PostgreSQL.csproj)
echo "$version_number"
echo "version_number<<EOF" >> $GITHUB_OUTPUT
echo "$version_number" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
shell: bash
- name: Display Version
run: 'echo "Version number: ${{ steps.extract_version.outputs.version_number }}"'
- name: Extract Package Release Notes
id: extract_package_release_notes
run: >
# Running on Linux/Unix
sudo apt-get install xmlstarlet
package_release_notes=$(xmlstarlet sel -t -v "//PackageReleaseNotes" -n STX.EFxceptions.PostgreSQL/STX.EFxceptions.PostgreSQL.csproj)
echo "$package_release_notes"
echo "package_release_notes<<EOF" >> $GITHUB_OUTPUT
echo "$package_release_notes" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
shell: bash
- name: Display Package Release Notes
run: 'echo "Package Release Notes: ${{ steps.extract_package_release_notes.outputs.package_release_notes }}"'
- name: Create GitHub Tag
run: >-
git tag -a "v${{ steps.extract_version.outputs.version_number }}" -m "Release - v${{ steps.extract_version.outputs.version_number }}"
git push origin --tags
- name: Create GitHub Release
uses: actions/create-release@v1
with:
tag_name: v${{ steps.extract_version.outputs.version_number }}
release_name: Release - v${{ steps.extract_version.outputs.version_number }}
body: >-
## Release - v${{ steps.extract_version.outputs.version_number }}
### Release Notes
${{ steps.extract_package_release_notes.outputs.package_release_notes }}
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_TAGGING }}
17 changes: 17 additions & 0 deletions STX.EFxceptions.PostgreSQL.Infrastructure.Build/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ----------------------------------------------------------------------------------
// Copyright(c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using STX.EFxceptions.PostgreSQL.Infrastructure.Build.Services;

namespace STX.EFxceptions.PostgreSQL.Infrastructure.Build
{
internal class Program
{
static void Main(string[] args)
{
var scriptGenerationService = new ScriptGenerationService();
scriptGenerationService.GenerateBuildScript();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ADotNet" Version="3.0.3" />
<PackageReference Include="STX.EFxceptions.Abstractions" Version="0.1.6" />
<PackageReference Include="STX.EFxceptions.Core" Version="0.1.6" />
<PackageReference Include="STX.EFxceptions.Identity.Core" Version="0.1.6" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// ----------------------------------------------------------------------------------
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

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;

namespace STX.EFxceptions.PostgreSQL.Infrastructure.Build.Services
{
internal class ScriptGenerationService
{
private readonly ADotNetClient adotNetClient;

public ScriptGenerationService() =>
this.adotNetClient = new ADotNetClient();

public void GenerateBuildScript()
{
string branchName = "main";
string projectName = "STX.EFxceptions.PostgreSQL";

var githubPipeline = new GithubPipeline
{
Name = "Build",

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

Jobs = new Dictionary<string, Job>
{
{
"build",
new Job
{
Name = "Build",
RunsOn = BuildMachines.WindowsLatest,

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

new SetupDotNetTaskV3
{
Name = "Setup .Net",

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

new RestoreTask
{
Name = "Restore"
},

new DotNetBuildTask
{
Name = "Build"
},

new TestTask
{
Name = "Test"
}
}
}
},
{
"add_tag",
new TagJob(
runsOn: BuildMachines.UbuntuLatest,
dependsOn: "build",
projectRelativePath: $"{projectName}/{projectName}.csproj",
githubToken: "${{ secrets.PAT_FOR_TAGGING }}",
branchName: branchName)
{
Name = "Tag and Release"
}
},
}
};

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

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

adotNetClient.SerializeAndWriteToFile(
adoPipeline: githubPipeline,
path: buildScriptPath);
}
}
}
6 changes: 5 additions & 1 deletion STX.EFxceptions.PostgreSQL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.EFxceptions.PostgreSQL.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.EFxceptions.Identity.PostgreSQL.Tests.Acceptance", "STX.EFxceptions.Identity.PostgreSQL.Tests.Acceptance\STX.EFxceptions.Identity.PostgreSQL.Tests.Acceptance.csproj", "{2A18E4E6-ED2F-4579-B85A-4282DA9EDDD3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.EFxceptions.PostgreSQL.Tests.Acceptance", "STX.EFxceptions.PostgreSQL.Tests.Acceptance\STX.EFxceptions.PostgreSQL.Tests.Acceptance.csproj", "{E8F4E849-EC1B-49B4-BE19-8C7A7C36C25A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.EFxceptions.PostgreSQL.Infrastructure.Build", "STX.EFxceptions.PostgreSQL.Infrastructure.Build\STX.EFxceptions.PostgreSQL.Infrastructure.Build.csproj", "{068E4391-352C-42B9-8DB6-A928C2B612FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -47,6 +47,10 @@ Global
{2A18E4E6-ED2F-4579-B85A-4282DA9EDDD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A18E4E6-ED2F-4579-B85A-4282DA9EDDD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A18E4E6-ED2F-4579-B85A-4282DA9EDDD3}.Release|Any CPU.Build.0 = Release|Any CPU
{068E4391-352C-42B9-8DB6-A928C2B612FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{068E4391-352C-42B9-8DB6-A928C2B612FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{068E4391-352C-42B9-8DB6-A928C2B612FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{068E4391-352C-42B9-8DB6-A928C2B612FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 2c49fa9

Please sign in to comment.