Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# If this file is renamed, the incrementing run attempt number will be reset. If the workflow's
# `name` changes, the `workflow_run` trigger in publish.yml must be updated.
# Builds, tests and packages (on Windows and Linux) the project on merges or PRs to 'dev' or 'main'.
# Saves artifacts (from Windows job) on merges to main, or when the workflow is manually triggered with 'Publish a GitHub release and packages'.
# The Linux job publishes a docker image on every build.

name: CI

Expand All @@ -11,7 +12,7 @@ on:
workflow_dispatch:
inputs:
publish:
description: 'Publish a GitHub release'
description: 'Publish a GitHub release and packages'
type: boolean
required: true
default: true
Expand All @@ -26,35 +27,36 @@ jobs:
name: Build (Windows)
runs-on: windows-latest

# A manual run with the `publish` input unchecked does nothing.
if: github.event_name != 'workflow_dispatch' || inputs.publish

permissions:
# Required for creating GitHub releases.
contents: write
contents: read

steps:
- uses: actions/checkout@v6
- name: Setup
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Build and Publish
- name: Build and Package
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
./build/Build.Windows.ps1
- name: Upload packages
# Consumed by the publish-nuget job in publish.yml
if: github.event_name != 'pull_request'
# Consumed by the publish-nuget and publish-github jobs in publish.yml
if: env.CI_PUBLISH == 'true'
uses: actions/upload-artifact@v7
with:
name: packages
path: artifacts/*.nupkg
if-no-files-found: error
retention-days: 1
- name: Upload archives
# Consumed by the publish-npm job in publish.yml
if: github.event_name != 'pull_request'
# Consumed by the publish-npm and publish-github jobs in publish.yml
if: env.CI_PUBLISH == 'true'
uses: actions/upload-artifact@v7
with:
name: archives
Expand All @@ -63,13 +65,25 @@ jobs:
artifacts/seqcli-*-*.tar.gz
if-no-files-found: error
retention-days: 1
- name: Upload docs
# Consumed by the publish-github job in publish.yml
if: env.CI_PUBLISH == 'true'
uses: actions/upload-artifact@v7
with:
name: docs
path: artifacts/seqcli-*.md
if-no-files-found: error
retention-days: 1

build-linux:
name: Build (Linux)
runs-on: ubuntu-24.04

# A manual run with the `publish` input unchecked does nothing.
if: github.event_name != 'workflow_dispatch' || inputs.publish

permissions:
contents: write
contents: read

steps:
- uses: actions/checkout@v6
Expand Down
101 changes: 89 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Publishes the packages built by a successful CI run to NuGet.org and npm
# Publishes the packages built by a successful CI run: creates a draft GitHub release, pushes the
# packages to NuGet.org and npm, then publishes the release once both registries have succeeded.

name: Publish

Expand All @@ -16,14 +17,74 @@ env:
CI_TARGET_BRANCH: ${{ github.event.workflow_run.head_branch }}

jobs:
publish-nuget:
name: Publish (NuGet)
draft-release:
name: Draft GitHub release
runs-on: ubuntu-24.04

if: >-
github.event.workflow_run.conclusion == 'success' &&
(github.event.workflow_run.event == 'push' || github.event.workflow_run.event == 'workflow_dispatch') &&
github.event.workflow_run.head_repository.full_name == github.repository
github.event.workflow_run.head_repository.full_name == github.repository &&
(github.event.workflow_run.event == 'workflow_dispatch' ||
(github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main'))

permissions:
# Required to download artifacts from the triggering CI run.
actions: read
# Required to create the release.
contents: write

outputs:
tag: ${{ steps.draft.outputs.tag }}

steps:
# Build.Common.ps1 and baseversion, at the commit CI built, to reproduce its version.
- uses: actions/checkout@v6
with:
ref: ${{ github.event.workflow_run.head_sha }}
persist-credentials: false
- name: Download release assets
# Every artifact of the CI run: `packages`, `archives` and `docs`.
uses: actions/download-artifact@v8
with:
path: release-assets
merge-multiple: true
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Create draft release
# The tag isn't created until the release is published, at the commit given by --target.
id: draft
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
shell: pwsh
run: |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably go in a script file

. ./build/Build.Common.ps1
$tag = "v$(Get-SemVer)"
"tag=$tag" >> $env:GITHUB_OUTPUT

$assets = @(Get-ChildItem ./release-assets -File | ForEach-Object { $_.FullName })
if ($assets.Count -eq 0) { throw "No release assets found in ./release-assets" }

$isDraft = gh release view $tag --repo $env:GITHUB_REPOSITORY --json isDraft --jq .isDraft 2>$null
if ($LASTEXITCODE -eq 0) {
# A draft left by an earlier attempt of this run; refresh its assets.
if ($isDraft -ne 'true') { throw "Release $tag has already been published" }
Write-Host "Updating existing draft release $tag"
& gh release upload $tag --repo $env:GITHUB_REPOSITORY --clobber @assets
if ($LASTEXITCODE -ne 0) { throw "Uploading release assets failed" }
} else {
Write-Host "Creating draft release $tag"
$arguments = @('release', 'create', $tag, '--draft', '--title', $tag, '--target', $env:HEAD_SHA, '--generate-notes', '--repo', $env:GITHUB_REPOSITORY)
if ($env:CI_TARGET_BRANCH -ne 'main') { $arguments += '--prerelease' }
& gh @arguments @assets
if ($LASTEXITCODE -ne 0) { throw "Creating the draft release failed" }
}

publish-nuget:
name: Publish (NuGet)
runs-on: ubuntu-24.04

needs: draft-release

permissions:
# Required to download artifacts from the triggering CI run.
Expand Down Expand Up @@ -57,18 +118,15 @@ jobs:
$packages = @(Get-ChildItem ./packages/*.nupkg)
if ($packages.Count -eq 0) { throw "No packages found in ./packages" }
foreach ($nupkg in $packages) {
dotnet nuget push "$nupkg" --api-key "$env:NUGET_API_KEY" --source https://api.nuget.org/v3/index.json
dotnet nuget push "$nupkg" --api-key "$env:NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
if ($LASTEXITCODE -ne 0) { throw "Publishing failed" }
}

publish-npm:
name: Publish (npm)
runs-on: ubuntu-24.04

if: >-
github.event.workflow_run.conclusion == 'success' &&
(github.event.workflow_run.event == 'push' || github.event.workflow_run.event == 'workflow_dispatch') &&
github.event.workflow_run.head_repository.full_name == github.repository
needs: draft-release

permissions:
# Required to download artifacts from the triggering CI run.
Expand All @@ -78,8 +136,8 @@ jobs:
id-token: write

steps:
# Build.Npm.ps1 and the package templates under ./npm, at the commit CI built. The checks
# above guarantee this is a commit pushed to this repository, not pull request code.
# Build.Npm.ps1 and the package templates under ./npm, at the commit CI built. The checks on
# the draft-release job guarantee this is a commit pushed to this repository, not pull request code.
- uses: actions/checkout@v6
with:
ref: ${{ github.event.workflow_run.head_sha }}
Expand All @@ -104,3 +162,22 @@ jobs:
shell: pwsh
run: |
./build/Build.Npm.ps1 -ArchiveDir ./npm-archives

publish-github:
name: Publish GitHub release
runs-on: ubuntu-24.04

# Only publish the release once the packages are on NuGet.org and npm.
needs: [ draft-release, publish-nuget, publish-npm ]

permissions:
# Required to publish the release and create its tag.
contents: write

steps:
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.draft-release.outputs.tag }}
run: |
gh release edit "$TAG" --draft=false --repo "$GITHUB_REPOSITORY"
24 changes: 4 additions & 20 deletions build/Build.Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function Create-ArtifactDir
mkdir ./artifacts
}

function Publish-Archives($version)
function Create-Archives($version)
{
$rids = $([xml](Get-Content .\src\SeqCli\SeqCli.csproj)).Project.PropertyGroup.RuntimeIdentifiers.Split(';')
foreach ($rid in $rids) {
Expand Down Expand Up @@ -78,7 +78,7 @@ function Publish-Archives($version)
}
}

function Publish-DotNetTool($version)
function Package-DotNetTool($version)
{
Write-Output "Building dotnet tool"

Expand All @@ -95,18 +95,6 @@ function Publish-Docs($version)
if($LASTEXITCODE -ne 0) { throw "Build failed" }
}

function Upload-GitHubRelease($version)
{
Write-Output "Creating release for version $version"

$prerelease = "";
if ($env:CI_TARGET_BRANCH -ne "main") {
$prerelease = "--prerelease ";
}

iex "gh release create v$version --title v$version $prerelease--generate-notes $(get-item ./artifacts/*)"
}

function Remove-GlobalJson
{
if(Test-Path ./global.json) { rm ./global.json }
Expand All @@ -127,15 +115,11 @@ Clean-Output
Create-ArtifactDir
Create-GlobalJson
Restore-Packages
Publish-Archives($version)
Publish-DotNetTool($version)
Create-Archives($version)
Package-DotNetTool($version)
Execute-Tests($version)
Publish-Docs($version)

if ($env:CI_PUBLISH -eq "True") {
Upload-GitHubRelease($version)
}

Remove-GlobalJson

Pop-Location
25 changes: 15 additions & 10 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This directory holds the PowerShell scripts that build, test, package, and publi
| Script | Runs on | Produces |
|---|---|---|
| `Build.Common.ps1` | (dot-sourced by the others) | Version number helpers |
| `Build.Windows.ps1` | Windows | Release archives for every platform, the `seqcli` .NET tool package, generated docs, a GitHub release |
| `Build.Windows.ps1` | Windows | Release archives for every platform, the `seqcli` .NET tool package, generated docs |
| `Build.Linux.ps1` | Linux | `datalust/seqcli` Docker images for `linux/amd64` and `linux/arm64` |
| `Build.Npm.ps1` | Linux (any OS locally) | `@datalust/seqcli` and `@datalust/seqcli-<rid>` npm packages |

Expand All @@ -20,7 +20,7 @@ Every artifact from one CI run shares a single version, computed by `Get-SemVer`
```

* `<baseversion>` is read from [`baseversion`](../baseversion) in the repository root (e.g. `2026.1`). Bump it there when starting a new release line.
* `<build number>` is `CI_BUILD_NUMBER_BASE + 2300`, zero-padded to five digits (e.g. `02616`). `CI_BUILD_NUMBER_BASE` is the GitHub Actions `run_number`; the fixed offset keeps build numbers increasing across the move from the previous CI system. Note the comment at the top of `ci.yml`: renaming the workflow file resets `run_number`, which would produce lower version numbers than already-published releases. Locally, where the variable is unset, the build number is the literal string `local`.
* `<build number>` is `CI_BUILD_NUMBER_BASE + 2300`, zero-padded to five digits (e.g. `02616`). `CI_BUILD_NUMBER_BASE` is the GitHub Actions `run_number`; the fixed offset keeps build numbers increasing across the move from the previous CI system. Renaming the workflow file resets `run_number`, which would produce lower version numbers than already-published releases. Locally, where the variable is unset, the build number is the literal string `local`.
* The prerelease suffix is added for every branch except `main`. It is the first ten characters of the branch name, stripped of anything other than letters, digits and hyphens, followed by the build number. A `dev` build is therefore `2026.1.02700-dev-02700`; a `main` build is `2026.1.02616`.

`CI_TARGET_BRANCH` overrides the branch detected from git. In CI it is set from `github.head_ref` (for pull requests) or `github.ref_name`.
Expand All @@ -33,7 +33,7 @@ npm enforces strict semver, which forbids leading zeros in numeric components, s

The workflow runs on pushes and pull requests to `dev` and `main`, and can be triggered manually with `workflow_dispatch`. Two jobs run:

1. **Build (Windows)** runs `Build.Windows.ps1`. On non-PR builds, it then uploads the tool package as a workflow artifact named `packages`, and the release archives as one named `archives`, for the publish workflow to consume.
1. **Build (Windows)** runs `Build.Windows.ps1`. When `CI_PUBLISH` is set (pushes to `main`, and manual runs with the `publish` input checked), it then uploads the tool package as a workflow artifact named `packages`, the release archives as one named `archives`, and the markdown command reference as one named `docs`, for the publish workflow to consume.
2. **Build (Linux)** runs `Build.Linux.ps1`, after configuring `binfmt` so that ARM64 images can be built on the x64 runner. It runs in parallel with the Windows job.

Environment variables control what gets published:
Expand All @@ -42,19 +42,22 @@ Environment variables control what gets published:
|---|---|---|
| `CI_BUILD_NUMBER_BASE` | `github.run_number` | Build number component of the version |
| `CI_TARGET_BRANCH` | `github.head_ref` or `github.ref_name` | Branch component of the version |
| `CI_PUBLISH` | `True` for pushes to `main`, or when the manual `publish` input is set | Whether `Build.Windows.ps1` creates a GitHub release |
| `GH_TOKEN` | `secrets.GITHUB_TOKEN` | Used by `gh release create` |
| `CI_PUBLISH` | `True` for pushes to `main`, or when the manual `publish` input is set | Whether CI uploads the artifacts the publish workflow publishes to NuGet, npm and a GitHub release |
| `DOCKER_USER`, `DOCKER_TOKEN` | Docker Hub secrets | When `DOCKER_TOKEN` is non-empty, `Build.Linux.ps1` pushes images |
| `SEQ_DOCKER_TAG` | e.g. `2026.1` | Seq image tag used for the Linux end-to-end tests |

GitHub supplies no secrets or OIDC tokens to pull requests from forks, and PR builds run the full build and test steps but publish nothing.

## The publish workflow

`publish.yml` runs via `workflow_run` when the CI workflow completes. It only publishes when that CI run succeeded, and was started by a push or manual dispatch on `dev` or `main` in this repository; it does nothing for pull requests. Two jobs run, independently:
`publish.yml` runs via `workflow_run` when the CI workflow completes. It only publishes when that CI run succeeded in this repository, and was either a push to `main` or a manual dispatch on `dev` or `main`; it does nothing for pull requests or pushes to `dev`. Four jobs run:

1. **Publish (NuGet)** downloads the `packages` artifact from the CI run and pushes it to NuGet.org.
2. **Publish (npm)** checks out the commit CI built, downloads the `archives` artifact, and runs `Build.Npm.ps1`.
1. **Draft GitHub release** downloads all three artifacts and creates a draft release `v<version>` targeting the commit CI built, with them attached; builds from branches other than `main` are marked as prereleases. Drafts are visible only to people with write access, and the tag isn't created until the release is published.
2. **Publish (NuGet)** downloads the `packages` artifact from the CI run and pushes it to NuGet.org.
3. **Publish (npm)** checks out the commit CI built, downloads the `archives` artifact, and runs `Build.Npm.ps1`.
4. **Publish GitHub release** runs only after both registries succeed, and publishes the draft, which creates the tag.

The NuGet and npm jobs run in parallel, after the draft is created. If either fails, the draft is left in place; re-running the failed jobs publishes it once they succeed. Re-running the draft job updates the existing draft's assets rather than creating another.

Both registries use [trusted publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing).

Expand All @@ -63,12 +66,14 @@ Both registries use [trusted publishing](https://learn.microsoft.com/nuget/nuget
| Trigger | GitHub release | NuGet | Docker Hub | npm |
|---|---|---|---|---|
| Pull request | no | no | no | no |
| Push to `dev` | no (unless manual `publish`) | prerelease version | `datalust/seqcli-ci:<version>` | prerelease, dist-tag `dev` |
| Push to `dev` | no | no | `datalust/seqcli-ci:<version>` | no |
| Push to `main` | yes, `v<version>` | release version | `datalust/seqcli-ci:<version>` | release, dist-tag `latest` |
| Manual run, `publish` checked | yes (prerelease unless on `main`) | prerelease version unless on `main` | `datalust/seqcli-ci:<version>` | prerelease (dist-tag `dev`) unless on `main` |
| Manual run, `publish` unchecked | no (CI skips its jobs) | no | no | no |

Note that `Build.Linux.ps1` always pushes to the `datalust/seqcli-ci` repository (the image name with a `-ci` suffix), never directly to `datalust/seqcli`. Promoting an image to the public `datalust/seqcli` repository, and tagging it `latest`, is a separate step outside this repository.

To publish a release from `dev` (for example a preview build), run the workflow manually from the Actions tab with the **Publish a GitHub release** input checked. The release is marked as a prerelease because the branch is not `main`.
To publish a release from `dev` (for example a preview build), run the workflow manually from the Actions tab with the **Publish a GitHub release and packages** input checked; this also publishes to NuGet and npm. The release is marked as a prerelease because the branch is not `main`.

## Running the builds locally

Expand Down