diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c6442c32 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +# If this file is renamed, the incrementing run attempt number will be reset. + +name: CI + +on: + push: + branches: [ "dev", "main" ] + pull_request: + branches: [ "dev", "main" ] + +env: + CI_BUILD_NUMBER_BASE: ${{ github.run_number }} + CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }} + +jobs: + build-windows: + name: Build (Windows) + runs-on: windows-latest + + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Setup + shell: pwsh + run: ./build/Setup.Windows.ps1 + - name: Compute build number + shell: bash + run: | + echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+2300))" >> $GITHUB_ENV + + - name: Build and Publish + env: + DOTNET_CLI_TELEMETRY_OPTOUT: true + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: pwsh + run: | + ./build/Build.Windows.ps1 + + build-linux: + name: Build (Linux) + runs-on: ubuntu-24.04 + + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Setup + shell: bash + run: ./build/setup.linux.sh + - name: Compute build number + shell: bash + run: | + echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+2300))" >> $GITHUB_ENV + + - name: Build and Publish + env: + DOTNET_CLI_TELEMETRY_OPTOUT: true + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: pwsh + run: | + ./build/Build.Linux.ps1 diff --git a/Build.Common.ps1 b/Build.Common.ps1 deleted file mode 100644 index 87f2d499..00000000 --- a/Build.Common.ps1 +++ /dev/null @@ -1,12 +0,0 @@ -function Get-SemVer($shortver) -{ - # This script originally (c) 2016 Serilog Contributors - license Apache 2.0 - $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; - $suffix = @{ $true = ""; $false = ($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '[\/\+]','-').Trim("-")}[$branch -eq "main"] - - if ($suffix) { - $shortver + "-" + $suffix - } else { - $shortver - } -} diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index c0f95e9e..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,56 +0,0 @@ -version: 2025.1.{build} -skip_tags: true -image: -- Visual Studio 2022 -- Ubuntu2004 -environment: - DOCKER_TOKEN: - secure: QKr2YEuliXdFKe3jN7w97w== - DOCKER_USER: - 'datalustbuild' -test: off -artifacts: -- path: artifacts/seqcli-*.zip -- path: artifacts/seqcli-*.tar.gz -- path: artifacts/seqcli.*.nupkg -- path: artifacts/seqcli-*.md - -for: -- - matrix: - only: - - image: Visual Studio 2022 - - install: - - pwsh: ./Setup.ps1 - - build_script: - - pwsh: ./Build.ps1 - - deploy: - - - provider: NuGet - api_key: - secure: 8gHaCWoeZrbMxRKH09E/cwYxYVvkiJ9P/GXC8H4oNxoYZ2pQgeWzBGkOT9noYrBU - skip_symbols: true - artifact: /seqcli\..*\.nupkg/ - on: - branch: main - - - provider: GitHub - auth_token: - secure: Bo3ypKpKFxinjR9ShkNekNvkob2iklHJU+UlYyfHtcFFIAa58SV2TkEd0xWxz633 - artifact: /seqcli-.*\.(nupkg|zip|tar\.gz)/ - tag: v$(appveyor_build_version) - on: - branch: main -- - matrix: - only: - - image: Ubuntu2004 - - install: - - pwsh: ./setup.sh - - build_script: - - pwsh: $env:PATH = "$env:HOME/.dotnetcli:$env:PATH"; ./Build.Docker.ps1 diff --git a/build/Build.Common.ps1 b/build/Build.Common.ps1 new file mode 100644 index 00000000..0fba7f31 --- /dev/null +++ b/build/Build.Common.ps1 @@ -0,0 +1,14 @@ +function Get-SemVer() +{ + $branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH]; + $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER] + $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"] + $commitHash = $(git rev-parse --short HEAD) + $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] + + if ($suffix) { + $shortver + "-" + $suffix + } else { + $shortver + } +} diff --git a/Build.Docker.ps1 b/build/Build.Linux.ps1 similarity index 79% rename from Build.Docker.ps1 rename to build/Build.Linux.ps1 index e68c4381..9516d80e 100644 --- a/Build.Docker.ps1 +++ b/build/Build.Linux.ps1 @@ -2,10 +2,9 @@ Push-Location $PSScriptRoot . ./Build.Common.ps1 -$IsCIBuild = $null -ne $env:APPVEYOR_BUILD_NUMBER -$IsPublishedBuild = ($env:APPVEYOR_REPO_BRANCH -eq "main" -or $env:APPVEYOR_REPO_BRANCH -eq "dev") -and $null -eq $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH +$IsPublishedBuild = $null -ne $env:DOCKER_TOKEN -$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL]) +$version = Get-SemVer() $framework = "net9.0" $image = "datalust/seqcli" $archs = @( @@ -42,14 +41,19 @@ function Build-DockerImage($arch) if($LASTEXITCODE -ne 0) { exit 3 } } -function Publish-DockerImage($arch) +function Login-ToDocker() { $ErrorActionPreference = "SilentlyContinue" - if ($IsCIBuild) { - Write-Output "$env:DOCKER_TOKEN" | docker login -u $env:DOCKER_USER --password-stdin - if ($LASTEXITCODE) { exit 3 } - } + Write-Output "$env:DOCKER_TOKEN" | docker login -u $env:DOCKER_USER --password-stdin + if ($LASTEXITCODE) { exit 3 } + + $ErrorActionPreference = "Stop" +} + +function Publish-DockerImage($arch) +{ + $ErrorActionPreference = "SilentlyContinue" & docker push "$image-ci:$version-$($arch.rid)" if($LASTEXITCODE -ne 0) { exit 3 } @@ -76,13 +80,15 @@ Execute-Tests foreach ($arch in $archs) { Build-DockerImage($arch) +} + +if ($IsPublishedBuild) { + Login-ToDocker() - if ($IsPublishedBuild) { + foreach ($arch in $archs) { Publish-DockerImage($arch) } -} -if ($IsPublishedBuild) { Publish-DockerManifest($archs) } diff --git a/Build.ps1 b/build/Build.Windows.ps1 similarity index 96% rename from Build.ps1 rename to build/Build.Windows.ps1 index caf8ff60..309a54a7 100644 --- a/Build.ps1 +++ b/build/Build.Windows.ps1 @@ -4,7 +4,7 @@ Push-Location $PSScriptRoot $ErrorActionPreference = 'Stop' -$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL]) +$version = Get-SemVer() $framework = 'net9.0' $windowsTfmSuffix = '-windows' diff --git a/Setup.ps1 b/build/Setup.Windows.ps1 similarity index 100% rename from Setup.ps1 rename to build/Setup.Windows.ps1 diff --git a/setup.sh b/build/setup.linux.sh similarity index 100% rename from setup.sh rename to build/setup.linux.sh diff --git a/docker-publish.ps1 b/docker-publish.ps1 deleted file mode 100644 index 99399c59..00000000 --- a/docker-publish.ps1 +++ /dev/null @@ -1,59 +0,0 @@ -param ( - [Parameter(Mandatory=$True)] - [string] $version -) - -$ErrorActionPreference = "Stop" - -$versionParts = $version.Split('.') - -$major = $versionParts[0] -$minor = $versionParts[1] -$isPre = $version.endswith("pre") - -$image = "datalust/seqcli" -$archs = @("x64", "arm64") -$publishImages = @() - -foreach ($arch in $archs) { - $ciImage = "$image-ci:$version-$arch" - $publishImage = "$($image):$version-$arch"; - - docker pull $ciImage - if ($LASTEXITCODE) { exit 1 } - - docker tag $ciImage $publishImage - if ($LASTEXITCODE) { exit 1 } - - docker push $publishImage - if ($LASTEXITCODE) { exit 1 } - - $publishImages += $publishImage -} - -$publishManifest = "$($image):$version" - -$pushTags = @($publishManifest) - -if ($isPre -eq $True) { - $pushTags += "$($image):preview" -} else { - $pushTags += "$($image):$major", "$($image):$major.$minor", "$($image):latest" -} - -$choices = "&Yes", "&No" -$decision = $Host.UI.PromptForChoice("Publishing ($publishManifest) as ($pushTags)", "Does this look right?", $choices, 1) -if ($decision -eq 0) { - foreach ($pushTag in $pushTags) { - Write-Host "Publishing $pushTag" - - echo "creating manifest $pushTag from $publishImages" - iex "docker manifest create $pushTag $publishImages" - if ($LASTEXITCODE) { exit 1 } - - docker manifest push $pushTag - if ($LASTEXITCODE) { exit 1 } - } -} else { - Write-Host "Cancelled" -}