DevOps ‐ Continuous Integration (CI) - iNineBD/Track-5Sem2025Main GitHub Wiki

🎯 Objective

This documentation describes the structure of the Continuous Integration (CI) process in the Frontend and Backend of the Track project. The pipeline is configured using GitHub Actions and aims to ensure code quality, run automated tests, build the application, and analyze it with SonarCloud.


🧩 Summary



FRONTEND



⚙️ CI Structure - Frontend

The CI structure in the frontend is divided into two main files:

  • main.yml — Executed in pull requests for the main branches (main, sprint-*).
  • vueci.yml — Executed on every push to the development branches (feature/**, fix/**, hotfix/**, release/**).

Both workflows use:

  • Node.js 18.x
  • NPM for dependencies
  • Automated tests
  • ESLint + Prettier
  • SonarCloud (only in main.yml)

🔍 Workflows - Frontend

Below are the two Continuous Integration (CI) workflows used in the frontend, explaining how they work and with a summary of the main differences between them:

🟢 main.yml — Build, Test and SonarCloud

name: Build, Test and SonarCloud

on:
  pull_request:
    branches:
      - 'main'
      - 'sprint-1'
      - 'sprint-2'
      - 'sprint-3'
 
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x] # Versão LTS recomendada para Nuxt 3

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Isso garante que o clone seja completo e com o histórico completo de commits

      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install dependencies
        run: npm install --no-package-lock

      - name: Run tests with coverage
        run: npm run test:coverage

      - name: Build application
        run: npm run build

Runs on pull requests for main branches. Steps:

  1. Checkout the repository with full history (fetch-depth: 0)
  2. Setup Node.js with version 18.x
  3. Install dependencies (npm install --no-package-lock)
  4. Run tests with coverage (npm run test:coverage)
  5. Build the application (npm run build)

📌 Trigger: pull_request on the branches main, sprint-1, sprint-2, sprint-3.


🧹 vueci.yml — Lint + Prettier + Test

name: Lint+Prettier

on:
  push:
    branches:
        - 'feature/**'
        - 'fix/**'
        - 'hotfix/**'
        - 'release/**'

jobs:
  lint:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 18.x

      - name: Install dependencies
        run: npm install --no-package-lock

      - name: Run ESLint with auto fix
        run: npm run lint:fix

      - name: Build application
        run: npm run build

      - name: Run tests and generate coverage
        run: |
          npm run test:coverage

Runs every push on development branches. Steps:

  1. Repository checkout
  2. Node.js setup with version 18.x
  3. Installation of dependencies (npm install --no-package-lock)
  4. Execution of ESLint with auto-fixation (npm run lint:fix)
  5. Build of the application (npm run build)
  6. Execution of tests and generation of coverage (npm run test:coverage)

📌 Trigger: push on branches feature/**, fix/**, hotfix/**, release/**.


📋 Workflow Summary - Frontend

Archive Event (on) Monitored Branches Executed Steps
main.yml pull_request main, sprint-1, sprint-2, sprint-3 Checkout, Setup Node, Install, Tests with coverage, Build
vueci.yml push feature/**, fix/**, hotfix/**, release/** Checkout, Setup Node, Install, ESLint (auto-fix), Build, Tests + Coverage

✅ Considerations - Frontend

  • The two workflows complement each other:
  • main.yml ensures quality before merges.
  • vueci.yml allows for quick local validations on development branches.


BACKEND



⚙️ CI Structure - Backend

The CI structure in the backend is also divided into two main files:

  • main.yml — Executed on pull requests to the main branches (main, sprint-*).
  • goci.yml — Executed on each push to the development branches (feature/**, fix/**, hotfix/**, release/**).

Both workflows use:

  • Go 1.22.1
  • Tests with coverage
  • GolangCI-Lint
  • Build the application

🔍 Workflows - Backend

Below are the two Continuous Integration (CI) workflows used in the backend, explaining how they work and with a summary of the main differences between them:

🟢 main.yml — Build, Test and SonarCloud Analysis

name: Build, Test and SonarCloud Analysis

on:
  pull_request:
    branches:
      - main
      - sprint-1
      - sprint-2
      - sprint-3

jobs:
  build-and-test:
    name: Build and Test
    runs-on: ubuntu-latest

    steps: # Faz checkout do repositório
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Go # Configura o ambiente Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.22.1'

      - name: Cache Go modules # Faz cache dos módulos do Go
        uses: actions/cache@v4
        with:
          path: |
            ~/go/pkg/mod
            ~/.cache/go-build
          key: ${{ runner.os }}-go-${{ hashFiles('src/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: Download Go dependencies # Baixa as dependências Go
        working-directory: src
        run: |
          if [ ! -f go.sum ]; then
            go mod tidy
          fi
          go mod download

      - name: Create .env file # Cria arquivo .env na raiz do projeto.
        working-directory: src
        run: |
          echo "DB_USER=${{ secrets.DB_USER }}" > ../.env
          echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ../.env
          echo "DB_HOST=${{ secrets.DB_HOST }}" >> ../.env
          echo "DB_PORT=${{ secrets.DB_PORT }}" >> ../.env
          echo "DB_NAME=${{ secrets.DB_NAME }}" >> ../.env
          echo "DB_SCHEMA=${{ secrets.DB_SCHEMA }}" >> ../.env

      - name: Create .env file in service # Cria arquivo .env no pacote service
        working-directory: src/pkg/service
        run: |
          echo "DB_USER=${{ secrets.DB_USER }}" > .env
          echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
          echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
          echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env
          echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
          echo "DB_SCHEMA=${{ secrets.DB_SCHEMA }}" >> .env

      - name: Verify .env file (debug) # Verifica criação do .env (debug)
        working-directory: src
        run: |
          ls -la ../
          cat ../.env

      - name: Run tests with coverage and generate reports # Roda os testes e gera relatórios em .out, .html e .xml
        working-directory: src
        run: |
          # Cria o diretório coverage_report na raiz do projeto
          mkdir -p coverage_report

          # Executa os testes e gera o arquivo de cobertura, ignorando modelos e DTO
          go test $(go list ./... | grep -v '/models' | grep -v '/dto' | grep -v '_test.go') -coverprofile=../coverage_report/coverage.out -covermode=atomic \
            -coverpkg=./... \
            -cover \
            -run=. \
            -tags=integration \
            -vet=off

      - name: Upload coverage report # Faz upload dos relatórios de cobertura como artefato
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: coverage_report/coverage.out

      - name: Build application # Builda a aplicação
        working-directory: src
        run: go build -v ./...

Executed on pull requests for main branches. Steps:

  1. Checkout of the repository
  2. Setup of Go with version 1.22.1
  3. Cache and download of dependencies
  4. Installation of dependencies (go mod tidy and go mod download)
  5. Creation of .env files with secrets
  6. Execution of tests with coverage and generation of coverage.out
  7. Upload of the coverage report
  8. Build of the application (go build -v ./...)

📌 Trigger: pull_request on the branches main, sprint-1, sprint-2, sprint-3


🧹 goci.yml — GolangCI-Lint and Quick Tests

name: GolangCI-Lint and Quick Tests

on:
  push:
    branches:
      - 'fix/**'
      - 'feature/**'
      - 'hotfix/**'
      - 'release/**'
      
jobs:
  lint:
    name: Run GolangCI-Lint
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository # Faz checkout do repositório
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # Necessário para o GolangCI-Lint analisar o histórico

      - name: Set up Go # Configura o ambiente Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.22.1'
          cache: false # Desabilita o cache interno do setup-go (vamos usar manual)

      - name: Cache Go Modules # Cache dos módulos Go
        uses: actions/cache@v4
        with:
          path: |
            ~/go/pkg/mod
            ~/.cache/go-build
          key: ${{ runner.os }}-go-${{ hashFiles('src/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: Install GolangCI-Lint # Instala o GolangCI-Lint
        run: |
          curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.8
          echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

      - name: Format code with gofmt # Formata o código com gofmt
        working-directory: src
        run: go fmt ./...

      - name: Ensure Go Modules # Garante que os módulos Go estão em ordem
        working-directory: src
        run: go mod tidy -v

      - name: Run GolangCI-Lint # Executa o linter GolangCI
        working-directory: src
        run: golangci-lint run ./...

  quick-test: #Teste rápido para push e validação do programa e alterações.
    name: Build and Basic Tests with Coverage
    runs-on: ubuntu-latest
    needs: lint

    steps:
      - name: Checkout repository # Faz checkout do repositório
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 #  para analise de cobertura

      - name: Set up Go # Configura ambiente Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.22.1'

      - name: Cache Go modules # Cache dos módulos Go
        uses: actions/cache@v4
        with:
          path: |
            ~/go/pkg/mod
            ~/.cache/go-build
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: Download Go dependencies # Baixa dependências Go
        working-directory: src
        run: |
          if [ ! -f go.sum ]; then
            go mod tidy
          fi
          go mod download

      - name: Create .env file # Cria o arquivo .env na raiz do projeto
        working-directory: src
        run: |
          echo "DB_USER=${{ secrets.DB_USER }}" > ../.env
          echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ../.env
          echo "DB_HOST=${{ secrets.DB_HOST }}" >> ../.env
          echo "DB_PORT=${{ secrets.DB_PORT }}" >> ../.env
          echo "DB_NAME=${{ secrets.DB_NAME }}" >> ../.env
          echo "DB_SCHEMA=${{ secrets.DB_SCHEMA }}" >> ../.env

      - name: Create .env file in service # Cria o arquivo .env no pacote service
        working-directory: src/pkg/service
        run: |
          echo "DB_USER=${{ secrets.DB_USER }}" > .env
          echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
          echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
          echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env
          echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
          echo "DB_SCHEMA=${{ secrets.DB_SCHEMA }}" >> .env

      # Builda aplicação Go
      - name: Build application
        working-directory: src
        run: go build -v ./...

Executed every push on development branches. Steps:

  1. Repository checkout with full history (fetch-depth: 0)
  2. Go setup with version 1.22.1 (no setup-go internal cache)
  3. Go module cache
  4. GolangCI-Lint installation with version 1.64.8
  5. Code formatting with go fmt ./...
  6. Execution of golangci-lint run

📌 Trigger: push on branches feature/**, fix/**, hotfix/**, release/**


📋 Workflow Summary - Backend

File Event (on) Monitored Branches Executed Steps
main.yml pull_request main, sprint-1, sprint-2, sprint-3 Checkout, Setup Go, Cache, .env, Tests with coverage, Build
goci.yml push feature/**, fix/**, hotfix/**, release/** Checkout, Setup Go, Cache, golangci-lint, gofmt

✅ Considerations - Backend

  • main.yml ensures tests with coverage and build for validation before merging.
  • vueci.yml performs lint and automated code formatting in development branches.
⚠️ **GitHub.com Fallback** ⚠️