diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 1e4961b..3f2e700 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -24,6 +24,10 @@ jobs: uses: actions/setup-node@v4 with: node-version: '24' + - name: Enable Corepack (for Yarn) + uses: actions/setup-node@v4 + with: + node-version: '24' - name: Enable Corepack (for Yarn) run: corepack enable - name: Install dependencies @@ -43,20 +47,20 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: driver-opts: | image=moby/buildkit:latest - + - name: Login to Container Registry uses: docker/login-action@v3 with: registry: registry.bk.glpx.pro username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - + - name: Build and push frontend uses: docker/build-push-action@v5 with: @@ -82,43 +86,58 @@ jobs: POSTGRES_DB: postgres steps: - uses: actions/checkout@v4 - - name: Start PostgreSQL with PostGIS - run: | - # Stop any existing PostgreSQL containers - docker stop postgres-test 2>/dev/null || true - docker rm postgres-test 2>/dev/null || true - - # Start PostgreSQL with PostGIS - docker run -d \ - --name postgres-test \ - -e POSTGRES_USER=turash \ - -e POSTGRES_PASSWORD=turash123 \ - -e POSTGRES_DB=postgres \ - -p 5432:5432 \ - postgis/postgis:16-3.4 - - echo "PostgreSQL container started, waiting for it to be ready..." - # Wait for PostgreSQL to be ready - for i in {1..60}; do - if docker exec postgres-test pg_isready -U turash >/dev/null 2>&1; then - echo "✓ PostgreSQL is ready!" - # Grant CREATEDB privilege (required for pgtestdb) - docker exec postgres-test psql -U turash -d postgres -c "ALTER USER turash CREATEDB;" 2>/dev/null || true - exit 0 - fi - echo "Waiting for PostgreSQL... (attempt $i/60)" - sleep 2 - done - - echo "✗ PostgreSQL failed to start in time" - echo "Container logs:" - docker logs postgres-test || true - exit 1 - name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.25.3' cache: true + + - name: Install PostgreSQL + run: | + echo "Installing PostgreSQL for tests..." + + # Update package list + apt-get update + + # Install PostgreSQL and PostGIS + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + postgresql \ + postgresql-contrib \ + postgresql-postgis \ + postgresql-client \ + sudo + + # Start PostgreSQL service + systemctl start postgresql || service postgresql start + + # Wait for PostgreSQL to be ready + for i in {1..30}; do + if pg_isready -h localhost -p 5432 >/dev/null 2>&1; then + echo "✓ PostgreSQL is ready!" + break + fi + echo "Waiting for PostgreSQL... (attempt $i/30)" + sleep 2 + done + + # Check if PostgreSQL is actually ready + if ! pg_isready -h localhost -p 5432 >/dev/null 2>&1; then + echo "✗ PostgreSQL failed to start" + systemctl status postgresql || service postgresql status + journalctl -u postgresql -n 20 || true + exit 1 + fi + + # Create test user and database + sudo -u postgres psql -c "CREATE USER turash WITH PASSWORD 'turash123';" 2>/dev/null || true + sudo -u postgres psql -c "ALTER USER turash CREATEDB;" 2>/dev/null || true + sudo -u postgres psql -c "CREATE DATABASE postgres OWNER turash;" 2>/dev/null || true + + # Enable PostGIS + sudo -u postgres psql -d postgres -c "CREATE EXTENSION IF NOT EXISTS postgis;" 2>/dev/null || true + + echo "✓ PostgreSQL setup complete" + - name: Install CGO dependencies (for race detector) id: cgo-setup run: | @@ -153,7 +172,7 @@ jobs: echo "⚠ No supported package manager found (apt-get, apk, yum, dnf)" echo "⚠ gcc installation skipped - race detector will be disabled" fi - + # Verify installation if command -v gcc &> /dev/null || [ -f /usr/bin/gcc ]; then echo "✓ gcc successfully installed" @@ -165,6 +184,7 @@ jobs: fi echo "cgo_available=$CGO_AVAILABLE" >> $GITHUB_OUTPUT continue-on-error: true + - name: Install dependencies working-directory: bugulma/backend run: go mod download @@ -173,6 +193,7 @@ jobs: CGO_ENABLED: 1 GOPROXY: https://proxy.golang.org,direct GOSUMDB: sum.golang.org + - name: Tidy and verify modules working-directory: bugulma/backend run: | @@ -183,6 +204,7 @@ jobs: CGO_ENABLED: 0 GOPROXY: https://proxy.golang.org,direct GOSUMDB: sum.golang.org + - name: Verify module setup working-directory: bugulma/backend run: | @@ -196,6 +218,7 @@ jobs: CGO_ENABLED: 0 GOPROXY: https://proxy.golang.org,direct GOSUMDB: sum.golang.org + - name: Build module to populate cache working-directory: bugulma/backend run: go build ./... @@ -204,6 +227,7 @@ jobs: CGO_ENABLED: 0 GOPROXY: https://proxy.golang.org,direct GOSUMDB: sum.golang.org + - name: Vet working-directory: bugulma/backend run: go vet ./... @@ -212,22 +236,37 @@ jobs: CGO_ENABLED: 0 GOPROXY: https://proxy.golang.org,direct GOSUMDB: sum.golang.org + - name: Test working-directory: bugulma/backend run: | # Check if CGO is available for race detector CGO_AVAILABLE="${{ steps.cgo-setup.outputs.cgo_available || '0' }}" + + # Build test command + TEST_CMD="go test -v" + + # Add race detector if CGO is available if [ "$CGO_AVAILABLE" = "1" ] && command -v gcc &> /dev/null; then echo "Running tests with race detector..." - CGO_ENABLED=1 go test -v -race -coverprofile=coverage.out ./... + TEST_CMD="$TEST_CMD -race" + export CGO_ENABLED=1 else echo "Running tests without race detector (CGO not available)..." - CGO_ENABLED=0 go test -v -coverprofile=coverage.out ./... + export CGO_ENABLED=0 fi + + # Add coverage + TEST_CMD="$TEST_CMD -coverprofile=coverage.out" + + # Run all tests + echo "Running all tests..." + $TEST_CMD ./... env: GO111MODULE: on GOPROXY: https://proxy.golang.org,direct GOSUMDB: sum.golang.org + - name: Coverage working-directory: bugulma/backend run: go tool cover -html=coverage.out -o coverage.html @@ -239,20 +278,20 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: driver-opts: | image=moby/buildkit:latest - + - name: Login to Container Registry uses: docker/login-action@v3 with: registry: registry.bk.glpx.pro username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - + - name: Build and push backend uses: docker/build-push-action@v5 with: @@ -286,4 +325,3 @@ jobs: - name: Run E2E tests working-directory: bugulma/frontend run: yarn test:e2e --headed=false - diff --git a/.gitea/workflows/ci.yml.backup b/.gitea/workflows/ci.yml.backup new file mode 100644 index 0000000..b87a7b2 --- /dev/null +++ b/.gitea/workflows/ci.yml.backup @@ -0,0 +1,319 @@ +name: CI/CD Pipeline + +on: + push: + branches: + - master + paths: + - 'bugulma/**' + - 'k8s/**' + - '.gitea/workflows/**' + pull_request: + branches: + - master + paths: + - 'bugulma/**' + - 'k8s/**' + +jobs: + frontend-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + - name: Enable Corepack (for Yarn) + run: corepack enable + - name: Install dependencies + working-directory: bugulma/frontend + run: yarn install --immutable + - name: Lint + working-directory: bugulma/frontend + run: yarn lint + - name: Test + working-directory: bugulma/frontend + run: yarn test --run + + frontend-build: + runs-on: ubuntu-latest + needs: frontend-lint + if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/master' + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: | + image=moby/buildkit:latest + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: registry.bk.glpx.pro + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push frontend + uses: docker/build-push-action@v5 + with: + context: bugulma/frontend + file: bugulma/frontend/Dockerfile + push: true + tags: | + registry.bk.glpx.pro/turash/turash-frontend:latest + registry.bk.glpx.pro/turash/turash-frontend:${{ gitea.sha }} + cache-from: type=registry,ref=registry.bk.glpx.pro/turash/turash-frontend:buildcache + cache-to: type=registry,ref=registry.bk.glpx.pro/turash/turash-frontend:buildcache,mode=max + platforms: linux/amd64 + build-args: | + BUILDKIT_INLINE_CACHE=1 + + backend-lint: + runs-on: ubuntu-latest + env: + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + POSTGRES_USER: turash + POSTGRES_PASSWORD: turash123 + POSTGRES_DB: postgres + steps: + - uses: actions/checkout@v4 + - name: Setup PostgreSQL for tests + id: postgres-setup + run: | + echo "Attempting to setup PostgreSQL for tests..." + + # Check if Docker is available + if ! command -v docker >/dev/null 2>&1; then + echo "⚠ Docker is not available in this environment" + echo "⚠ Database-dependent tests will be skipped" + echo "skip_db_tests=true" >> $GITHUB_OUTPUT + exit 0 + fi + + # Stop any existing PostgreSQL containers + docker stop postgres-test 2>/dev/null || true + docker rm postgres-test 2>/dev/null || true + + # Start PostgreSQL with PostGIS + if docker run -d \ + --name postgres-test \ + -e POSTGRES_USER=turash \ + -e POSTGRES_PASSWORD=turash123 \ + -e POSTGRES_DB=postgres \ + -p 5432:5432 \ + postgis/postgis:16-3.4; then + + echo "PostgreSQL container started, waiting for it to be ready..." + # Wait for PostgreSQL to be ready + for i in {1..60}; do + if docker exec postgres-test pg_isready -U turash >/dev/null 2>&1; then + echo "✓ PostgreSQL is ready!" + # Grant CREATEDB privilege (required for pgtestdb) + docker exec postgres-test psql -U turash -d postgres -c "ALTER USER turash CREATEDB;" 2>/dev/null || true + echo "skip_db_tests=false" >> $GITHUB_OUTPUT + exit 0 + fi + echo "Waiting for PostgreSQL... (attempt $i/60)" + sleep 2 + done + + echo "✗ PostgreSQL failed to start in time" + docker logs postgres-test || true + else + echo "✗ Failed to start PostgreSQL container" + fi + + echo "skip_db_tests=true" >> $GITHUB_OUTPUT + exit 0 + continue-on-error: true + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.25.3' + cache: true + - name: Install CGO dependencies (for race detector) + id: cgo-setup + run: | + echo "Checking for gcc (required for race detector)..." + CGO_AVAILABLE=0 + # Check if gcc is already available + if command -v gcc &> /dev/null; then + echo "✓ gcc is already available" + gcc --version + CGO_AVAILABLE=1 + else + echo "gcc not found, attempting to install..." + # Detect package manager and install gcc + if command -v apt-get &> /dev/null; then + echo "Using apt-get (Debian/Ubuntu)..." + if [ "$(id -u)" -eq 0 ]; then + apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq build-essential && CGO_AVAILABLE=1 || true + else + (sudo apt-get update -qq && DEBIAN_FRONTEND=noninteractive sudo apt-get install -y -qq build-essential && CGO_AVAILABLE=1) || \ + (apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq build-essential && CGO_AVAILABLE=1) || true + fi + elif command -v apk &> /dev/null; then + echo "Using apk (Alpine)..." + apk add --no-cache gcc musl-dev && CGO_AVAILABLE=1 || true + elif command -v yum &> /dev/null; then + echo "Using yum (RHEL/CentOS)..." + yum install -y gcc && CGO_AVAILABLE=1 || true + elif command -v dnf &> /dev/null; then + echo "Using dnf (Fedora)..." + dnf install -y gcc && CGO_AVAILABLE=1 || true + else + echo "⚠ No supported package manager found (apt-get, apk, yum, dnf)" + echo "⚠ gcc installation skipped - race detector will be disabled" + fi + + # Verify installation + if command -v gcc &> /dev/null || [ -f /usr/bin/gcc ]; then + echo "✓ gcc successfully installed" + gcc --version || /usr/bin/gcc --version + CGO_AVAILABLE=1 + else + echo "⚠ gcc installation failed - race detector will be disabled" + fi + fi + echo "cgo_available=$CGO_AVAILABLE" >> $GITHUB_OUTPUT + continue-on-error: true + - name: Install dependencies + working-directory: bugulma/backend + run: go mod download + env: + GO111MODULE: on + CGO_ENABLED: 1 + GOPROXY: https://proxy.golang.org,direct + GOSUMDB: sum.golang.org + - name: Tidy and verify modules + working-directory: bugulma/backend + run: | + go mod tidy + go mod verify + env: + GO111MODULE: on + CGO_ENABLED: 0 + GOPROXY: https://proxy.golang.org,direct + GOSUMDB: sum.golang.org + - name: Verify module setup + working-directory: bugulma/backend + run: | + pwd + ls -la go.mod + go list -m + # Verify all packages can be listed + go list ./... + env: + GO111MODULE: on + CGO_ENABLED: 0 + GOPROXY: https://proxy.golang.org,direct + GOSUMDB: sum.golang.org + - name: Build module to populate cache + working-directory: bugulma/backend + run: go build ./... + env: + GO111MODULE: on + CGO_ENABLED: 0 + GOPROXY: https://proxy.golang.org,direct + GOSUMDB: sum.golang.org + - name: Vet + working-directory: bugulma/backend + run: go vet ./... + env: + GO111MODULE: on + CGO_ENABLED: 0 + GOPROXY: https://proxy.golang.org,direct + GOSUMDB: sum.golang.org + - name: Test + working-directory: bugulma/backend + run: | + # Check if CGO is available for race detector + CGO_AVAILABLE="${{ steps.cgo-setup.outputs.cgo_available || '0' }}" + + # Build test command + TEST_CMD="go test -v" + + # Add race detector if CGO is available + if [ "$CGO_AVAILABLE" = "1" ] && command -v gcc &> /dev/null; then + echo "Running tests with race detector..." + TEST_CMD="$TEST_CMD -race" + export CGO_ENABLED=1 + else + echo "Running tests without race detector (CGO not available)..." + export CGO_ENABLED=0 + fi + + # Add coverage + TEST_CMD="$TEST_CMD -coverprofile=coverage.out" + + # Run all tests + echo "Running all tests..." + $TEST_CMD ./... + env: + GO111MODULE: on + GOPROXY: https://proxy.golang.org,direct + GOSUMDB: sum.golang.org + - name: Coverage + working-directory: bugulma/backend + run: go tool cover -html=coverage.out -o coverage.html + + backend-build: + runs-on: ubuntu-latest + needs: backend-lint + if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/master' + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: | + image=moby/buildkit:latest + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: registry.bk.glpx.pro + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push backend + uses: docker/build-push-action@v5 + with: + context: bugulma/backend + file: bugulma/backend/Dockerfile + push: true + tags: | + registry.bk.glpx.pro/turash/turash-backend:latest + registry.bk.glpx.pro/turash/turash-backend:${{ gitea.sha }} + cache-from: type=registry,ref=registry.bk.glpx.pro/turash/turash-backend:buildcache + cache-to: type=registry,ref=registry.bk.glpx.pro/turash/turash-backend:buildcache,mode=max + platforms: linux/amd64 + build-args: | + BUILDKIT_INLINE_CACHE=1 + + e2e-test: + runs-on: ubuntu-latest + needs: [frontend-build, backend-build] + if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + - name: Enable Corepack (for Yarn) + run: corepack enable + - name: Install dependencies + working-directory: bugulma/frontend + run: yarn install --immutable + - name: Run E2E tests + working-directory: bugulma/frontend + run: yarn test:e2e --headed=false +