Skip to content
Closed
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
11 changes: 2 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# If this file is renamed, the incrementing run attempt number will be reset. If the workflow's
# If this file is renamed, the incrementing run number will be reset. If the workflow's
# `name` changes, the `workflow_run` trigger in publish.yml must be updated.

name: CI
Expand All @@ -8,18 +8,11 @@ on:
branches: [ "dev", "main" ]
pull_request:
branches: [ "dev", "main" ]
workflow_dispatch:
inputs:
publish:
description: 'Publish a GitHub release'
type: boolean
required: true
default: true

env:
CI_BUILD_NUMBER_BASE: ${{ github.run_number }}
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
CI_PUBLISH: ${{ (github.event_name == 'push' && github.ref_name == 'main') || inputs.publish }}
CI_PUBLISH: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev'))}}

jobs:
build-windows:
Expand Down
91 changes: 67 additions & 24 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,74 @@
# Publishes the packages built by a successful CI run to NuGet.org and npm
# Publishes the packages built by a successful CI run to NuGet.org and npm.
#
# CI runs on `main` are published automatically. Builds from other branches (e.g. `dev`) are only
# published when this workflow is run manually from the Actions tab, selecting the branch to publish;
# that publishes the latest successful CI push build of the branch.

name: Publish

on:
workflow_run:
workflows: [ "CI" ]
types: [ completed ]
branches: [ "dev", "main" ]
branches: [ "main" ]
workflow_dispatch:

permissions: {}

env:
# Reproduce the version computed by the triggering CI run (see Get-SemVer in build/Build.Common.ps1).
CI_BUILD_NUMBER_BASE: ${{ github.event.workflow_run.run_number }}
CI_TARGET_BRANCH: ${{ github.event.workflow_run.head_branch }}

jobs:
publish-nuget:
name: Publish (NuGet)
# Identifies the CI run whose artifacts are published, and the values needed to reproduce its version.
resolve:
name: Resolve CI run
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_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.head_repository.full_name == github.repository)

permissions:
# Required to download artifacts from the triggering CI run.
# Required to look up CI runs.
actions: read

outputs:
run-id: ${{ github.event.workflow_run.id || steps.latest.outputs.id }}
run-number: ${{ github.event.workflow_run.run_number || steps.latest.outputs.number }}
head-branch: ${{ github.event.workflow_run.head_branch || github.ref_name }}
head-sha: ${{ github.event.workflow_run.head_sha || steps.latest.outputs.sha }}

steps:
# Automatic runs take everything from the triggering CI run, validated by the condition above.
# The query's filters give manual runs the same guarantees: a successful CI build of a commit
# pushed to this repository, never pull request code.
- name: Find latest successful CI push build
id: latest
if: github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail

run=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow ci.yml --branch "$GITHUB_REF_NAME" \
--event push --status success --limit 1 --json databaseId,number,headSha,url \
--jq '.[0] // empty | "id=\(.databaseId)", "number=\(.number)", "sha=\(.headSha)", "url=\(.url)"')

if [ -z "$run" ]; then
echo "::error::No successful CI push build found for branch '$GITHUB_REF_NAME'"
exit 1
fi

echo "$run" | tee -a "$GITHUB_OUTPUT"

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

permissions:
# Required to download artifacts from the CI run.
actions: read
# Required for NuGet.org trusted publishing.
id-token: write
Expand All @@ -41,7 +83,7 @@ jobs:
with:
name: packages
path: packages
run-id: ${{ github.event.workflow_run.id }}
run-id: ${{ needs.resolve.outputs.run-id }}
github-token: ${{ github.token }}
- name: Log in to NuGet
uses: NuGet/login@v1
Expand All @@ -64,25 +106,26 @@ jobs:
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: resolve

permissions:
# Required to download artifacts from the triggering CI run.
# Required to download artifacts from the CI run.
actions: read
contents: read
# Required for npm trusted publishing and provenance.
id-token: write

env:
# Reproduce the version computed by the CI run (see Get-SemVer in build/Build.Common.ps1).
CI_BUILD_NUMBER_BASE: ${{ needs.resolve.outputs.run-number }}
CI_TARGET_BRANCH: ${{ needs.resolve.outputs.head-branch }}

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 resolve job
# guarantees this is a commit pushed to this repository, not pull request code.
- uses: actions/checkout@v6
with:
ref: ${{ github.event.workflow_run.head_sha }}
ref: ${{ needs.resolve.outputs.head-sha }}
persist-credentials: false
- name: Setup
uses: actions/setup-node@v7
Expand All @@ -98,7 +141,7 @@ jobs:
with:
name: archives
path: npm-archives
run-id: ${{ github.event.workflow_run.id }}
run-id: ${{ needs.resolve.outputs.run-id }}
github-token: ${{ github.token }}
- name: Publish
shell: pwsh
Expand Down
8 changes: 6 additions & 2 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ GitHub supplies no secrets or OIDC tokens to pull requests from forks, and PR bu

## 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 automatically via `workflow_run` when the CI workflow completes on `main`. It only publishes when that CI run succeeded, and was started by a push or manual dispatch in this repository; it does nothing for pull requests.

Builds from `dev` are not published automatically. To publish one, run the **Publish** workflow manually from the Actions tab and select the `dev` branch. It publishes the latest successful CI push build of that branch. The CI run's artifacts are only retained for one day, so if that build is older, push again or re-run CI first.

A **Resolve CI run** job first identifies the CI run, then two jobs run, independently:

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`.
Expand All @@ -63,7 +67,7 @@ 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 (unless manual `publish`) | prerelease version, when the publish workflow is run manually | `datalust/seqcli-ci:<version>` | prerelease, dist-tag `dev`, when the publish workflow is run manually |
| Push to `main` | yes, `v<version>` | release version | `datalust/seqcli-ci:<version>` | release, dist-tag `latest` |

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.
Expand Down