Vai al contenuto

Step 11 — CI/CD con GitHub Actions

Obiettivo: automazione build, test, deploy docs, release.

Workflow inclusi

Workflow Trigger Cosa fa
ci.yml push e PR su main Build + test + JaCoCo + artifact OpenAPI
docs.yml push su main con cambio in docs/ Build MkDocs + deploy GitHub Pages
release.yml tag v*.*.* Build JAR + changelog + GitHub Release
codeql.yml push, PR, schedule weekly SAST Java con CodeQL

CI

.github/workflows/ci.yml (estratto)
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: "21"
          cache: maven
      - run: ./mvnw -B -ntp verify
      - uses: actions/upload-artifact@v4
        with:
          name: jacoco-report
          path: target/site/jacoco/

Docs su GitHub Pages

.github/workflows/docs.yml (estratto)
permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  build:
    steps:
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
          cache: pip
      - run: pip install -r requirements-docs.txt
      - run: mkdocs build --strict
      - uses: actions/upload-pages-artifact@v3
        with:
          path: site/

  deploy:
    needs: build
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - id: deployment
        uses: actions/deploy-pages@v4

Settings → Pages

Imposta Source su GitHub Actions (non gh-pages branch legacy).

Dependabot

.github/dependabot.yml
version: 2
updates:
  - package-ecosystem: maven
    directory: "/"
    schedule:
      interval: weekly
  - package-ecosystem: github-actions
    directory: "/"
    schedule:
      interval: weekly
  - package-ecosystem: pip
    directory: "/"
    schedule:
      interval: monthly

Esercizi

  1. Aggiungi un job CI che pubblica i risultati JUnit con dorny/test-reporter.
  2. Implementa un workflow pr.yml che commenta sul PR la diff di coverage.
  3. Configura branch protection su main (review + checks obbligatori).

Riferimenti nel codice