Skip to content

Commit 55d211c

Browse files
nblumhardtEEParker
andauthored
Set up GitHub Actions (#174)
* 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 <[email protected]>
1 parent 87e782c commit 55d211c

File tree

16 files changed

+202
-78
lines changed

16 files changed

+202
-78
lines changed

.github/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# .github/release.yml
2+
3+
changelog:
4+
exclude:
5+
labels:
6+
- ignore-for-release
7+
authors:
8+
- octocat
9+
categories:
10+
- title: Breaking Changes 🛠
11+
labels:
12+
- Semver-Beta
13+
- title: Major Update 🛸
14+
labels:
15+
- Semver-Major
16+
- Feature
17+
- title: New Features 🎉
18+
labels:
19+
- Semver-Minor
20+
- enhancement
21+
- title: Dependencies 👒
22+
labels:
23+
- dependencies
24+
- title: Bugfixes 🐛
25+
labels:
26+
- Semver-Patch
27+
- bug
28+
- title: Other Changes
29+
labels:
30+
- "*"

.github/workflows/ci-release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# If this file is renamed, the incrementing run attempt number will be reset.
2+
3+
name: CI
4+
5+
on:
6+
push:
7+
tags:
8+
- '*'
9+
10+
env:
11+
CI_BUILD_NUMBER: ${{ github.run_number }}
12+
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
13+
CI_COMMIT_TAG: ${{ github.ref_name }}
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Setup
23+
uses: actions/setup-dotnet@v4
24+
with:
25+
dotnet-version: 8.0.x
26+
- name: Build and Publish
27+
env:
28+
DOTNET_CLI_TELEMETRY_OPTOUT: true
29+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
30+
shell: pwsh
31+
run: |
32+
./Build.ps1
33+
- name: Create Release
34+
uses: ncipollo/release-action@v1
35+
with:
36+
artifacts: "artifacts/*.nupkg"
37+
generateReleaseNotes: true

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# If this file is renamed, the incrementing run attempt number will be reset.
2+
3+
name: CI
4+
5+
on:
6+
push:
7+
branches: [ "dev", "master" ]
8+
pull_request:
9+
branches: [ "dev", "master" ]
10+
11+
env:
12+
CI_BUILD_NUMBER: ${{ github.run_number }}
13+
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
14+
#CI_COMMIT_TAG: ""
15+
16+
jobs:
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Setup
24+
uses: actions/setup-dotnet@v4
25+
with:
26+
dotnet-version: 8.0.x
27+
- name: Build and Publish
28+
env:
29+
DOTNET_CLI_TELEMETRY_OPTOUT: true
30+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
31+
shell: pwsh
32+
run: |
33+
./Build.ps1

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,5 @@ _Pvt_Extensions
239239

240240
sample/Sample/out/
241241

242-
.DS_Store
242+
.DS_Store
243+
.idea

Build.ps1

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,80 @@
1-
$ErrorActionPreference = "Stop"
2-
echo "build: Build started"
1+
Write-Output "build: Build started"
32

43
Push-Location $PSScriptRoot
54

5+
Write-Output "build: Tool versions follow"
6+
7+
dotnet --version
8+
dotnet --list-sdks
9+
610
if(Test-Path .\artifacts) {
7-
echo "build: Cleaning .\artifacts"
8-
Remove-Item .\artifacts -Force -Recurse
11+
Write-Output "build: Cleaning ./artifacts"
12+
Remove-Item ./artifacts -Force -Recurse
913
}
1014

11-
& dotnet restore --no-cache
15+
& dotnet restore .\serilog-sinks-splunk.sln --no-cache
16+
17+
$branch = $NULL -ne $env:CI_TARGET_BRANCH ? $env:CI_TARGET_BRANCH : (git symbolic-ref --short -q HEAD)
18+
$revision = $NULL -ne $env:CI_BUILD_NUMBER ? "{0:00000}" -f [Convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10) : "local"
1219

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

19-
echo "build: Package version suffix is $suffix"
20-
echo "build: Build version suffix is $buildSuffix"
24+
Write-Output $brach
25+
Write-Output $revision
26+
Write-Output $suffix
2127

22-
foreach ($src in ls src/*) {
28+
Write-Output "build: Package version suffix is $suffix"
29+
30+
31+
foreach ($src in Get-ChildItem src/*) {
2332
Push-Location $src
2433

25-
echo "build: Packaging project in $src"
34+
Write-Output "build: Packaging project in $src"
2635

27-
& dotnet build -c Release --version-suffix=$buildSuffix
28-
if ($suffix) {
29-
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --version-suffix=$suffix --no-build
36+
if ($prefix) {
37+
# release build
38+
& dotnet pack -c Release -o ../../artifacts --version-prefix=$prefix
39+
} elseif ($suffix) {
40+
# prerelease build
41+
& dotnet pack -c Release -o ../../artifacts --version-suffix=$suffix
3042
} else {
31-
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --no-build
43+
# local build
44+
& dotnet pack -c Release -o ../../artifacts
3245
}
33-
if($LASTEXITCODE -ne 0) { exit 1 }
46+
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }
3447

3548
Pop-Location
3649
}
3750

38-
foreach ($test in ls test/*.Tests) {
51+
Write-Output "build: Checking complete solution builds"
52+
& dotnet build .\serilog-sinks-splunk.sln -c Release
53+
if($LASTEXITCODE -ne 0) { throw "Solution build failed" }
54+
55+
56+
foreach ($test in Get-ChildItem test/*.Tests) {
3957
Push-Location $test
4058

41-
echo "build: Testing project in $test"
59+
Write-Output "build: Testing project in $test"
4260

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

4664
Pop-Location
4765
}
4866

49-
dotnet build -c Release .\sample\Sample\Sample.csproj
50-
5167
Pop-Location
68+
69+
if ($env:NUGET_API_KEY -and ($NULL -ne $suffix -or $NULL -ne $prefix)) {
70+
# GitHub Actions will only supply this to branch builds and not PRs. We publish
71+
# builds from any branch this action targets (i.e. master and dev).
72+
73+
Write-Output "build: Publishing NuGet packages"
74+
75+
foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
76+
Write-Output "build: Publishing $nupkg"
77+
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg" --no-symbols
78+
if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
79+
}
80+
}

Setup.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$RequiredDotnetVersion = $(cat ./global.json | convertfrom-json).sdk.version
4+
5+
New-Item -ItemType Directory -Force "./build/" | Out-Null
6+
7+
Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./build/installcli.ps1"
8+
& ./build/installcli.ps1 -InstallDir "$pwd/.dotnetcli" -NoPath -Version $RequiredDotnetVersion
9+
if ($LASTEXITCODE) { throw ".NET install failed" }

appveyor.yml

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

build.sh

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

docker-compose.dcproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<DockerTargetOS>Linux</DockerTargetOS>
66
<ProjectGuid>1b9defa3-d600-45fa-93a5-79006076fb5c</ProjectGuid>
77
<DockerComposeProjectName>serilogsinkssplunk</DockerComposeProjectName>
8+
<IsPackable>false</IsPackable>
89
</PropertyGroup>
910
<ItemGroup>
1011
<None Include="deploy/**/*" />
@@ -14,4 +15,7 @@
1415
<None Include="docker-compose.yml" />
1516
<None Include=".dockerignore" />
1617
</ItemGroup>
18+
<Target Name="pack">
19+
<Message Text="Not packable. This exists to prevent compile warnings."></Message>
20+
</Target>
1721
</Project>

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.201",
4+
"rollForward": "latestPatch"
5+
}
6+
}

0 commit comments

Comments
 (0)