Skip to content

Commit 62bb43a

Browse files
authored
Merge pull request #390 from datalust/ci/gh-actions
Port CI to GitHub Actions
2 parents 16a906f + f747477 commit 62bb43a

File tree

11 files changed

+135
-177
lines changed

11 files changed

+135
-177
lines changed

.github/workflows/ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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", "main" ]
8+
pull_request:
9+
branches: [ "dev", "main" ]
10+
11+
env:
12+
CI_BUILD_NUMBER_BASE: ${{ github.run_number }}
13+
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
14+
CI_PUBLISH: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
15+
16+
jobs:
17+
build-windows:
18+
name: Build (Windows)
19+
runs-on: windows-latest
20+
21+
permissions:
22+
contents: write
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Setup
27+
uses: actions/setup-dotnet@v4
28+
with:
29+
dotnet-version: 9.0.x
30+
- name: Build and Publish
31+
env:
32+
DOTNET_CLI_TELEMETRY_OPTOUT: true
33+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
shell: pwsh
36+
run: |
37+
./build/Build.Windows.ps1
38+
39+
build-linux:
40+
name: Build (Linux)
41+
runs-on: ubuntu-22.04
42+
43+
permissions:
44+
contents: write
45+
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Setup
49+
uses: actions/setup-dotnet@v4
50+
with:
51+
dotnet-version: 9.0.x
52+
- name: Configure Docker
53+
run: |
54+
docker run --privileged --rm linuxkit/binfmt:bebbae0c1100ebf7bf2ad4dfb9dfd719cf0ef132
55+
sudo service docker restart
56+
- name: Build and Publish
57+
env:
58+
DOTNET_CLI_TELEMETRY_OPTOUT: true
59+
DOCKER_USER: ${{ secrets.DOCKER_USER }}
60+
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
61+
shell: pwsh
62+
run: |
63+
./build/Build.Linux.ps1

Build.Common.ps1

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

Setup.ps1

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

appveyor.yml

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

baseversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025.1

build/Build.Common.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function Get-SemVer()
2+
{
3+
$branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH];
4+
$revision = @{ $true = "{0:00000}" -f $([convert]::ToInt32($env:CI_BUILD_NUMBER_BASE, 10) + 2300); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER_BASE]
5+
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"]
6+
$commitHash = $(git rev-parse --short HEAD)
7+
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
8+
9+
$base = $(Get-Content ./baseversion).Trim()
10+
11+
if ($suffix) {
12+
$base + "." + $revision + "-" + $suffix
13+
} else {
14+
$revision
15+
}
16+
}
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
Push-Location $PSScriptRoot
1+
Push-Location $PSScriptRoot/../
22

3-
. ./Build.Common.ps1
3+
. ./build/Build.Common.ps1
44

5-
$IsCIBuild = $null -ne $env:APPVEYOR_BUILD_NUMBER
6-
$IsPublishedBuild = ($env:APPVEYOR_REPO_BRANCH -eq "main" -or $env:APPVEYOR_REPO_BRANCH -eq "dev") -and $null -eq $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH
5+
$version = Get-SemVer
76

8-
$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL])
97
$framework = "net9.0"
108
$image = "datalust/seqcli"
119
$archs = @(
1210
@{ rid = "x64"; platform = "linux/amd64" },
1311
@{ rid = "arm64"; platform = "linux/arm64/v8" }
1412
)
1513

16-
$endToEndVersion = "preview"
17-
1814
function Execute-Tests
1915
{
2016
& dotnet test ./test/SeqCli.Tests/SeqCli.Tests.csproj -c Release -f $framework /p:Configuration=Release /p:VersionPrefix=$version
2117
if ($LASTEXITCODE -ne 0) { exit 1 }
2218

2319
cd ./test/SeqCli.EndToEnd/
24-
docker pull "datalust/seq:$endToEndVersion"
25-
docker tag "datalust/seq:$endToEndVersion" datalust/seq:latest
20+
docker pull datalust/seq:latest
2621
& dotnet run -f $framework -- --docker-server
2722
if ($LASTEXITCODE -ne 0)
2823
{
@@ -35,21 +30,27 @@ function Execute-Tests
3530
function Build-DockerImage($arch)
3631
{
3732
$rid = "linux-$($arch.rid)"
33+
3834
& dotnet publish src/SeqCli/SeqCli.csproj -c Release -f $framework -r $rid --self-contained /p:VersionPrefix=$version /p:PublishSingleFile=true
3935
if($LASTEXITCODE -ne 0) { exit 2 }
4036

4137
& docker buildx build --platform "$($arch.platform)" -f dockerfiles/seqcli/$rid.Dockerfile -t "$image-ci:$version-$($arch.rid)" .
4238
if($LASTEXITCODE -ne 0) { exit 3 }
4339
}
4440

45-
function Publish-DockerImage($arch)
41+
function Login-ToDocker()
4642
{
4743
$ErrorActionPreference = "SilentlyContinue"
4844

49-
if ($IsCIBuild) {
50-
Write-Output "$env:DOCKER_TOKEN" | docker login -u $env:DOCKER_USER --password-stdin
51-
if ($LASTEXITCODE) { exit 3 }
52-
}
45+
Write-Output "$env:DOCKER_TOKEN" | docker login -u $env:DOCKER_USER --password-stdin
46+
if ($LASTEXITCODE) { exit 3 }
47+
48+
$ErrorActionPreference = "Stop"
49+
}
50+
51+
function Publish-DockerImage($arch)
52+
{
53+
$ErrorActionPreference = "SilentlyContinue"
5354

5455
& docker push "$image-ci:$version-$($arch.rid)"
5556
if($LASTEXITCODE -ne 0) { exit 3 }
@@ -76,13 +77,15 @@ Execute-Tests
7677

7778
foreach ($arch in $archs) {
7879
Build-DockerImage($arch)
80+
}
7981

80-
if ($IsPublishedBuild) {
82+
if ("$($env:DOCKER_TOKEN)" -ne "") {
83+
Login-ToDocker
84+
85+
foreach ($arch in $archs) {
8186
Publish-DockerImage($arch)
8287
}
83-
}
8488

85-
if ($IsPublishedBuild) {
8689
Publish-DockerManifest($archs)
8790
}
8891

Build.ps1 renamed to build/Build.Windows.ps1

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
Push-Location $PSScriptRoot
1+
Push-Location $PSScriptRoot/../
22

3-
. ./Build.Common.ps1
3+
. ./build/Build.Common.ps1
44

55
$ErrorActionPreference = 'Stop'
66

7-
$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL])
7+
$version = Get-SemVer
8+
89
$framework = 'net9.0'
910
$windowsTfmSuffix = '-windows'
1011

@@ -78,6 +79,26 @@ function Publish-Docs($version)
7879
if($LASTEXITCODE -ne 0) { throw "Build failed" }
7980
}
8081

82+
function Upload-NugetPackages
83+
{
84+
# GitHub Actions will only supply this to branch builds and not PRs. We publish
85+
# builds from any branch this action targets (i.e. main and dev).
86+
87+
Write-Output "build: Publishing NuGet packages"
88+
89+
foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
90+
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg"
91+
if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
92+
}
93+
}
94+
95+
function Upload-GitHubRelease($version)
96+
{
97+
Write-Output "build: Creating release for version $version"
98+
99+
iex "gh release create v$version --title v$version --generate-notes $(get-item ./artifacts/*)"
100+
}
101+
81102
function Remove-GlobalJson
82103
{
83104
if(Test-Path ./global.json) { rm ./global.json }
@@ -104,6 +125,16 @@ Publish-Archives($version)
104125
Publish-DotNetTool($version)
105126
Execute-Tests($version)
106127
Publish-Docs($version)
128+
129+
if ("$($env:NUGET_API_KEY)" -ne "")
130+
{
131+
Upload-NugetPackages
132+
}
133+
134+
if ($env:CI_PUBLISH -eq "True") {
135+
Upload-GitHubRelease($version)
136+
}
137+
107138
Remove-GlobalJson
108139

109140
Pop-Location

docker-publish.ps1

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

setup.sh

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

0 commit comments

Comments
 (0)