Files
mesh/.gitea/workflows/ci.yml
T
waozi 76fe8298ac
Mesh CI and deploy / container (push) Successful in 14m24s
Mesh CI and deploy / checks (push) Failing after 27m14s
Mesh CI and deploy / deploy (push) Skipped
Hold native CI steps until the native dependencies are pushed
The native server compiles only with uncommitted Ziran standard library,
compression and SQLite work, so with the locked toolchain the checks job
and the native release in the deploy job failed and blocked every Go
deploy. The plan lists the missing symbols and how to restore both steps.
2026-11-22 19:10:32 -03:00

345 lines
15 KiB
YAML

name: Mesh CI and deploy
on:
push:
branches: [master]
workflow_dispatch:
schedule:
- cron: '27 4 * * 1'
permissions:
contents: read
concurrency:
group: mesh-production
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
# Every gate that runs on the shared Build slot lives in one job, so each
# push sets up Ziran, generates the Go and builds liboqs once.
checks:
runs-on: build-ubuntu24.04
steps:
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
submodules: recursive
- name: Install workflow validation tools
run: |
python3 -m venv "$RUNNER_TEMP/mesh-validation"
"$RUNNER_TEMP/mesh-validation/bin/pip" install 'PyYAML==6.0.2' 'shellcheck-py==0.11.0.1'
echo "$RUNNER_TEMP/mesh-validation/bin" >> "$GITHUB_PATH"
- name: Test Mesh migration and site
run: |
mkdir -p build/test-tmp
TMPDIR="$PWD/build/test-tmp" python3 -m unittest discover -s scripts -p 'test_mesh*.py'
python3 -B scripts/test_migrate_env.py
python3 -B scripts/test_provision_mesh_site.py
- name: Validate workflow permissions and dependencies
run: |
python3 -B scripts/test_gitea_workflow.py
python3 -B scripts/test_gitea_origin.py
shellcheck deploy/install.sh deploy/rollback.sh
- name: Verify immutable build and deployment policy
run: |
python3 -B scripts/verify_build_inputs.py
python3 -B scripts/test_build_inputs.py
python3 -B scripts/test_check_sarif.py
python3 -B scripts/test_bootstrap_ssh.py
python3 -B scripts/test_deployment_inputs.py
python3 -B scripts/test_deploy_install.py
# The host runner keeps the Go build and module caches. Its job cache
# server is unreachable, and a restore waits out a timeout of minutes.
- uses: https://github.com/actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version-file: go.mod
cache: false
# The shared runner exports the native SDK's GOROOT for other builds.
# Each tool must read the standard library of the Go setup-go installed.
- name: Use the installed Go root
run: |
root=$(dirname "$(dirname "$(readlink -f "$(command -v go)")")")
echo "GOROOT=$root" >> "$GITHUB_ENV"
GOROOT=$root go version
- name: Generate the Go from the Zi sources
uses: ./.gitea/actions/generate
- name: Build the vendored liboqs
uses: ./.gitea/actions/liboqs
- name: Check formatting
run: test -z "$(git ls-files -z '*.go' | xargs -0 gofmt -l)"
- name: Check generated diff hygiene
run: git diff --check
- name: Install golangci-lint
env:
GOLANGCI_LINT_VERSION: "2.14.0"
GOLANGCI_LINT_SHA256: "ab90aeb7b066f92a33415b638a50fe5344bbb75a0d32ad30cc248d88f81032ab"
run: |
curl --fail --location --silent --show-error \
--output "$RUNNER_TEMP/golangci-lint.tar.gz" \
"https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz"
printf '%s %s\n' "$GOLANGCI_LINT_SHA256" "$RUNNER_TEMP/golangci-lint.tar.gz" | sha256sum --check --strict
tar --extract --gzip --file "$RUNNER_TEMP/golangci-lint.tar.gz" --directory "$RUNNER_TEMP"
install -m 0755 "$RUNNER_TEMP/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint" "$RUNNER_TEMP/golangci-lint"
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Lint
run: golangci-lint run --timeout=5m
env:
CGO_ENABLED: "1"
GOFLAGS: "-mod=mod"
CGO_CFLAGS: "-I${{ github.workspace }}/build/liboqs/install/include"
CGO_LDFLAGS: "-L${{ github.workspace }}/build/liboqs/install/lib -loqs"
# One run reports coverage and is the plain test gate.
- name: Test and report coverage
run: |
make test TEST_FLAGS="-coverprofile=coverage.out"
GOFLAGS=-mod=mod go tool cover -func=coverage.out | tail -1
- name: Race test
run: make test GOFLAGS="-mod=mod -race"
- name: Install pinned vulnerability, source and license scanners
env:
CGO_ENABLED: '0'
GOFLAGS: '-mod=mod'
run: |
export GOBIN="$RUNNER_TEMP"
go install golang.org/x/vuln/cmd/[email protected]
go install github.com/securego/gosec/v2/cmd/[email protected]
go install github.com/google/go-licenses/[email protected]
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Scan the generated application packages without cgo
env:
CGO_ENABLED: '0'
GOFLAGS: "-mod=mod"
run: |
test -s server.zi.go
test -s google_play_reconciliation.zi.go
govulncheck -scan=package . ./native
- name: Scan the generated application packages with native cryptography
env:
CGO_ENABLED: '1'
GOFLAGS: "-mod=mod"
CGO_CFLAGS: "-I${{ github.workspace }}/build/liboqs/install/include"
CGO_LDFLAGS: "-L${{ github.workspace }}/build/liboqs/install/lib -loqs"
run: govulncheck -scan=package . ./native
- name: Scan generated Go and check dependency licenses
env:
CGO_ENABLED: '1'
GOFLAGS: '-mod=mod'
CGO_CFLAGS: '-I${{ github.workspace }}/build/liboqs/install/include'
CGO_LDFLAGS: '-L${{ github.workspace }}/build/liboqs/install/lib -loqs'
run: |
gosec -quiet -severity high -confidence high -fmt=sarif -out gosec.sarif . ./native
GOROOT="$(go env GOROOT)" go-licenses check --ignore mesh . ./native
- name: Preserve the source scan report
if: always()
uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: gosec-sarif
path: gosec.sarif
if-no-files-found: error
container:
runs-on: ${{ vars.MESH_CONTAINER_RUNNER || 'build-ubuntu24.04' }}
steps:
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
submodules: recursive
- uses: https://github.com/actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version-file: go.mod
- name: Generate the Go from the Zi sources
uses: ./.gitea/actions/generate
# A cancelled run skips its image cleanup. The runner refuses jobs below
# 2 GiB free in its slot, so earlier job images go before each build.
- name: Remove images of earlier runs
run: |
docker image ls --filter 'reference=mesh:ci-*' --quiet | sort -u | xargs -r docker image rm --force
docker image prune --force
- name: Build container image
run: docker build --pull --build-arg VERSION="ci-$GITHUB_SHA" -t "mesh:ci-$GITHUB_RUN_ID" .
# The CI slice denies private ranges, including Docker's bridge, so a
# published port cannot reach the container. A probe in the container's
# own network namespace reads it over loopback instead.
- name: Verify container starts as a non-root user
env:
EXPECTED_VERSION: ci-${{ github.sha }}
PROBE_IMAGE: busybox:1.37.0@sha256:a7dbc319b1438115a207e11930dc4bb3e643dcb3ec0bdd694bb36cd8fad289ec
run: |
MESH_TOKEN_SECRET_HEX=$(python3 -c 'import secrets; print(secrets.token_hex(32))')
export MESH_TOKEN_SECRET_HEX
container=$(docker run -d --read-only --tmpfs /data:uid=65532,gid=65532,mode=0700 -e MESH_TOKEN_SECRET_HEX -e MESH_DB=/data/test.db -e MESH_ADDR=:8080 "mesh:ci-$GITHUB_RUN_ID")
trap 'docker logs "$container"; docker rm -f "$container"' EXIT
test "$(docker inspect --format '{{.Config.User}}' "$container")" = '65532:65532'
probe() {
docker run --rm --network "container:$container" "$PROBE_IMAGE" wget -q -O - -T 2 "http://127.0.0.1:8080$1"
}
docker pull --quiet "$PROBE_IMAGE"
ready=false
for attempt in $(seq 60); do
if probe /readyz > /dev/null; then
ready=true
break
fi
sleep 1
done
if [ "$ready" != true ]; then
echo 'container did not become ready'
exit 1
fi
probe /api/v1/node | python3 -c 'import json, os, sys; node = json.load(sys.stdin); assert node["build_version"] == os.environ["EXPECTED_VERSION"], node'
docker image rm "$PROBE_IMAGE"
# The action's own setup checks Trivy out from GitHub with the job token,
# which GitHub refuses for a Gitea run, so the pinned release is installed here.
- name: Install the pinned image scanner
env:
TRIVY_VERSION: "0.70.0"
TRIVY_SHA256: "8b4376d5d6befe5c24d503f10ff136d9e0c49f9127a4279fd110b727929a5aa9"
run: |
curl --fail --location --silent --show-error \
--output "$RUNNER_TEMP/trivy.tar.gz" \
"https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz"
printf '%s %s\n' "$TRIVY_SHA256" "$RUNNER_TEMP/trivy.tar.gz" | sha256sum --check --strict
mkdir -p "$RUNNER_TEMP/trivy-bin"
tar --extract --gzip --file "$RUNNER_TEMP/trivy.tar.gz" --directory "$RUNNER_TEMP/trivy-bin" trivy
echo "$RUNNER_TEMP/trivy-bin" >> "$GITHUB_PATH"
- name: Scan image
uses: https://github.com/aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
skip-setup-trivy: 'true'
version: v0.70.0
image-ref: mesh:ci-${{ github.run_id }}
format: sarif
output: trivy-results.sarif
severity: CRITICAL,HIGH
exit-code: '1'
ignore-unfixed: false
limit-severities-for-sarif: true
- name: Preserve the scan report
if: always()
uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: trivy-sarif
path: trivy-results.sarif
if-no-files-found: error
- name: Remove the job image
if: always()
run: docker image rm "mesh:ci-$GITHUB_RUN_ID"
deploy:
needs: [checks, container]
if: >-
github.server_url == 'https://git.waozi.xyz' &&
github.repository == 'ziranlang/mesh' && github.ref == 'refs/heads/master' &&
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
vars.MESH_DEPLOY_READY == 'true' && vars.MESH_DEPLOY_RUNNER != ''
runs-on: ${{ vars.MESH_DEPLOY_RUNNER || 'build-ubuntu24.04' }}
permissions:
contents: read
actions: read
steps:
- name: Verify canonical deployment context
run: |
test "$GITHUB_SERVER_URL" = https://git.waozi.xyz
test "$GITHUB_REPOSITORY" = ziranlang/mesh
test "$GITHUB_REF" = refs/heads/master
case "$GITHUB_EVENT_NAME" in push|workflow_dispatch) ;; *) exit 1 ;; esac
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
submodules: recursive
- uses: https://github.com/actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version-file: go.mod
- name: Generate the Go from the Zi sources
uses: ./.gitea/actions/generate
- name: Verify the pinned native source
id: liboqs
run: python3 -B scripts/verify_deployment_inputs.py pinned-source
- name: Package the exact canonical revision
run: |
test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
test "$(git ls-remote --exit-code origin refs/heads/master | cut -f1)" = "$GITHUB_SHA"
git ls-files -z --recurse-submodules > "$RUNNER_TEMP/mesh-source-files"
find . -maxdepth 1 -type f \( -name '*.zi.go' -o -name '*.zi_test.go' \) \
-print0 >> "$RUNNER_TEMP/mesh-source-files"
tar --null --no-recursion --files-from="$RUNNER_TEMP/mesh-source-files" \
--create --gzip --file="$RUNNER_TEMP/mesh-source.tar.gz"
- name: Publish the source artifact for this attempt
id: origin-artifact
uses: https://github.com/actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: mesh-origin-source-${{ github.run_attempt }}
path: ${{ runner.temp }}/mesh-source.tar.gz
if-no-files-found: error
retention-days: 1
compression-level: 0
- name: Configure SSH
env:
MESH_SSH_KEY: ${{ secrets.MESH_SSH_KEY }}
MESH_SSH_HOST: ${{ secrets.MESH_HOST }}
MESH_SSH_HOST_KEY: ${{ secrets.MESH_SSH_HOST_KEY }}
MESH_SSH_USER: ${{ secrets.MESH_USER }}
run: |
: "${MESH_SSH_KEY:?Missing Mesh origin identity}"
: "${MESH_SSH_HOST:?Missing Mesh origin host}"
: "${MESH_SSH_HOST_KEY:?Missing Mesh origin host key}"
: "${MESH_SSH_USER:?Missing Mesh origin account}"
umask 077
ssh_dir=$(mktemp -d /dev/shm/mesh-deploy-ssh.XXXXXXXX)
printf 'MESH_SSH_DIR=%s\n' "$ssh_dir" >> "$GITHUB_ENV"
printf '%s\n' "$MESH_SSH_KEY" > "$ssh_dir/id_ed25519"
python3 -B scripts/verify_deployment_inputs.py configure-ssh \
--host "$MESH_SSH_HOST" --user "$MESH_SSH_USER" \
--trusted-key "$MESH_SSH_HOST_KEY" --ssh-dir "$ssh_dir"
- name: Deploy the verified Gitea artifact
env:
GITEA_JOB_TOKEN: ${{ secrets.GITEA_TOKEN }}
EXPECTED_LIBOQS_COMMIT: ${{ steps.liboqs.outputs.liboqs_commit }}
EXPECTED_LIBOQS_DIGEST: ${{ steps.liboqs.outputs.liboqs_digest }}
EXPECTED_LIBOQS_ENTRIES: ${{ steps.liboqs.outputs.liboqs_entries }}
ARTIFACT_ID: ${{ steps.origin-artifact.outputs.artifact-id }}
run: |
: "${GITEA_JOB_TOKEN:?Missing short-lived Gitea job identity}"
: "${ARTIFACT_ID:?Missing Gitea artifact ID}"
printf '%s' "$GITEA_JOB_TOKEN" | ssh -F "$MESH_SSH_DIR/config" mesh-origin \
deploy "$GITHUB_RUN_ID" "$GITHUB_RUN_ATTEMPT" "$GITHUB_SHA" \
"$EXPECTED_LIBOQS_COMMIT" "$EXPECTED_LIBOQS_DIGEST" "$EXPECTED_LIBOQS_ENTRIES" "$ARTIFACT_ID"
- name: Remove the job's SSH credentials
if: always()
run: |
if [ -n "${MESH_SSH_DIR:-}" ]; then
rm -rf -- "$MESH_SSH_DIR"
fi