ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 1m5s
ci / test (pull_request) Successful in 7m15s
ci / build (pull_request) Successful in 2m25s
ci / image (pull_request) Successful in 28s
On main and tags GITHUB_SERVER_URL is http://gitea-http.gitea.svc..., and the runner's Docker daemon refused to push there: "server gave HTTP response to HTTPS client". crane pushes the saved image with --insecure for http:// servers and tags the channels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
359 lines
16 KiB
YAML
359 lines
16 KiB
YAML
name: ci
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ["v*"]
|
|
pull_request:
|
|
|
|
concurrency:
|
|
group: ci-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
GOLANGCI_LINT_VERSION: v2.15.0
|
|
SQLC_VERSION: v1.31.1
|
|
# sha256 of golangci-lint-<version>-linux-amd64.tar.gz from the release's checksums.txt
|
|
GOLANGCI_LINT_SHA256: 9b7fe6a6bf6334b98decf8d86b11415ea7889afdabdd1959fdce23af2a9ebcea
|
|
HELM_VERSION: v3.19.0
|
|
SHELLCHECK_VERSION: v0.12.0
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
# The runners are ephemeral and clone every action from GitHub, which
|
|
# takes minutes; Go comes as a tarball instead, and the job image
|
|
# already has the Node version the frontend build needs.
|
|
- name: Install Go
|
|
run: |
|
|
v="$(awk '/^go /{print $2}' go.mod)"
|
|
curl -fsSL "https://go.dev/dl/go${v}.linux-amd64.tar.gz" | tar -C /usr/local -xz
|
|
echo /usr/local/go/bin >> "$GITHUB_PATH"
|
|
echo "$HOME/go/bin" >> "$GITHUB_PATH"
|
|
echo "GO_VERSION=$v" >> "$GITHUB_ENV"
|
|
# Module, build and npm caches live in the runners' S3 cache. Only main
|
|
# saves them (one entry per commit, expired by the bucket after 7 days);
|
|
# pull requests and tags restore the newest one from main.
|
|
- name: Restore caches
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: |
|
|
~/go/pkg/mod
|
|
~/.cache/go-build
|
|
~/.cache/golangci-lint
|
|
~/.npm
|
|
key: lint-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-${{ github.sha }}
|
|
restore-keys: |
|
|
lint-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-
|
|
lint-go${{ env.GO_VERSION }}-
|
|
- name: Build frontend
|
|
run: npm ci --no-audit --no-fund --prefer-offline && npm run build
|
|
- name: Generated code is up to date
|
|
run: |
|
|
go tool templ generate
|
|
# The release binary avoids compiling sqlc's cgo parser.
|
|
curl -fsSL "https://github.com/sqlc-dev/sqlc/releases/download/${SQLC_VERSION}/sqlc_${SQLC_VERSION#v}_linux_amd64.tar.gz" | tar -xz -C /usr/local/bin sqlc
|
|
sqlc generate
|
|
git diff --exit-code -- '*.go'
|
|
- name: gofmt
|
|
run: test -z "$(gofmt -l internal cmd tools deploy)" || { gofmt -l internal cmd tools deploy; exit 1; }
|
|
- name: go vet
|
|
run: go vet ./...
|
|
# The release binary instead of `go install`, which compiled the linter
|
|
# from source on every run.
|
|
- name: golangci-lint
|
|
run: |
|
|
v="${GOLANGCI_LINT_VERSION#v}"
|
|
curl -fsSLo /tmp/golangci-lint.tar.gz "https://github.com/golangci/golangci-lint/releases/download/${GOLANGCI_LINT_VERSION}/golangci-lint-${v}-linux-amd64.tar.gz"
|
|
echo "${GOLANGCI_LINT_SHA256} /tmp/golangci-lint.tar.gz" | sha256sum -c -
|
|
tar -xzf /tmp/golangci-lint.tar.gz -C /usr/local/bin --strip-components=1 "golangci-lint-${v}-linux-amd64/golangci-lint"
|
|
golangci-lint run ./...
|
|
- name: Helm chart
|
|
run: |
|
|
curl -fsSL "https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz" | tar -xz -C /usr/local/bin --strip-components=1 linux-amd64/helm
|
|
chart=deploy/helm/uptimesebi
|
|
base="--set publicURL=https://uptime.example.com --set redis.url=redis://redis:6379/0 --set secretKeys.value=k1:test"
|
|
helm lint --strict "$chart" $base --set database.url=postgres://u:p@db/uptime
|
|
# Every combination renders; missing settings fail with a message.
|
|
helm template t "$chart" $base --set database.url=postgres://u:p@db/uptime >/dev/null
|
|
helm template t "$chart" $base --set database.bundled.enabled=true --set ingress.enabled=true --set ingress.tls.enabled=true \
|
|
--set checker.enabled=true --set checker.token=usa_x --set statuspage.enabled=true --set statuspage.token=usa_y \
|
|
--set 'statuspage.hosts={status.example.com}' --set statuspage.ingress.enabled=true \
|
|
--set redis.sentinel.master=m --set 'redis.sentinel.addrs={s1:26379}' --set redis.sentinel.password=p >/dev/null
|
|
helm template t "$chart" --set publicURL=https://uptime.example.com --set secretKeys.value=k1:test \
|
|
--set database.bundled.enabled=true --set redis.bundled.enabled=true --set redis.bundled.persistence.enabled=false >/dev/null
|
|
if helm template t "$chart" $base >/dev/null 2>&1; then echo "rendered without a database" >&2; exit 1; fi
|
|
# The install script the API serves must stay POSIX sh for Alpine,
|
|
# Debian and Raspberry Pi OS; the test renders and checks it.
|
|
- name: shellcheck
|
|
run: |
|
|
# Static release binary instead of apt-get update + install on every run.
|
|
curl -fsSL "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" \
|
|
| tar -xJ -C /usr/local/bin --strip-components=1 "shellcheck-${SHELLCHECK_VERSION}/shellcheck"
|
|
go test -count=1 -run 'TestScript|TestInstall' -v ./deploy/agent/ | grep -v '^=== RUN'
|
|
- name: Save caches
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/cache/save@v4
|
|
with:
|
|
path: |
|
|
~/go/pkg/mod
|
|
~/.cache/go-build
|
|
~/.cache/golangci-lint
|
|
~/.npm
|
|
key: lint-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-${{ github.sha }}
|
|
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
timescaledb:
|
|
image: timescale/timescaledb:2.30.1-pg16
|
|
env:
|
|
POSTGRES_PASSWORD: postgres
|
|
redis:
|
|
image: redis:8-alpine
|
|
# Targets of the database checks; SQL Server is left to local runs,
|
|
# its image is too large for ephemeral runners.
|
|
mariadb:
|
|
image: mariadb:11@sha256:e1d5495f445654134f226f55a41ce0da227116f6f27f283101f405c794d841fc
|
|
env:
|
|
MARIADB_ROOT_PASSWORD: checkpw
|
|
MARIADB_DATABASE: shop
|
|
options: --health-cmd "healthcheck.sh --connect" --health-interval 2s --health-retries 60
|
|
mongo:
|
|
image: mongo:8
|
|
env:
|
|
MONGO_INITDB_ROOT_USERNAME: root
|
|
MONGO_INITDB_ROOT_PASSWORD: checkpw
|
|
rabbitmq:
|
|
image: rabbitmq:4-alpine
|
|
env:
|
|
RABBITMQ_DEFAULT_USER: check
|
|
RABBITMQ_DEFAULT_PASS: checkpw
|
|
kafka:
|
|
image: apache/kafka-native:4.4.0@sha256:11fde816adf384402de9f3e57aeaf2c3722ba0671610247817688d07441714b4
|
|
env:
|
|
KAFKA_NODE_ID: 1
|
|
KAFKA_PROCESS_ROLES: broker,controller
|
|
KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
|
|
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
|
|
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
|
|
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
|
|
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
|
|
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
|
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
|
|
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
|
|
env:
|
|
UPTIME_TEST_DATABASE_URL: postgres://uptime:uptime@timescaledb:5432/uptime_test?sslmode=disable
|
|
UPTIME_TEST_REDIS_URL: redis://redis:6379/15
|
|
UPTIME_TEST_MYSQL_ADDR: mariadb:3306
|
|
UPTIME_TEST_MONGO_ADDR: mongo:27017
|
|
UPTIME_TEST_RABBITMQ_ADDR: rabbitmq:5672
|
|
UPTIME_TEST_KAFKA_ADDR: kafka:9092
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
# The runners are ephemeral and clone every action from GitHub, which
|
|
# takes minutes; Go comes as a tarball instead, and the job image
|
|
# already has the Node version the frontend build needs.
|
|
- name: Install Go
|
|
run: |
|
|
v="$(awk '/^go /{print $2}' go.mod)"
|
|
curl -fsSL "https://go.dev/dl/go${v}.linux-amd64.tar.gz" | tar -C /usr/local -xz
|
|
echo /usr/local/go/bin >> "$GITHUB_PATH"
|
|
echo "$HOME/go/bin" >> "$GITHUB_PATH"
|
|
echo "GO_VERSION=$v" >> "$GITHUB_ENV"
|
|
- name: Restore caches
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: |
|
|
~/go/pkg/mod
|
|
~/.cache/go-build
|
|
~/.npm
|
|
key: test-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-${{ github.sha }}
|
|
restore-keys: |
|
|
test-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-
|
|
test-go${{ env.GO_VERSION }}-
|
|
- name: Build frontend
|
|
run: npm ci --no-audit --no-fund --prefer-offline && npm run build
|
|
- name: Prepare database
|
|
# The same roles and databases as the local environment: the
|
|
# application role must not be a superuser, or row-level security
|
|
# is bypassed and the isolation tests prove nothing.
|
|
run: go run ./internal/devtools/pginit "postgres://postgres:postgres@timescaledb:5432/postgres?sslmode=disable" deploy/dev/postgres-init.sql
|
|
- name: Test
|
|
# Integration tests share one database, so packages run one at a time.
|
|
run: go test -p 1 -count=1 ./...
|
|
- name: Save caches
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/cache/save@v4
|
|
with:
|
|
path: |
|
|
~/go/pkg/mod
|
|
~/.cache/go-build
|
|
~/.npm
|
|
key: test-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-${{ github.sha }}
|
|
|
|
build:
|
|
# Nothing is built or pushed from code that fails lint or tests; the
|
|
# image job waits for this one.
|
|
needs: [lint, test]
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.binaries.outputs.version }}
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
# The runners are ephemeral and clone every action from GitHub, which
|
|
# takes minutes; Go comes as a tarball instead, and the job image
|
|
# already has the Node version the frontend build needs.
|
|
- name: Install Go
|
|
run: |
|
|
v="$(awk '/^go /{print $2}' go.mod)"
|
|
curl -fsSL "https://go.dev/dl/go${v}.linux-amd64.tar.gz" | tar -C /usr/local -xz
|
|
echo /usr/local/go/bin >> "$GITHUB_PATH"
|
|
echo "$HOME/go/bin" >> "$GITHUB_PATH"
|
|
echo "GO_VERSION=$v" >> "$GITHUB_ENV"
|
|
- name: Restore caches
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: |
|
|
~/go/pkg/mod
|
|
~/.cache/go-build
|
|
~/.npm
|
|
key: build-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-${{ github.sha }}
|
|
restore-keys: |
|
|
build-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-
|
|
build-go${{ env.GO_VERSION }}-
|
|
- name: Build frontend
|
|
run: npm ci --no-audit --no-fund --prefer-offline && npm run build
|
|
- name: Build binaries
|
|
id: binaries
|
|
run: |
|
|
set -eu
|
|
pkg=git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo
|
|
case "$GITHUB_REF" in
|
|
refs/tags/v*) version="$GITHUB_REF_NAME" ;;
|
|
*) version="$(git log -1 --format=%cd --date=format:%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)" ;;
|
|
esac
|
|
echo "VERSION=$version" >> "$GITHUB_ENV"
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
for platform in linux/amd64 linux/arm64 linux/arm/v7 linux/arm/v6; do
|
|
IFS=/ read -r os arch variant <<< "$platform"
|
|
CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=${variant#v} go build -trimpath \
|
|
-ldflags "-s -w -X $pkg.Version=$version -X $pkg.Commit=$(git rev-parse --short=12 HEAD)" \
|
|
-o "dist/$(echo "$platform" | tr / _)/" ./cmd/...
|
|
done
|
|
ls -lR dist
|
|
# Checker and status page images for every platform, plain and
|
|
# self-updating, assembled from the binaries above without Docker;
|
|
# pushed like the main image and signed for the self-updating agents.
|
|
- name: Agent images
|
|
env:
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }}
|
|
run: |
|
|
set -eu
|
|
host="${GITHUB_SERVER_URL#*://}"
|
|
owner="$(printf '%s' "${GITHUB_REPOSITORY%/*}" | tr 'A-Z' 'a-z')"
|
|
flags="-version $VERSION -commit $GITHUB_SHA -ref $GITHUB_REF -created $(git log -1 --format=%ct) -source $GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
|
|
case "$GITHUB_SERVER_URL" in http://*) flags="$flags -insecure" ;; esac
|
|
case "$GITHUB_REF" in
|
|
refs/heads/main|refs/tags/v*)
|
|
if [ -n "${PACKAGE_TOKEN:-}" ]; then flags="$flags -push"; else echo "PACKAGE_TOKEN is not set; building without pushing."; fi ;;
|
|
esac
|
|
export REGISTRY_USER="$GITHUB_ACTOR" REGISTRY_PASSWORD="${PACKAGE_TOKEN:-}"
|
|
go build -o image ./tools/image
|
|
for variant in "" -autoupdate; do
|
|
./image -name checker -repo "$host/$owner/uptimesebi-checker" -port 8081/tcp $variant $flags
|
|
./image -name statuspage -repo "$host/$owner/uptimesebi-statuspage" -port 8082/tcp \
|
|
-env UPTIME_STATUSPAGE_CACHE_DIR=/var/lib/uptimesebi $variant $flags
|
|
done
|
|
- name: Save caches
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/cache/save@v4
|
|
with:
|
|
path: |
|
|
~/go/pkg/mod
|
|
~/.cache/go-build
|
|
~/.npm
|
|
key: build-go${{ env.GO_VERSION }}-${{ hashFiles('go.sum', 'package-lock.json') }}-${{ github.sha }}
|
|
# The image job packs the amd64 binaries instead of compiling everything again.
|
|
- name: Hand the binaries to the image job
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: image-context
|
|
path: |
|
|
Dockerfile.ci
|
|
dist/linux_amd64/
|
|
retention-days: 1
|
|
|
|
image:
|
|
# Builds Dockerfile.ci (the build job's amd64 binaries on distroless)
|
|
# with the runner's Docker daemon and pushes with crane instead of Kaniko rebuilding frontend
|
|
# and Go from the git context. Images are pushed only from main and tags,
|
|
# and only once the PACKAGE_TOKEN secret (write:package) exists.
|
|
# The build job's version, so the API reports the release its agent
|
|
# images are tagged with.
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
# Node for the artifact action; the Docker CLI is added below.
|
|
container:
|
|
image: node:24-alpine
|
|
defaults:
|
|
run:
|
|
shell: sh
|
|
steps:
|
|
- uses: actions/download-artifact@v4
|
|
with:
|
|
name: image-context
|
|
path: ctx
|
|
- name: Build (and push from main and tags)
|
|
env:
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
VERSION: ${{ needs.build.outputs.version }}
|
|
run: |
|
|
set -eu
|
|
apk add --no-cache docker-cli docker-cli-buildx crane >/dev/null
|
|
REGISTRY="${GITHUB_SERVER_URL#*://}"
|
|
IMAGE="$(printf '%s/%s' "$REGISTRY" "$GITHUB_REPOSITORY" | tr 'A-Z' 'a-z')"
|
|
TAG="$VERSION"
|
|
TAGS="${IMAGE}:${TAG#v}"
|
|
# Channels: edge follows main, beta the newest prerelease, latest
|
|
# and stable the newest release, X.Y its newest patch.
|
|
CHANNELS=""
|
|
case "$GITHUB_REF" in
|
|
refs/heads/main) CHANNELS="edge" ;;
|
|
refs/tags/v*-beta.*) CHANNELS="beta" ;;
|
|
refs/tags/v*)
|
|
MINOR="$(printf '%s' "${TAG#v}" | cut -d. -f1-2)"
|
|
CHANNELS="latest stable $MINOR" ;;
|
|
esac
|
|
for c in $CHANNELS; do TAGS="$TAGS ${IMAGE}:$c"; done
|
|
set --
|
|
for t in $TAGS; do set -- "$@" -t "$t"; done
|
|
docker build --platform linux/amd64 -f ctx/Dockerfile.ci "$@" ctx
|
|
case "$GITHUB_REF" in
|
|
refs/heads/main|refs/tags/v*)
|
|
if [ -z "${PACKAGE_TOKEN:-}" ]; then
|
|
echo "PACKAGE_TOKEN is not set; built without pushing."
|
|
exit 0
|
|
fi
|
|
# crane instead of docker push: on main and tags GITHUB_SERVER_URL is
|
|
# the in-cluster plain-HTTP address, which the runner's Docker
|
|
# daemon refuses ("server gave HTTP response to HTTPS client").
|
|
INSECURE=""
|
|
case "$GITHUB_SERVER_URL" in http://*) INSECURE="--insecure" ;; esac
|
|
printf '%s' "$PACKAGE_TOKEN" | crane auth login "$REGISTRY" -u "$GITHUB_ACTOR" --password-stdin $INSECURE
|
|
FIRST=""
|
|
for t in $TAGS; do
|
|
if [ -z "$FIRST" ]; then
|
|
docker save "$t" -o /tmp/image.tar
|
|
crane push $INSECURE /tmp/image.tar "$t"
|
|
FIRST="$t"
|
|
else
|
|
crane tag $INSECURE "$FIRST" "${t##*:}"
|
|
fi
|
|
done ;;
|
|
*) echo "Pull request: built without pushing." ;;
|
|
esac
|