Files
ExecuteR/.gitea/workflows/ci.yml
T
Alphaeus Mote 8f230cd89c
CI / build-test (push) Successful in 33m26s
CI / images (push) Has been skipped
Release / images (push) Successful in 9m49s
Release / release (push) Successful in 18m53s
fix(ci): retry an image push the registry timed out on
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 09:55:17 -05:00

337 lines
14 KiB
YAML

name: CI
# Runs only when something buildable changes — docs-only commits (README,
# docs/, compose examples) skip the queue entirely.
on:
# Manual trigger from the Gitea Actions UI (or API), for an on-demand build
# without a dummy commit.
workflow_dispatch:
pull_request:
branches: [main]
paths:
- 'src/**'
- 'tests/**'
- 'scripts/**'
- 'assets/**'
- 'build/**'
- '.gitea/workflows/**'
- 'ExecuteR.slnx'
- 'Directory.Build.props'
- 'Directory.Packages.props'
- 'global.json'
- 'dotnet-tools.json'
push:
branches: [dev, main]
paths:
- 'src/**'
- 'tests/**'
- 'scripts/**'
- 'assets/**'
- 'build/**'
- '.gitea/workflows/**'
- 'ExecuteR.slnx'
- 'Directory.Build.props'
- 'Directory.Packages.props'
- 'global.json'
- 'dotnet-tools.json'
jobs:
build-test:
# Windows is required to build/test the agent (CIM, ConPTY, DPAPI, service).
# Label must match a registered runner: windows-host.
runs-on: windows-host
# Single source of truth for the version: the images job consumes this
# instead of recomputing, so binaries and container images never drift.
outputs:
version: ${{ steps.ver.outputs.version }}
short: ${{ steps.ver.outputs.short }}
release: ${{ steps.ver.outputs.release }}
steps:
# This repository uses the SHA-256 object format. actions/checkout
# cannot clone it (it inits a SHA-1 repo then fetches: "mismatched
# algorithms"), so check out with plain git clone, which negotiates
# the object format correctly. The version needs the branch's whole
# history and its tags (the last release tag and the commits since it),
# so no --depth.
- name: Checkout
shell: pwsh
env:
CHECKOUT_TOKEN: ${{ github.token }}
run: |
$ErrorActionPreference = 'Stop'
Get-ChildItem -Force | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
$ref = '${{ github.head_ref }}'
if (-not $ref) { $ref = '${{ github.ref_name }}' }
$url = '${{ github.server_url }}/${{ github.repository }}.git' -replace '^https://', "https://x-access-token:$env:CHECKOUT_TOKEN@"
git clone --single-branch --branch $ref $url .
git log -1 --format='%H %s'
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Setup Node
uses: actions/setup-node@v4
with:
# @nats-io/* packages require Node >= 22.
node-version: '22'
# README, Versioning. A build is X.Y.Z.N (N commits after the last
# release tag vX.Y.Z; 0.0.0.N before the first). A push to main that
# release.yml releases (a fix, feat or breaking change since the last
# release) builds as that release, X.Y.Z, the version release.yml
# computes the same way (semantic-release, dry run): the two workflows
# agree on a release commit's version, and its images come from
# release.yml (release=true skips them here).
- name: Version
id: ver
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$v = $null
$release = 'false'
if ('${{ github.event_name }}' -eq 'push' -and '${{ github.ref_name }}' -eq 'main') {
try {
$next = ./scripts/Get-NextRelease.ps1
if ($next) { $v = $next.Version; $release = 'true' }
}
catch {
Write-Host "::warning::The next release could not be computed ($_); building as a build between releases."
}
}
if (-not $v) { $v = ./scripts/Get-Version.ps1 }
$short = ./scripts/Get-Version.ps1 -Version $v -Format Short
"version=$v" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"short=$short" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"release=$release" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "Version: $v ($short; release: $release)"
# A refused dry run above leaves its exit code behind; this step succeeded.
$global:LASTEXITCODE = 0
- name: Restore
run: dotnet restore ExecuteR.slnx
- name: Build
run: dotnet build ExecuteR.slnx -c Release --no-restore "-p:UnifiedVersion=${{ steps.ver.outputs.version }}" "-p:GitCommitShort=${{ steps.ver.outputs.short }}"
# The real program, for the tests that run the server with its built-in store.
- name: Fetch the object store
shell: pwsh
run: ./scripts/Get-ObjectStore.ps1 -Runtime win-x64 -Destination artifacts/object-store/win-x64
- name: Unit tests
run: |
dotnet test tests/Shared.Tests -c Release --no-build --nologo
dotnet test tests/Agent.Tests -c Release --no-build --nologo
dotnet test tests/Agent.Watchdog.Tests -c Release --no-build --nologo
dotnet test tests/Backend.Tests -c Release --no-build --nologo
# The version scripts and the release numbering, in a scratch repository.
- name: Versioning checks
shell: pwsh
run: ./scripts/tests/Test-Versioning.ps1
- name: Integration tests
run: dotnet test tests/Integration.Tests -c Release --no-build --nologo
- name: WebUI install
run: npm ci
working-directory: src/WebUI
- name: WebUI check
run: npm run check
working-directory: src/WebUI
- name: WebUI build
env:
PUBLIC_BUILD_VERSION: ${{ steps.ver.outputs.version }}
run: npm run build
working-directory: src/WebUI
# Package the agent for every platform here (only Windows can build the
# windows flavor and the MSI) so the Linux image job can bake the Windows
# package into the backend image — no manual seeding at deploy.
- name: Package agent (all platforms)
if: ${{ github.event_name == 'push' }}
shell: pwsh
run: |
./scripts/Package-Agent.ps1 -Version ${{ steps.ver.outputs.version }} `
-Runtimes win-x64,win-arm64,linux-x64,linux-arm64,osx-x64,osx-arm64
$stage = 'artifacts/agent-package'
New-Item -ItemType Directory -Force $stage | Out-Null
$msi = "artifacts/ExecuteR-Agent-${{ steps.ver.outputs.version }}.msi"
$zip = "artifacts/ExecuteR-Agent-${{ steps.ver.outputs.version }}-win-x64.zip"
if (Test-Path $msi) { Copy-Item $msi "$stage/Agent.msi" }
if (Test-Path $zip) { Copy-Item $zip "$stage/Agent.zip" }
foreach ($rid in 'linux-x64','linux-arm64','osx-x64','osx-arm64') {
$unix = "artifacts/ExecuteR-Agent-${{ steps.ver.outputs.version }}-$rid.zip"
if (Test-Path $unix) { Copy-Item $unix "$stage/Agent-$rid.zip" }
}
'${{ steps.ver.outputs.version }}' | Set-Content "$stage/VERSION" -NoNewline
Get-ChildItem $stage | Select-Object Name, Length
# The combined standalone server (UI + API + NATS sidecar in one binary).
- name: Package server (win-x64 + linux-x64)
if: ${{ github.event_name == 'push' }}
shell: pwsh
run: ./scripts/Package-Server.ps1 -Version ${{ steps.ver.outputs.version }} -SkipIcon
- name: Upload agent package
if: ${{ github.event_name == 'push' }}
uses: actions/upload-artifact@v3
with:
name: agent-package
path: artifacts/agent-package/
retention-days: 7
- name: Upload platform binaries
if: ${{ github.event_name == 'push' }}
uses: actions/upload-artifact@v3
with:
name: binaries
path: |
artifacts/ExecuteR-Agent-*.zip
artifacts/ExecuteR-Agent-*.msi
artifacts/ExecuteR-Agent-*-checksums.txt
artifacts/ExecuteR-Server-*.zip
artifacts/ExecuteR-Server-*.msi
artifacts/ExecuteR-Server-*-checksums.txt
retention-days: 7
images:
# Build the backend + webui images and publish them to the Gitea container
# registry. Image names match what docker-compose.yml pulls:
# <gitea-host>/<owner>/executer-backend:<tag>
# <gitea-host>/<owner>/executer-webui:<tag>
# A release commit's images (X.Y.Z and latest) come from release.yml.
needs: build-test
if: ${{ github.event_name == 'push' && needs.build-test.outputs.release != 'true' }}
# Needs Docker; label must match a registered Linux runner.
runs-on: ubuntu-host
env:
# Gitea's built-in container registry lives on the Gitea host itself and
# needs no configuration: Actions injects GITEA_TOKEN per run and it is
# accepted as the registry password for the triggering actor.
# The REGISTRY_* secrets are only an override for an EXTERNAL registry.
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST }}
REGISTRY_USER: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASS: ${{ secrets.REGISTRY_PASSWORD }}
SERVER_URL: ${{ github.server_url }}
ACTOR: ${{ github.actor }}
BUILTIN_TOKEN: ${{ secrets.GITEA_TOKEN }}
OWNER: ${{ github.repository_owner }}
steps:
# SHA-256 repo: plain git clone (see build-test).
- name: Checkout
shell: bash
env:
CHECKOUT_TOKEN: ${{ github.token }}
run: |
set -e
find . -mindepth 1 -maxdepth 1 -exec rm -rf {} + 2>/dev/null || true
REF='${{ github.head_ref }}'
[ -z "$REF" ] && REF='${{ github.ref_name }}'
URL="$(echo '${{ github.server_url }}/${{ github.repository }}.git' | sed "s#^https://#https://x-access-token:${CHECKOUT_TOKEN}@#")"
git clone --depth 1 --branch "$REF" "$URL" .
git log -1 --format='%H %s'
- name: Resolve registry target
id: ver
shell: bash
run: |
set -e
# The version is NOT recomputed here — it comes from build-test's
# output (needs.build-test.outputs.version) so images match the binaries.
# Default to Gitea's own registry on this instance; fall back to the
# REGISTRY_* secrets only when an external registry is configured.
if [ -n "$REGISTRY_HOST" ]; then
HOST="$REGISTRY_HOST"; USER="$REGISTRY_USER"; PASS="$REGISTRY_PASS"
echo "Using external registry $HOST"
else
HOST="$(echo "$SERVER_URL" | sed -E 's#^https?://##; s#/$##')"
USER="$ACTOR"; PASS="$BUILTIN_TOKEN"
echo "Using the built-in Gitea registry at $HOST"
fi
# Gitea package paths are lowercase.
OWNER_LC="$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')"
{
echo "host=$HOST"
echo "user=$USER"
echo "prefix=${HOST}/${OWNER_LC}/executer"
} >> "$GITHUB_OUTPUT"
echo "::add-mask::$PASS"
echo "REGISTRY_LOGIN_PASSWORD=$PASS" >> "$GITHUB_ENV"
- name: Registry login
run: echo "$REGISTRY_LOGIN_PASSWORD" | docker login "${{ steps.ver.outputs.host }}" -u "${{ steps.ver.outputs.user }}" --password-stdin
# Bake the Windows-built agent into the backend image so the URL install
# flow serves it with no manual seeding.
- name: Download agent package
uses: actions/download-artifact@v3
continue-on-error: true
with:
name: agent-package
path: src/Infra/backend/agent-package
- name: Confirm agent package staged
run: |
if ls src/Infra/backend/agent-package/Agent.* >/dev/null 2>&1; then
echo "Agent package will be baked into the backend image:"
ls -la src/Infra/backend/agent-package/
else
echo "::warning::No agent package staged - the backend image will ship without an installer and /api/enrollment/agent-package will 404 until one is mounted or offloaded to S3."
fi
- name: Build images
env:
VERSION: ${{ needs.build-test.outputs.version }}
GIT_COMMIT_SHORT: ${{ needs.build-test.outputs.short }}
PREFIX: ${{ steps.ver.outputs.prefix }}
SOURCE_URL: ${{ github.server_url }}/${{ github.repository }}
run: |
set -e
GIT_COMMIT="$(git rev-parse HEAD)"
[ -n "$GIT_COMMIT_SHORT" ] || GIT_COMMIT_SHORT="$(git rev-parse --short HEAD)"
BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
for svc in backend webui; do
docker build -f "src/Infra/${svc}/Dockerfile" \
--build-arg UNIFIED_VERSION="$VERSION" \
--build-arg GIT_COMMIT="$GIT_COMMIT" \
--build-arg GIT_COMMIT_SHORT="$GIT_COMMIT_SHORT" \
--build-arg BUILD_DATE="$BUILD_DATE" \
--build-arg SOURCE_URL="$SOURCE_URL" \
-t "${PREFIX}-${svc}:$VERSION" .
done
- name: Tag and push
env:
VERSION: ${{ needs.build-test.outputs.version }}
PREFIX: ${{ steps.ver.outputs.prefix }}
REF_NAME: ${{ github.ref_name }}
# main: <version> (X.Y.Z.N) and latest. Other branches: dev and
# <version>-dev only. A branch counts its own commits since the same
# release tag, so dev's 1.4.0.3 is not main's 1.4.0.3 and must not
# take main's version tag.
run: |
set -e
# The registry sometimes times out mid-upload; a retried push skips the layers already there.
push() { for try in 1 2 3 4; do docker push "$1" && return 0; echo "::warning::push of $1 failed (try $try)"; sleep $((try * 15)); done; return 1; }
for svc in backend webui; do
if [ "$REF_NAME" = "main" ]; then
push "${PREFIX}-${svc}:$VERSION"
docker tag "${PREFIX}-${svc}:$VERSION" "${PREFIX}-${svc}:latest"
push "${PREFIX}-${svc}:latest"
else
docker tag "${PREFIX}-${svc}:$VERSION" "${PREFIX}-${svc}:dev"
docker tag "${PREFIX}-${svc}:$VERSION" "${PREFIX}-${svc}:${VERSION}-dev"
push "${PREFIX}-${svc}:dev"
push "${PREFIX}-${svc}:${VERSION}-dev"
fi
done
echo "Published ${PREFIX}-backend and ${PREFIX}-webui"