Skip to content

sonarQube properties pour le frontend: Exclure les fichiers spec sino… #4

sonarQube properties pour le frontend: Exclure les fichiers spec sino…

sonarQube properties pour le frontend: Exclure les fichiers spec sino… #4

Workflow file for this run

name: Test and analyse Both Frontend and Backend and then Build and Push Docker Images
# garantir que la CI s'exécute à l'ouverture/màj des PR ainsi que pour les màj importantes des branches principales.
on:
push:
branches:
- main
- develop
pull_request:
jobs:
test-frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: front
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: front/package-lock.json
- run: npm ci
- run: npm run test -- --no-watch --no-progress --browsers=ChromeHeadless --code-coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./front/coverage/bobapp/report-lcovonly.txt
analysis-frontend:
needs: test-frontend
runs-on: ubuntu-latest
defaults:
run:
working-directory: front
steps:
- uses: actions/checkout@v4
- name: Setup Node.js with caching
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: "npm"
cache-dependency-path: front/package-lock.json
- run: npm ci
- name: Ensure coverage directory exists
run: mkdir -p coverage/bobapp
- name: Run tests and generate coverage report
run: npm run test -- --no-watch --no-progress --browsers=ChromeHeadless --code-coverage
- name: List coverage directory
run: ls -la coverage/bobapp
- name: Check if coverage report exists
env:
COVERAGE_REPORT_PATH: ./front/coverage/bobapp/report-lcovonly.txt
run: |
if [ ! -f "$COVERAGE_REPORT_PATH" ]; then
echo "⚠️ Warning: Coverage report not found at $COVERAGE_REPORT_PATH!"
else
echo "Coverage report found at $COVERAGE_REPORT_PATH."
fi
- name: Run Sonar analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: npm run sonar
test-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: "adopt"
java-version: 11
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven and Run Tests
run: |
cd back
mvn clean install
- name: Test Report
uses: phoenix-actions/test-reporting@v8
if: success() || failure()
with:
name: Maven Tests
path: back/target/surefire-reports/TEST-*.xml
reporter: java-junit
analysis-backend:
needs: test-backend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: "adopt"
java-version: 11
- name: Cache SonarQube packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: |
cd back
mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
build-and-push-docker-images:
needs: [test-frontend, test-backend, analysis-backend, analysis-frontend]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: List directory contents
run: ls -la
- name: Build and push frontend Docker image
run: |
cd front # Change le répertoire courant pour accéder au dossier 'front'.
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/bobapp_frontend:latest -f Dockerfile .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/bobapp_frontend:latest
- name: Build and push backend Docker image
run: |
cd back # Change le répertoire courant pour accéder au dossier 'back'.
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/bobapp_backend:latest -f Dockerfile .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/bobapp_backend:latest