Skip to content

Commit 8e68ee3

Browse files
author
ChristianHaase
committed
feat: enhance gh action workflow
1 parent 79ef031 commit 8e68ee3

File tree

6 files changed

+119
-64
lines changed

6 files changed

+119
-64
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Continout Integration
2+
3+
on:
4+
push:
5+
branches: [ "dev", "master" ]
6+
pull_requests:
7+
branches: [ "dev", "master" ]
8+
9+
env:
10+
CI_BUILD_NUMBER_BASE: ${{ github.run_number }}
11+
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
12+
13+
jobs:
14+
build:
15+
16+
# We need to run on Windows as we're supporting .NET Framework
17+
runs-on: windows-latest
18+
19+
steps:
20+
- uses: actions/checkout@v5
21+
- name: Setup .NET ${{ env.NET_VERSION }}
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: ${{ env.NET_VERSION }}
25+
- name: Compute and set build number
26+
shell: bash
27+
run: |
28+
echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+1000))" >> $GITHUB_ENV
29+
- name: Build & Push
30+
env:
31+
DOTNET_CLI_TELEMTRY_OPTOUT: true
32+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
33+
shell: pwsh
34+
run: |
35+
./Build.ps1

.github/workflows/dotnet.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

Build.ps1

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Write-Output "build: Versions"
2+
3+
dotnet --version
4+
dotnet --list-sdks
5+
6+
Write-Output "build: Build started"
7+
8+
Push-Location $PSScriptRoot
9+
try {
10+
if(Test-Path .\artifacts) {
11+
Write-Output "build: Cleaning ./artifacts"
12+
Remove-Item ./artifacts -Force -Recurse
13+
}
14+
15+
& dotnet restore --no-cache
16+
17+
$dvp = [Xml] (Get-Content .\Directory.Version.props)
18+
$versionPrefix = $dvp.Project.PropertyGroup.VersionPrefix
19+
20+
Write-Output "build: Package base version is $versionPrefix"
21+
22+
$branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH];
23+
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER];
24+
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"]
25+
$commitHash = $(git rev-parse --short HEAD)
26+
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
27+
28+
Write-Output "build: Package version suffix is $suffix"
29+
Write-Output "build: Build version suffix is $buildSuffix"
30+
31+
& dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true
32+
if($LASTEXITCODE -ne 0) { throw "Build failed" }
33+
34+
foreach ($src in Get-ChildItem src/*) {
35+
Push-Location $src
36+
37+
Write-Output "build: Packaging project in $src"
38+
39+
if ($suffix) {
40+
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts --version-suffix=$suffix
41+
} else {
42+
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts
43+
}
44+
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }
45+
46+
Pop-Location
47+
}
48+
49+
foreach ($test in Get-ChildItem tests/) {
50+
Push-Location $test
51+
52+
Write-Output "build: Testing project in $test"
53+
54+
& dotnet test -c Release --no-build --no-restore
55+
if($LASTEXITCODE -ne 0) { throw "Testing failed" }
56+
57+
Pop-Location
58+
}
59+
60+
if ($env:NUGET_API_KEY) {
61+
# GitHub Actions will only supply this to branch builds and not PRs. We publish
62+
# builds from any branch this action targets (i.e. main and dev).
63+
64+
Write-Output "build: Publishing NuGet package"
65+
66+
foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
67+
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg"
68+
if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
69+
}
70+
71+
if (!($suffix)) {
72+
Write-Output "build: Creating release for version $versionPrefix"
73+
74+
iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"
75+
}
76+
}
77+
} finally {
78+
Pop-Location
79+
}

Directory.Version.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<VersionPrefix>0.1.0</VersionPrefix>
4+
</PropertyGroup>
5+
</Project>

src/ByteGuard.FileValidator/ByteGuard.FileValidator.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;net48;net8.0;net9.0;net10.0</TargetFrameworks>
5-
<VersionPrefix>0.1.0</VersionPrefix>
6-
<VersionSuffix>-beta</VersionSuffix>
75
<Authors>ByteGuard Contributors, detilium</Authors>
86
<Description>ByteGuard File Validator is a security-focused .NET library for validating user-supplied files, providing a configurable API to help you enforce safe and consistent file handling across your applications.</Description>
97
<PackageProjectUrl>https://github.com/ByteGuard-HQ/byteguard-file-validator-net</PackageProjectUrl>

0 commit comments

Comments
 (0)