-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from rcruzfreelance/users/rcruzfreelance/infra…
…-build-project INFRA: Build Project
- Loading branch information
Showing
5 changed files
with
255 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "[email protected]" | ||
- 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
17
STX.EFxceptions.PostgreSQL.Infrastructure.Build/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ns.PostgreSQL.Infrastructure.Build/STX.EFxceptions.PostgreSQL.Infrastructure.Build.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
107 changes: 107 additions & 0 deletions
107
STX.EFxceptions.PostgreSQL.Infrastructure.Build/Services/ScriptGenerationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters