From 69ebce57e9249e50443a4064200cc0cb4d43a687 Mon Sep 17 00:00:00 2001 From: Anton Ovchinnikov Date: Tue, 20 May 2025 23:59:02 +0200 Subject: [PATCH] test: Add basic Github Actions config (#63) * test: Add basic Github Actions config * fix(e2e-tests): handle asynchronous port publishing for ucind container * fix(e2e-tests): increase machine ready wait timeout 1->10s * fix: Pin GHA versions --------- Co-authored-by: Pavel Sviderski --- .github/workflows/go-tests.yml | 36 ++++++++++++++++++++++++++++++++++ Makefile | 12 ++++++++++++ internal/ucind/machine.go | 7 ++----- scripts/docker/entrypoint.sh | 2 +- 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/go-tests.yml diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml new file mode 100644 index 00000000..8ee00618 --- /dev/null +++ b/.github/workflows/go-tests.yml @@ -0,0 +1,36 @@ +name: Go Tests + +on: + push: + branches: + - "main" + - "test/**" + - "release/**" + pull_request: + branches: + - main + paths: + - ".github/**" + - "**.go" + - "go.*" + - "Makefile" + - "scripts/**" + - "test/**" +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Set up Go + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + with: + go-version: "1.23.2" + + - name: Install dependencies + run: go mod tidy + + - name: Run tests + run: make test + timeout-minutes: 10 diff --git a/Makefile b/Makefile index e9d3c5e4..78a663b6 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,18 @@ corrosion-multiarch-image-push: ucind-image: docker build -t "$(UCIND_IMAGE)" --target ucind . +.PHONY: ucind-image-push +ucind-image-push: ucind-image + docker push "$(UCIND_IMAGE)" + .PHONY: ucind-multiarch-image-push ucind-multiarch-image-push: docker buildx build --push --platform linux/amd64,linux/arm64 -t "$(UCIND_IMAGE)" --target ucind . + +.PHONY: test +test: + go test -v ./... + +.PHONY: vet +vet: + go vet ./... diff --git a/internal/ucind/machine.go b/internal/ucind/machine.go index 07f4c730..c98fac25 100644 --- a/internal/ucind/machine.go +++ b/internal/ucind/machine.go @@ -160,10 +160,7 @@ func (p *Provisioner) waitPortPublished(ctx context.Context, containerID string, } binding, ok := c.NetworkSettings.Ports[port] - if !ok { - return nil, fmt.Errorf("port '%s' not published", port) - } - if len(binding) > 0 { + if ok && len(binding) > 0 { return binding, nil } @@ -196,7 +193,7 @@ func WaitMachineReady(ctx context.Context, m Machine, timeout time.Duration) err boff := backoff.WithContext(backoff.NewExponentialBackOff( backoff.WithInitialInterval(100*time.Millisecond), - backoff.WithMaxInterval(1*time.Second), + backoff.WithMaxInterval(10*time.Second), backoff.WithMaxElapsedTime(timeout), ), ctx) diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.sh index f2a1a64e..61b698b1 100755 --- a/scripts/docker/entrypoint.sh +++ b/scripts/docker/entrypoint.sh @@ -6,7 +6,7 @@ cleanup() { echo "Terminating container processes..." # Terminate the main process if it has been started. - if [ -n "$MAIN_PID" ]; then + if [ -n "${MAIN_PID:-}" ]; then kill "$MAIN_PID" 2>/dev/null || true fi