Skip to content
Merged
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
81 changes: 69 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,54 @@ 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
# Writes the release tag to the step's `tag` output.
id: draft
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
shell: pwsh
run: |
Comment thread
KodrAus marked this conversation as resolved.
Resolved
./build/Build.Release.ps1 -AssetDir ./release-assets -Target $env:HEAD_SHA
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 +98,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 +116,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 +142,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"
59 changes: 59 additions & 0 deletions build/Build.Release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Creates (or refreshes) the draft GitHub release for a seqcli build, with every file in -AssetDir
# attached. The tag isn't created until the release is published, at the commit given by -Target.
#
# In CI (see draft-release in .github/workflows/publish.yml) the assets are the artifacts of the CI
# run, and the version is reproduced by Get-SemVer from CI_BUILD_NUMBER_BASE and CI_TARGET_BRANCH.
# Builds from branches other than `main` are marked as prereleases. If a draft for the tag already
# exists (left by an earlier attempt of the same run), its assets are replaced instead.
#
# The release tag is written to $env:GITHUB_OUTPUT as `tag` when that variable is set.
#
# Usage:
# ./build/Build.Release.ps1 -AssetDir ./release-assets -Target <sha>
param(
# Directory containing the files to attach to the release.
[Parameter(Mandatory)]
[string] $AssetDir,

# Commit the release's tag is created at when the release is published.
[Parameter(Mandatory)]
[string] $Target,

# GitHub repository to create the release in.
[string] $Repo = $env:GITHUB_REPOSITORY
)

$ErrorActionPreference = 'Stop'

if (-not $Repo) { throw "No repository given; pass -Repo or set GITHUB_REPOSITORY" }

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

Push-Location $PSScriptRoot/../
try {
. ./build/Build.Common.ps1
$tag = "v$(Get-SemVer)"
} finally {
Pop-Location
}

if ($env:GITHUB_OUTPUT) {
"tag=$tag" >> $env:GITHUB_OUTPUT
}

$isDraft = gh release view $tag --repo $Repo --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 $Repo --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', $Target, '--generate-notes', '--repo', $Repo)
# Get-SemVer adds a prerelease suffix for every branch except `main`.
if ($tag.Contains('-')) { $arguments += '--prerelease' }
& gh @arguments @assets
if ($LASTEXITCODE -ne 0) { throw "Creating the draft release failed" }
}
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
Loading