Skip to content

Add integration tests #255

Add integration tests

Add integration tests #255

Workflow file for this run

name: commit
on:
push:
branches:
- main
pull_request:
permissions:
id-token: write
contents: read
jobs:
linter:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: "1.25.2"
- run: go mod download
- run: go mod verify
- run: go install tool
- uses: golangci/golangci-lint-action@v8
with:
version: v2.5.0
tests:
name: tests-${{ matrix.os }}
runs-on: ${{ matrix.os }}
# Check on all supported GitHub Actions OS
# https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
# https://github.com/actions/runner-images
# https://github.com/actions/partner-runner-images
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- ubuntu-24.04
- ubuntu-22.04-arm
- ubuntu-24.04-arm
- windows-2022
- windows-2025
- macos-14
- macos-15
- macos-26
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: "1.25.2"
- run: go mod download
- run: go test -v ./... -coverprofile=./coverage.txt -covermode=atomic -coverpkg=./...
- name: Archive code coverage results
if: matrix.os == 'ubuntu-24.04'
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: coverage.txt
code_coverage:
if: github.event_name == 'pull_request'
runs-on: ubuntu-24.04
needs: tests
permissions:
contents: read
actions: read
pull-requests: write # write permission needed to comment on PR
steps:
- uses: fgrosse/go-coverage-report@v1.2.0
build:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0 # Required for goreleaser to get git history
- uses: actions/setup-go@v6
with:
go-version: "1.25.2"
- name: Set up QEMU for cross-compilation of Docker images
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Fix Segmentation fault of QEMU - https://github.com/docker/buildx/issues/1170
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -c yes
- run: go mod download
- run: go install tool
- run: go generate ./...
- name: Check for modified files
run: |
if ! git diff --quiet; then
echo "Error: Running 'go generate' modified files. Please commit these changes:"
git diff
exit 1
fi
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
id: goreleaser
with:
distribution: goreleaser
version: "~> v2"
args: release --skip=publish --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test build Docker image (stage-bin)
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: false
platforms: |
linux/arm64
linux/amd64
target: stage-bin
tags: test-build-bin
build-args: |
VERSION=${{ fromJSON(steps.goreleaser.outputs.metadata).version }}
COMMIT=${{ fromJSON(steps.goreleaser.outputs.metadata).commit }}
COMMIT_DATE=${{ fromJSON(steps.goreleaser.outputs.metadata).date }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test build Docker image (stage-release-all-in-one)
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: false
platforms: |
linux/arm64
linux/amd64
target: stage-release-all-in-one
tags: test-build-release
build-args: |
VERSION=${{ fromJSON(steps.goreleaser.outputs.metadata).version }}
COMMIT=${{ fromJSON(steps.goreleaser.outputs.metadata).commit }}
COMMIT_DATE=${{ fromJSON(steps.goreleaser.outputs.metadata).date }}
cache-from: type=gha
cache-to: type=gha,mode=max
nix-build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-24.04
- ubuntu-24.04-arm
- macos-15
- macos-26
steps:
- uses: actions/checkout@v5
- uses: DeterminateSystems/nix-installer-action@v14
with:
determinate: false
- uses: DeterminateSystems/magic-nix-cache-action@v8
with:
use-flakehub: false
- name: Check flake
run: nix flake check --print-build-logs
- name: Build package
run: nix build -L .#default
- name: Run binary version check
run: ./result/bin/any-sync-bundle --version
nix-devshell:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: DeterminateSystems/nix-installer-action@v14
with:
determinate: false
- uses: DeterminateSystems/magic-nix-cache-action@v8
with:
use-flakehub: false
- name: Check dev shell
run: |
nix develop --command go version
nix develop --command golangci-lint version
nix develop --command goreleaser --version
# Integration tests with real MongoDB and Redis
integration-test:
name: integration-test
runs-on: ubuntu-24.04
needs: build
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: "1.25.2"
- name: Start dependencies
run: docker compose -f compose.dev.yml up -d --wait
- name: Build bundle
run: go build -o any-sync-bundle .
- name: Create temp directories
run: mkdir -p ./tmp
- name: Run integration test
run: |
# IMPORTANT: Use temp paths to avoid config reuse between runs
# If bundle-config.yml exists, --initial-* flags are IGNORED
./any-sync-bundle start-bundle \
--bundle-config ./tmp/bundle-config.yml \
--client-config ./tmp/client-config.yml \
--initial-storage ./tmp/storage \
--initial-mongo-uri "mongodb://localhost:27017/?replicaSet=rs0" \
--initial-redis-uri "redis://localhost:6379" \
--initial-external-addrs "127.0.0.1" \
>bundle.log 2>&1 &
PID=$!
# Wait for ready or failure (max 90s)
for i in {1..90}; do
if grep -q "AnySync Bundle is ready!" bundle.log 2>/dev/null; then
echo "SUCCESS: Bundle is ready"
# Verify TCP port is listening
nc -z localhost 33010 || { echo "Port 33010 not listening"; kill $PID; exit 1; }
echo "SUCCESS: TCP port 33010 listening"
# Graceful shutdown
kill -INT $PID
wait $PID 2>/dev/null || true
# Verify shutdown message
grep -q "AnySync Bundle shutdown complete!" bundle.log && echo "SUCCESS: Clean shutdown"
exit 0
fi
# Check if process died
if ! kill -0 $PID 2>/dev/null; then
echo "FAILED: Bundle process died"
cat bundle.log
exit 1
fi
sleep 1
done
echo "FAILED: Timeout waiting for ready"
cat bundle.log
kill $PID 2>/dev/null || true
exit 1
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: bundle-logs
path: bundle.log
- name: Cleanup
if: always()
run: |
docker compose -f compose.dev.yml down -v
rm -rf ./tmp
# Integration test with S3 storage (MinIO)
integration-test-s3:
name: integration-test-s3
runs-on: ubuntu-24.04
needs: integration-test
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: "1.25.2"
- name: Start MongoDB and Redis
run: docker compose -f compose.dev.yml up -d --wait
- name: Start MinIO
run: |
docker run -d --name minio \
-p 9000:9000 -p 9001:9001 \
-e MINIO_ROOT_USER=minioadmin \
-e MINIO_ROOT_PASSWORD=minioadmin \
minio/minio:RELEASE.2025-09-07T16-13-09Z \
server /data --console-address ":9001"
# Wait for MinIO to be ready
for i in {1..30}; do
if curl -sf http://localhost:9000/minio/health/live >/dev/null; then
echo "MinIO ready"
break
fi
sleep 1
done
# Create bucket
docker run --rm --network host \
minio/mc:RELEASE.2025-08-13T08-35-41Z \
sh -c "mc alias set minio http://localhost:9000 minioadmin minioadmin && mc mb minio/anytype-data --ignore-existing"
- name: Build bundle
run: go build -o any-sync-bundle .
- name: Create temp directories
run: mkdir -p ./tmp
- name: Run S3 integration test
env:
AWS_ACCESS_KEY_ID: minioadmin
AWS_SECRET_ACCESS_KEY: minioadmin
run: |
./any-sync-bundle start-bundle \
--bundle-config ./tmp/bundle-config.yml \
--client-config ./tmp/client-config.yml \
--initial-storage ./tmp/storage \
--initial-mongo-uri "mongodb://localhost:27017/?replicaSet=rs0" \
--initial-redis-uri "redis://localhost:6379" \
--initial-external-addrs "127.0.0.1" \
--initial-s3-bucket "anytype-data" \
--initial-s3-endpoint "http://localhost:9000" \
--initial-s3-force-path-style \
>bundle.log 2>&1 &
PID=$!
# Wait for ready
for i in {1..90}; do
if grep -q "AnySync Bundle is ready!" bundle.log 2>/dev/null; then
echo "SUCCESS: Bundle is ready"
# Verify S3 backend was selected (lightnode/anynodes.go:179)
grep -q "using S3 storage backend" bundle.log || { echo "S3 not selected"; exit 1; }
echo "SUCCESS: S3 storage backend selected"
kill -INT $PID
wait $PID 2>/dev/null || true
exit 0
fi
if ! kill -0 $PID 2>/dev/null; then
echo "FAILED: Bundle process died"
cat bundle.log
exit 1
fi
sleep 1
done
echo "FAILED: Timeout"
cat bundle.log
kill $PID 2>/dev/null || true
exit 1
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: bundle-logs-s3
path: bundle.log
- name: Cleanup
if: always()
run: |
docker stop minio 2>/dev/null || true
docker rm minio 2>/dev/null || true
docker compose -f compose.dev.yml down -v
rm -rf ./tmp