mirror of
https://github.com/n30nex/CartoLite-Server.git
synced 2026-10-17 18:00:09 +00:00
358 lines
15 KiB
YAML
358 lines
15 KiB
YAML
name: CI
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: ci-${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
IMAGE_NAME: ghcr.io/n30nex/cartolite-server
|
|
# Exact published 0.6.2, in addition to the legacy 0.4.1 source migration below.
|
|
UPGRADE_FROM_IMAGE: ghcr.io/n30nex/cartolite-server@sha256:acb8a95101655cc0ded3971d1999390c5aff3dd276c97d3dc1f44dbfd408331d
|
|
|
|
jobs:
|
|
backend:
|
|
name: Go test, vet, and race
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
steps:
|
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
|
- uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
|
|
with:
|
|
go-version-file: backend/go.mod
|
|
cache-dependency-path: backend/go.sum
|
|
- working-directory: backend
|
|
run: go mod verify
|
|
- working-directory: backend
|
|
run: go test ./...
|
|
- working-directory: backend
|
|
run: go vet ./...
|
|
- working-directory: backend
|
|
run: go test -race ./...
|
|
- name: Synthetic ingest index benchmark
|
|
working-directory: backend
|
|
run: go test ./internal/engine -run '^$' -bench BenchmarkNodeRepresentative -benchmem -benchtime=200ms -count=3
|
|
|
|
frontend:
|
|
name: Frontend test and build
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
steps:
|
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
|
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
|
with:
|
|
node-version: 22
|
|
cache: npm
|
|
cache-dependency-path: web/package-lock.json
|
|
- working-directory: web
|
|
run: npm ci
|
|
- name: Audit shipped frontend dependencies
|
|
working-directory: web
|
|
run: npm audit --omit=dev --audit-level=high
|
|
- working-directory: web
|
|
run: npm test
|
|
- working-directory: web
|
|
run: npm run build
|
|
- run: node scripts/check-frontend-budget.mjs web/dist
|
|
|
|
container:
|
|
name: Container integration, browser, privacy, and scan (${{ matrix.arch }})
|
|
needs: [backend, frontend]
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- arch: amd64
|
|
runner: ubuntu-latest
|
|
- arch: arm64
|
|
runner: ubuntu-24.04-arm
|
|
runs-on: ${{ matrix.runner }}
|
|
timeout-minutes: 45
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
attestations: write
|
|
id-token: write
|
|
steps:
|
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
|
with:
|
|
fetch-depth: 0
|
|
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
|
with:
|
|
node-version: 22
|
|
cache: npm
|
|
cache-dependency-path: web/package-lock.json
|
|
- working-directory: web
|
|
if: matrix.arch == 'amd64'
|
|
run: |
|
|
npm ci
|
|
npm exec playwright install --with-deps chromium
|
|
- uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
|
|
- name: Read build identity
|
|
id: identity
|
|
run: |
|
|
version="$(tr -d '\r\n' < VERSION)"
|
|
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
|
|
test "$version" = "$(jq -r .version web/package.json)"
|
|
test "$version" = "$(jq -r .version web/package-lock.json)"
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
echo "time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
|
|
- name: Build hardened image
|
|
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
|
|
with:
|
|
context: .
|
|
platforms: linux/${{ matrix.arch }}
|
|
load: true
|
|
push: false
|
|
tags: cartolite-server:ci
|
|
build-args: |
|
|
APP_VERSION=${{ steps.identity.outputs.version }}
|
|
GIT_SHA=${{ github.sha }}
|
|
BUILD_TIME=${{ steps.identity.outputs.time }}
|
|
cache-from: type=gha,scope=world-${{ matrix.arch }}
|
|
cache-to: type=gha,scope=world-${{ matrix.arch }},mode=max
|
|
- run: |
|
|
bash scripts/check-image-size.sh cartolite-server:ci
|
|
test "$(docker image inspect cartolite-server:ci --format '{{.Config.User}}')" = "65532:65532"
|
|
test "$(docker image inspect cartolite-server:ci --format '{{.Architecture}}')" = "${{ matrix.arch }}"
|
|
test "$(docker image inspect cartolite-server:ci --format '{{index .Config.Labels "org.opencontainers.image.revision"}}')" = "$GITHUB_SHA"
|
|
- name: Start synthetic MQTT and server
|
|
run: |
|
|
docker network create cartolite-server-ci
|
|
docker volume create cartolite-server-ci-data
|
|
docker run -d --name cartolite-server-mqtt --network cartolite-server-ci \
|
|
--mount type=bind,source="$PWD/testdata/mosquitto.conf",target=/mosquitto/config/mosquitto.conf,readonly \
|
|
eclipse-mosquitto:2.0.22
|
|
docker run -d --name cartolite --network cartolite-server-ci \
|
|
-p 127.0.0.1:39476:8080 --read-only --cap-drop ALL \
|
|
--security-opt no-new-privileges:true --memory 256m \
|
|
--mount source=cartolite-server-ci-data,target=/data \
|
|
-e MQTT_BROKER_URL=tcp://cartolite-server-mqtt:1883 \
|
|
-e MQTT_TOPIC=meshcore/# -e MQTT_CLIENT_ID=cartolite-server-ci \
|
|
cartolite-server:ci
|
|
for _ in $(seq 1 90); do
|
|
curl --fail --silent http://127.0.0.1:39476/readyz >/dev/null && exit 0
|
|
sleep 1
|
|
done
|
|
docker logs cartolite
|
|
exit 1
|
|
- run: |
|
|
bash scripts/publish-fixture.sh cartolite-server-mqtt testdata/synthetic-live.ndjson
|
|
bash scripts/integration-smoke.sh http://127.0.0.1:39476 artifacts/integration cartolite-server-mqtt
|
|
bash scripts/performance-smoke.sh http://127.0.0.1:39476 cartolite-server-mqtt
|
|
- name: Worldwide and terrain regressions
|
|
if: matrix.arch == 'amd64'
|
|
working-directory: web
|
|
env:
|
|
CARTOLITE_BASE_URL: http://127.0.0.1:39476
|
|
PLAYWRIGHT_HTML_OUTPUT_DIR: focused-playwright-report
|
|
run: npm run test:e2e -- --grep '@terrain|@world' --output focused-test-results
|
|
- name: Complete desktop and mobile browser suite
|
|
if: matrix.arch == 'amd64'
|
|
working-directory: web
|
|
env:
|
|
CARTOLITE_BASE_URL: http://127.0.0.1:39476
|
|
shell: bash
|
|
run: |
|
|
(
|
|
while true; do
|
|
FIXTURE_DELAY_SECONDS=0.04 bash ../scripts/publish-fixture.sh cartolite-server-mqtt ../testdata/synthetic-live.ndjson
|
|
sleep 0.25
|
|
done
|
|
) &
|
|
publisher_pid=$!
|
|
trap 'kill "$publisher_pid" >/dev/null 2>&1 || true' EXIT
|
|
npm run test:e2e -- --grep-invert '@terrain|@world'
|
|
- uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
|
|
with:
|
|
scan-type: image
|
|
image-ref: cartolite-server:ci
|
|
format: table
|
|
severity: HIGH,CRITICAL
|
|
ignore-unfixed: true
|
|
exit-code: "1"
|
|
- name: Build the previous source release for native upgrade verification
|
|
run: |
|
|
git worktree add --detach "$RUNNER_TEMP/cartolite-upgrade-base" v0.4.1
|
|
previous_sha="$(git -C "$RUNNER_TEMP/cartolite-upgrade-base" rev-parse HEAD)"
|
|
docker build --tag cartolite-server:upgrade-base \
|
|
--build-arg APP_VERSION=0.4.1 --build-arg GIT_SHA="$previous_sha" \
|
|
"$RUNNER_TEMP/cartolite-upgrade-base"
|
|
- name: Verify Compose installation and upgrade from 0.4.1
|
|
run: bash scripts/compose-smoke.sh cartolite-server:ci "$GITHUB_SHA" cartolite-server:upgrade-base
|
|
- name: Log in to GHCR
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Publish the tested platform image
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
id: publish
|
|
run: |
|
|
candidate="${IMAGE_NAME}:sha-${GITHUB_SHA}-${{ matrix.arch }}"
|
|
docker tag cartolite-server:ci "$candidate"
|
|
docker push "$candidate"
|
|
docker buildx imagetools inspect "$candidate" > "$RUNNER_TEMP/candidate-inspect.txt"
|
|
digest="$(awk '$1 == "Digest:" {print $2; exit}' "$RUNNER_TEMP/candidate-inspect.txt")"
|
|
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]
|
|
mkdir -p artifacts/candidate
|
|
printf '%s\n' "$digest" > artifacts/candidate/${{ matrix.arch }}.txt
|
|
echo "digest=$digest" >> "$GITHUB_OUTPUT"
|
|
- name: Attest the tested platform image
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
uses: actions/attest@a1948c3f048ba23858d222213b7c278aabede763 # v4.1.1
|
|
with:
|
|
subject-name: ${{ env.IMAGE_NAME }}
|
|
subject-digest: ${{ steps.publish.outputs.digest }}
|
|
push-to-registry: true
|
|
- name: Record platform digest
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: candidate-${{ matrix.arch }}
|
|
path: artifacts/candidate/${{ matrix.arch }}.txt
|
|
overwrite: true
|
|
- name: Preserve browser and integration evidence
|
|
if: always()
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: cartolite-server-ci-evidence-${{ matrix.arch }}
|
|
overwrite: true
|
|
path: |
|
|
artifacts/integration/
|
|
artifacts/compose/
|
|
web/test-results/
|
|
web/playwright-report/
|
|
web/focused-test-results/
|
|
web/focused-playwright-report/
|
|
- if: always()
|
|
run: |
|
|
docker rm -f cartolite cartolite-server-mqtt >/dev/null 2>&1 || true
|
|
docker network rm cartolite-server-ci >/dev/null 2>&1 || true
|
|
|
|
publish:
|
|
name: Assemble and attest tested platform digests
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
needs: [container]
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
actions: read
|
|
packages: write
|
|
attestations: write
|
|
id-token: write
|
|
outputs:
|
|
image: ${{ steps.index.outputs.image }}
|
|
steps:
|
|
- uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
|
|
- uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Assemble exact tested images without rebuilding
|
|
id: index
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name candidate-amd64 --dir candidates
|
|
gh run download "$GITHUB_RUN_ID" --repo "$GITHUB_REPOSITORY" --name candidate-arm64 --dir candidates
|
|
amd64="$(cat candidates/amd64.txt)"
|
|
arm64="$(cat candidates/arm64.txt)"
|
|
[[ "$amd64" =~ ^sha256:[0-9a-f]{64}$ && "$arm64" =~ ^sha256:[0-9a-f]{64}$ ]]
|
|
gh attestation verify "oci://${IMAGE_NAME}@${amd64}" --repo "$GITHUB_REPOSITORY"
|
|
gh attestation verify "oci://${IMAGE_NAME}@${arm64}" --repo "$GITHUB_REPOSITORY"
|
|
candidate="${IMAGE_NAME}:sha-${GITHUB_SHA}"
|
|
docker buildx imagetools create --tag "$candidate" "${IMAGE_NAME}@${amd64}" "${IMAGE_NAME}@${arm64}"
|
|
docker buildx imagetools inspect "$candidate" --raw | jq -e '[.manifests[].platform | .os + "/" + .architecture] | sort == ["linux/amd64","linux/arm64"]'
|
|
docker buildx imagetools inspect "$candidate" > "$RUNNER_TEMP/candidate-inspect.txt"
|
|
digest="$(awk '$1 == "Digest:" {print $2; exit}' "$RUNNER_TEMP/candidate-inspect.txt")"
|
|
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]
|
|
echo "digest=$digest" >> "$GITHUB_OUTPUT"
|
|
echo "image=${IMAGE_NAME}@${digest}" >> "$GITHUB_OUTPUT"
|
|
- uses: actions/attest@a1948c3f048ba23858d222213b7c278aabede763 # v4.1.1
|
|
with:
|
|
subject-name: ${{ env.IMAGE_NAME }}
|
|
subject-digest: ${{ steps.index.outputs.digest }}
|
|
push-to-registry: true
|
|
|
|
public-install:
|
|
name: Anonymous published-image install (${{ matrix.arch }})
|
|
needs: [publish]
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- arch: amd64
|
|
runner: ubuntu-latest
|
|
- arch: arm64
|
|
runner: ubuntu-24.04-arm
|
|
runs-on: ${{ matrix.runner }}
|
|
steps:
|
|
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
|
- name: Pull anonymously and verify the install recipe
|
|
env:
|
|
CANDIDATE_IMAGE: ${{ needs.publish.outputs.image }}
|
|
run: |
|
|
mkdir -p "$RUNNER_TEMP/anonymous-docker"
|
|
DOCKER_CONFIG="$RUNNER_TEMP/anonymous-docker" docker pull "$CANDIDATE_IMAGE"
|
|
DOCKER_CONFIG="$RUNNER_TEMP/anonymous-docker" docker pull "$UPGRADE_FROM_IMAGE"
|
|
test "$(docker image inspect "$CANDIDATE_IMAGE" --format '{{.Architecture}}')" = "${{ matrix.arch }}"
|
|
test "$(docker image inspect "$UPGRADE_FROM_IMAGE" --format '{{.Architecture}}')" = "${{ matrix.arch }}"
|
|
bash scripts/compose-smoke.sh "$CANDIDATE_IMAGE" "$GITHUB_SHA" "$UPGRADE_FROM_IMAGE"
|
|
- if: always()
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: published-install-${{ matrix.arch }}
|
|
path: artifacts/compose/
|
|
overwrite: true
|
|
|
|
required:
|
|
name: CI / Required
|
|
if: always()
|
|
needs: [backend, frontend, container, publish, public-install]
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
statuses: write
|
|
steps:
|
|
- name: Require every validation job
|
|
id: gate
|
|
env:
|
|
BACKEND: ${{ needs.backend.result }}
|
|
FRONTEND: ${{ needs.frontend.result }}
|
|
CONTAINER: ${{ needs.container.result }}
|
|
PUBLISH: ${{ needs.publish.result }}
|
|
PUBLIC_INSTALL: ${{ needs.public-install.result }}
|
|
run: |
|
|
test "$BACKEND" = success -a "$FRONTEND" = success -a "$CONTAINER" = success
|
|
if [[ "$GITHUB_EVENT_NAME" == push ]]; then
|
|
test "$PUBLISH" = success -a "$PUBLIC_INSTALL" = success
|
|
fi
|
|
- name: Attach dispatched validation to the exact commit
|
|
if: always() && github.event_name == 'workflow_dispatch'
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GATE_RESULT: ${{ steps.gate.outcome }}
|
|
run: |
|
|
state=failure
|
|
if [ "$GATE_RESULT" = success ]; then
|
|
state=success
|
|
fi
|
|
gh api --method POST "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
|
|
-f state="$state" -f context='CI / Required' \
|
|
-f description='Backend, frontend and native platform validation' \
|
|
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
|
|
--silent
|