Skip to content

Various improvements to testing #1365

Various improvements to testing

Various improvements to testing #1365

Workflow file for this run

name: ci
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
branches:
- main
paths-ignore:
- 'website/**'
- 'docs/**'
- '*.md'
- 'CODEOWNERS'
- 'LICENSE'
push:
branches:
- main
paths-ignore:
- 'website/**'
- 'docs/**'
- '*.md'
- 'CODEOWNERS'
- 'LICENSE'
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-22.04
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- name: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: '1.22'
cache: false
# Use the golang-ci lint action which automattically sets up GHA caching and other things
# Note: There is also a "lint" target in docker-bake.hcl for local linting
# If you make changes to this, please make sure to also update the local linting target
- name: golangci-lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
with:
version: v1.61
args: --timeout=30m
- name: validate generated files
run: |
go generate || exit $?
git diff --exit-code
if [ $? -ne 0 ]; then
echo "::error::Missing updates to generated files. Please run 'go generate' and commit the changes"
exit 1
fi
integration:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
suite:
- Mariner2
- Azlinux3
- Bookworm
- Bullseye
- Bionic
- Focal
- Jammy
- Noble
- Windows
- other
include:
- suite: other
skip: Mariner2|Azlinux3|Bookworm|Bullseye|Bionic|Focal|Jammy|Noble|Windows
# TODO: support diff/merge
# Right now this is handled by the e2e suite, but we can migrate that here.
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: '1.22'
cache: false
- name: Configure dockerd
run: |
set -ex -o pipefail
sudo mkdir -p /etc/docker
jq . <<< '{ "features": {"containerd-snapshotter": true} }' | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker
- name: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup jaeger
run: |
set -e
docker run -d --net=host --restart=always --name jaeger -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:1.62.0
docker0_ip="$(ip -f inet addr show docker0 | grep -Po 'inet \K[\d.]+')"
echo "OTEL_EXPORTER_OTLP_ENDPOINT=http://${docker0_ip}:4318" >> "${GITHUB_ENV}"
echo "OTEL_SERVICE_NAME=dalec-integration-test" >> "${GITHUB_ENV}"
sudo systemctl cat docker
sudo systemctl cat containerd
sudo cat /etc/containerd/config.toml || ok
tmp="$(mktemp)"
echo "[Service]" > "${tmp}"
echo "Environment=\"OTEL_EXPORTER_OTLP_ENDPOINT=http://${docker0_ip}:4318\"" >> "${tmp}"
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo mkdir -p /etc/systemd/system/containerd.service.d
sudo cp "${tmp}" /etc/systemd/system/docker.service.d/otlp.conf
sudo cp "${tmp}" /etc/systemd/system/containerd.service.d/otlp.conf
sudo systemctl daemon-reload
sudo systemctl restart containerd
sudo systemctl restart docker
# Tests currently require buildkit v0.12.0 or higher
# The version of buildkit builtin to moby currently (v24) is too old
# So we need to setup a custom builder.
# - name: Set up builder
# uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
# with:
# driver-opts: |
# network=host
# env.OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318
# env.OTEL_SERVICE_NAME=buildkitd
- name: download deps
run: go mod download
- name: pre-cache worker image
run: |
if [ ! "${TEST_SUITE}" = "other" ]; then
go run ./cmd/ci-build-workers ${TEST_SUITE}
fi
env:
TEST_SUITE: ${{ matrix.suite }}
- name: Run integration tests
run: |
set -ex
if [ -n "${TEST_SUITE}" ] && [ ! "${TEST_SUITE}" = "other" ]; then
run="-run=${TEST_SUITE}"
fi
if [ -n "${TEST_SKIP}" ]; then
skip="-skip=${TEST_SKIP}"
fi
go test -timeout=30m -v -json ${run} ${skip} ./test | go run ./cmd/test2json2gha --slow 120s
env:
TEST_SUITE: ${{ matrix.suite }}
TEST_SKIP: ${{ matrix.skip }}
- name: dump logs
if: failure()
run: sudo journalctl -u docker
- name: Get traces
if: always()
run: |
set -ex
mkdir -p /tmp/reports
curl -sSLf localhost:16686/api/traces?service=${OTEL_SERVICE_NAME} > /tmp/reports/jaeger-tests.json
curl -sSLf localhost:16686/api/traces?service=containerd > /tmp/reports/jaeger-containerd.json
curl -sSLf localhost:16686/api/traces?service=docker > /tmp/reports/jaeger-docker.json
- name: Upload reports
if: always()
uses: actions/upload-artifact@v4
with:
name: integration-test-reports-${{matrix.suite}}
path: /tmp/reports/*
retention-days: 1
unit:
runs-on: ubuntu-22.04
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- name: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: '1.22'
cache: false
- name: download deps
run: go mod download
- name: Run unit tests
run: go test -v --test.short --json ./... | go run ./cmd/test2json2gha
e2e:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
disable_diff_merge: ["1", "0"]
name: "Test E2E (disable diff/merge: ${{ matrix.disable_diff_merge }})"
env:
DALEC_DISABLE_DIFF_MERGE: ${{ matrix.disable_diff_merge }}
FRONTEND_REF: localhost:5000/dalec/frontend
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- name: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# We need to fetch all commits so that we can diff against the base branch
fetch-depth: 0
- name: Expose GitHub tokens for caching
uses: crazy-max/ghaction-github-runtime@b3a9207c0e1ef41f4cf215303c976869d0c2c1c4 # v3.0.0
- name: Setup builder
run: |
# Sometimes the builder runs out of space... so cleanup anything we can first.
docker image prune -a -f
docker run -d --net=host registry
# If diff/merge are enabled we need to use a buildx builder to make sure the feature is supported.
# Otherwise we can just use the default docker builder.
if [ "${DALEC_DISABLE_DIFF_MERGE}" = "0" ]; then
docker buildx create --use --driver-opt network=host
echo FRONTEND_BAKE_TARGET="frontend-ci-full" >> $GITHUB_ENV
echo USE_BUILDX=1 >> $GITHUB_ENV
else
echo DALEC_NO_CACHE_EXPORT="1" >> $GITHUB_ENV
echo DALEC_DISABLE_NESTED="1" >> $GITHUB_ENV
echo FRONTEND_BAKE_TARGET="frontend-ci" >> $GITHUB_ENV
fi
- name: Build frontend image
run: docker buildx bake ${FRONTEND_BAKE_TARGET}
- name: test
run: |
docker buildx bake test
- name: Build go-md2man example in docs
run: |
version=$(cat docs/examples/go-md2man.yml | yq .version)
docker build -t go-md2man:$version -f docs/examples/go-md2man.yml --target=mariner2/rpm --output=_output .
docker build -t go-md2man:$version -f docs/examples/go-md2man.yml --target=mariner2 .
- name: dump logs
if: failure()
run: |
if [ "${USE_BUILDX}" = "1" ]; then
docker logs $(docker ps -lq)
else
sudo journalctl -u docker
fi