Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/develop-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,33 @@ jobs:
cd ~/personal/linkedin
docker compose up -d
echo "Rolled back ✅"

e2e-tests:
name: E2E Tests
runs-on: ubuntu-latest
needs: deploy-dev
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
cache: maven
- name: Wait for services to be ready
run: |
echo "Waiting for DEV to be ready..."
sleep 30
curl -f http://${{ secrets.HETZNER_IP }}:10000/actuator/health || echo "Health check failed, running tests anyway"
echo "Services ready!"
- name: Run E2E tests
run: |
cd e2e-tests
mvn test -De2e.base.url=http://${{ secrets.HETZNER_IP }}:10000
- name: Upload E2E results
uses: actions/upload-artifact@v4
if: always()
with:
name: e2e-test-results
path: e2e-tests/target/surefire-reports/
135 changes: 63 additions & 72 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,9 @@ on:

jobs:

detect-changes:
name: Detect Changed Services
runs-on: ubuntu-latest
outputs:
api-gateway: ${{ steps.changes.outputs.api-gateway }}
user-service: ${{ steps.changes.outputs.user-service }}
post-service: ${{ steps.changes.outputs.post-service }}
connections-service: ${{ steps.changes.outputs.connections-service }}
notification-service: ${{ steps.changes.outputs.notification-service }}
uploader-service: ${{ steps.changes.outputs.uploader-service }}
config-server: ${{ steps.changes.outputs.config-server }}
discovery-server: ${{ steps.changes.outputs.discovery-server }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
api-gateway:
- 'api-gateway/**'
user-service:
- 'user-service/**'
post-service:
- 'post-service/**'
connections-service:
- 'connections-service/**'
notification-service:
- 'notification-service/**'
uploader-service:
- 'uploader-service/**'
config-server:
- 'config-server/**'
discovery-server:
- 'discovery-server/**'

unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
Expand All @@ -55,23 +19,21 @@ jobs:
cache: maven
- name: Run unit tests
run: |
if [ -f "pom.xml" ]; then
mvn test -DskipIntegrationTests=true || true
else
echo "No root pom.xml found — skipping tests"
fi
for svc in user-service post-service connections-service notification-service uploader-service; do
echo "=== Testing $svc ==="
cd $svc && mvn test -q && cd ..
done
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
continue-on-error: true
with:
name: unit-test-results
path: '**/target/surefire-reports/*.xml'

code-coverage:
name: Code Coverage
runs-on: ubuntu-latest
continue-on-error: true
needs: unit-tests
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
Expand All @@ -82,14 +44,12 @@ jobs:
cache: maven
- name: Run tests with coverage
run: |
if [ -f "pom.xml" ]; then
mvn verify jacoco:report -DskipIntegrationTests=true || true
else
echo "No root pom.xml — skipping coverage"
fi
for svc in user-service post-service connections-service notification-service uploader-service; do
echo "=== Coverage for $svc ==="
cd $svc && mvn test jacoco:report -q && cd ..
done
- name: Upload coverage report
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: coverage-report
path: '**/target/site/jacoco/'
Expand All @@ -108,18 +68,14 @@ jobs:
cache: maven
- name: OWASP Dependency Check
run: |
if [ -f "pom.xml" ]; then
mvn dependency-check:check \
-DfailBuildOnCVSS=7 \
-DskipTestScope=true || true
else
echo "No root pom.xml — skipping OWASP"
fi
continue-on-error: true
for svc in user-service post-service connections-service notification-service uploader-service; do
echo "=== OWASP scan for $svc ==="
cd $svc && mvn dependency-check:check -DfailBuildOnCVSS=7 -DskipTestScope=true || true
cd ..
done
- name: Upload OWASP report
uses: actions/upload-artifact@v4
if: always()
continue-on-error: true
with:
name: owasp-report
path: '**/target/dependency-check-report.html'
Expand All @@ -130,8 +86,6 @@ jobs:
continue-on-error: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand All @@ -140,17 +94,54 @@ jobs:
cache: maven
- name: Checkstyle
run: |
if [ -f "pom.xml" ]; then
mvn checkstyle:check || true
else
echo "No root pom.xml — skipping checkstyle"
fi
continue-on-error: true
for svc in user-service post-service connections-service notification-service uploader-service; do
echo "=== Checkstyle for $svc ==="
cd $svc && mvn checkstyle:check -q || true
cd ..
done
- name: SpotBugs
run: |
if [ -f "pom.xml" ]; then
mvn spotbugs:check || true
else
echo "No root pom.xml — skipping spotbugs"
fi
continue-on-error: true
for svc in user-service post-service connections-service notification-service uploader-service; do
echo "=== SpotBugs for $svc ==="
cd $svc && mvn compile spotbugs:check -q || true
cd ..
done

sonarcloud:
name: SonarCloud Analysis
runs-on: ubuntu-latest
needs: unit-tests
continue-on-error: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
cache: maven
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: SonarCloud Scan
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
for svc in user-service post-service connections-service notification-service uploader-service; do
echo "=== Scanning $svc ==="
cd $svc
mvn verify jacoco:report sonar:sonar -DskipTests \
-Dsonar.projectKey=premtsd-code_LinkedIn_${svc} \
-Dsonar.organization=premtsd-code \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.projectName="${svc}" \
-Dsonar.java.coveragePlugin=jacoco \
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml \
|| true
cd ..
done
78 changes: 76 additions & 2 deletions connections-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<url/>
</scm>
<properties>
<java.version>21</java.version>
<java.version>17</java.version>
<spring-cloud.version>2023.0.3</spring-cloud.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -73,6 +73,21 @@
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>kafka</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
Expand Down Expand Up @@ -122,7 +137,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>1.19.0</version>
<version>1.19.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -164,6 +179,65 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<goals><goal>prepare-agent</goal></goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals><goal>report</goal></goals>
</execution>
<execution>
<id>check</id>
<goals><goal>check</goal></goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.70</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.3.1</version>
<configuration>
<threshold>High</threshold>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>9.0.9</version>
<configuration>
<failBuildOnCVSS>7</failBuildOnCVSS>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.premtsd.linkedin.connectionservice;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
@EnabledIfEnvironmentVariable(named = "DOCKER_AVAILABLE", matches = "true")
class ConnectionsServiceApplicationTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.premtsd.linkedin.connectionservice.integration;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.premtsd.linkedin.connectionservice.entity.Person;
import com.premtsd.linkedin.connectionservice.exception.BusinessRuleViolationException;
import com.premtsd.linkedin.connectionservice.service.ConnectionsService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
import org.springframework.boot.test.context.SpringBootTest;
import com.premtsd.linkedin.connectionservice.controller.ConnectionsController;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;

import java.util.Arrays;
Expand All @@ -20,8 +21,9 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebMvc
@WebMvcTest(ConnectionsController.class)
@AutoConfigureMockMvc(addFilters = false)
@ActiveProfiles("test")
class ConnectionsControllerIntegrationTest {

@Autowired
Expand All @@ -30,9 +32,6 @@ class ConnectionsControllerIntegrationTest {
@MockBean
private ConnectionsService connectionsService;

@Autowired
private ObjectMapper objectMapper;

private static final String X_USER_ID_HEADER = "X-User-Id";

@Test
Expand Down
Loading
Loading