Skip to content

Commit

Permalink
Set up GitHub Actions (#174)
Browse files Browse the repository at this point in the history
* Enable GitHub Actions

* Main branch is called master in this repo

* Ignore .idea

* No need to offset builds by 200

* work on build for new project format

* add automatic release notes

---------

Co-authored-by: EEParker <EEParker@users.noreply.github.com>
  • Loading branch information
nblumhardt and EEParker committed Apr 3, 2024
1 parent 87e782c commit 55d211c
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 78 deletions.
30 changes: 30 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# .github/release.yml

changelog:
exclude:
labels:
- ignore-for-release
authors:
- octocat
categories:
- title: Breaking Changes 🛠
labels:
- Semver-Beta
- title: Major Update 🛸
labels:
- Semver-Major
- Feature
- title: New Features 🎉
labels:
- Semver-Minor
- enhancement
- title: Dependencies 👒
labels:
- dependencies
- title: Bugfixes 🐛
labels:
- Semver-Patch
- bug
- title: Other Changes
labels:
- "*"
37 changes: 37 additions & 0 deletions .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# If this file is renamed, the incrementing run attempt number will be reset.

name: CI

on:
push:
tags:
- '*'

env:
CI_BUILD_NUMBER: ${{ github.run_number }}
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
CI_COMMIT_TAG: ${{ github.ref_name }}

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build and Publish
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
shell: pwsh
run: |
./Build.ps1
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "artifacts/*.nupkg"
generateReleaseNotes: true
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# If this file is renamed, the incrementing run attempt number will be reset.

name: CI

on:
push:
branches: [ "dev", "master" ]
pull_request:
branches: [ "dev", "master" ]

env:
CI_BUILD_NUMBER: ${{ github.run_number }}
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
#CI_COMMIT_TAG: ""

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build and Publish
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
shell: pwsh
run: |
./Build.ps1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,5 @@ _Pvt_Extensions

sample/Sample/out/

.DS_Store
.DS_Store
.idea
77 changes: 53 additions & 24 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,51 +1,80 @@
$ErrorActionPreference = "Stop"
echo "build: Build started"
Write-Output "build: Build started"

Push-Location $PSScriptRoot

Write-Output "build: Tool versions follow"

dotnet --version
dotnet --list-sdks

if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
Write-Output "build: Cleaning ./artifacts"
Remove-Item ./artifacts -Force -Recurse
}

& dotnet restore --no-cache
& dotnet restore .\serilog-sinks-splunk.sln --no-cache

$branch = $NULL -ne $env:CI_TARGET_BRANCH ? $env:CI_TARGET_BRANCH : (git symbolic-ref --short -q HEAD)
$revision = $NULL -ne $env:CI_BUILD_NUMBER ? "{0:00000}" -f [Convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10) : "local"

$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
$commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
# add a suffix if this is not a tag build
$suffix = $NULL -ne $env:CI_COMMIT_TAG ? "" : "$($branch.Substring(0, [Math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"
$prefix = $NULL -ne $env:CI_COMMIT_TAG ? $env:CI_COMMIT_TAG : $NULL

echo "build: Package version suffix is $suffix"
echo "build: Build version suffix is $buildSuffix"
Write-Output $brach
Write-Output $revision
Write-Output $suffix

foreach ($src in ls src/*) {
Write-Output "build: Package version suffix is $suffix"


foreach ($src in Get-ChildItem src/*) {
Push-Location $src

echo "build: Packaging project in $src"
Write-Output "build: Packaging project in $src"

& dotnet build -c Release --version-suffix=$buildSuffix
if ($suffix) {
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --version-suffix=$suffix --no-build
if ($prefix) {
# release build
& dotnet pack -c Release -o ../../artifacts --version-prefix=$prefix
} elseif ($suffix) {
# prerelease build
& dotnet pack -c Release -o ../../artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --no-build
# local build
& dotnet pack -c Release -o ../../artifacts
}
if($LASTEXITCODE -ne 0) { exit 1 }
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }

Pop-Location
}

foreach ($test in ls test/*.Tests) {
Write-Output "build: Checking complete solution builds"
& dotnet build .\serilog-sinks-splunk.sln -c Release
if($LASTEXITCODE -ne 0) { throw "Solution build failed" }


foreach ($test in Get-ChildItem test/*.Tests) {
Push-Location $test

echo "build: Testing project in $test"
Write-Output "build: Testing project in $test"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }
if($LASTEXITCODE -ne 0) { throw "Testing failed" }

Pop-Location
}

dotnet build -c Release .\sample\Sample\Sample.csproj

Pop-Location

if ($env:NUGET_API_KEY -and ($NULL -ne $suffix -or $NULL -ne $prefix)) {
# GitHub Actions will only supply this to branch builds and not PRs. We publish
# builds from any branch this action targets (i.e. master and dev).

Write-Output "build: Publishing NuGet packages"

foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
Write-Output "build: Publishing $nupkg"
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg" --no-symbols
if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
}
}
9 changes: 9 additions & 0 deletions Setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$ErrorActionPreference = "Stop"

$RequiredDotnetVersion = $(cat ./global.json | convertfrom-json).sdk.version

New-Item -ItemType Directory -Force "./build/" | Out-Null

Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./build/installcli.ps1"
& ./build/installcli.ps1 -InstallDir "$pwd/.dotnetcli" -NoPath -Version $RequiredDotnetVersion
if ($LASTEXITCODE) { throw ".NET install failed" }
33 changes: 0 additions & 33 deletions appveyor.yml

This file was deleted.

16 changes: 0 additions & 16 deletions build.sh

This file was deleted.

4 changes: 4 additions & 0 deletions docker-compose.dcproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<DockerTargetOS>Linux</DockerTargetOS>
<ProjectGuid>1b9defa3-d600-45fa-93a5-79006076fb5c</ProjectGuid>
<DockerComposeProjectName>serilogsinkssplunk</DockerComposeProjectName>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<None Include="deploy/**/*" />
Expand All @@ -14,4 +15,7 @@
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</ItemGroup>
<Target Name="pack">
<Message Text="Not packable. This exists to prevent compile warnings."></Message>
</Target>
</Project>
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.201",
"rollForward": "latestPatch"
}
}
1 change: 1 addition & 0 deletions sample/Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions serilog-sinks-splunk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{B9B13339-749C-4098-8845-780ED4FA488A}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
build.sh = build.sh
CHANGES.md = CHANGES.md
README.md = README.md
assets\Serilog.snk = assets\Serilog.snk
global.json = global.json
Setup.ps1 = Setup.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{1C75E4A9-4CB1-497C-AD17-B438882051A1}"
Expand All @@ -38,6 +37,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "splunk", "splunk", "{21EEF5
sample\splunk\Dockerfile = sample\splunk\Dockerfile
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{A9F9CB1C-35C7-4878-97B7-673F5D4BC64A}"
ProjectSection(SolutionItems) = preProject
.github\workflows\ci.yml = .github\workflows\ci.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
6 changes: 6 additions & 0 deletions src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<RootNamespace>Serilog</RootNamespace>
<LangVersion>latest</LangVersion>
<IsPackable>true</IsPackable>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="4.0.1" />
Expand Down
6 changes: 6 additions & 0 deletions src/Serilog.Sinks.TCP/Serilog.Sinks.Splunk.TCP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<SignAssembly>true</SignAssembly>
<IsPackable>true</IsPackable>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.7.0" />
<PackageReference Include="Splunk.Logging.Common.Core" Version="1.0.0" />
Expand Down
6 changes: 6 additions & 0 deletions src/Serilog.Sinks.UDP/Serilog.Sinks.Splunk.UDP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<SignAssembly>true</SignAssembly>
<IsPackable>true</IsPackable>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.7.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>Serilog.Sinks.Splunk.Tests</AssemblyName>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down

0 comments on commit 55d211c

Please sign in to comment.