Skip to content

Commit 2b8fe7b

Browse files
authored
Merge pull request #2 from premtsd-code/feature/github-actions-cicd
Feature/GitHub actions cicd
2 parents ac74db4 + 78f113b commit 2b8fe7b

File tree

8 files changed

+1045
-1515
lines changed

8 files changed

+1045
-1515
lines changed

.github/dependabot.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
8+
- package-ecosystem: docker
9+
directory: /
10+
schedule:
11+
interval: weekly
12+
13+
- package-ecosystem: maven
14+
directory: /api-gateway
15+
schedule:
16+
interval: weekly
17+
18+
- package-ecosystem: maven
19+
directory: /user-service
20+
schedule:
21+
interval: weekly
22+
23+
- package-ecosystem: maven
24+
directory: /post-service
25+
schedule:
26+
interval: weekly
27+
28+
- package-ecosystem: maven
29+
directory: /connections-service
30+
schedule:
31+
interval: weekly
32+
33+
- package-ecosystem: maven
34+
directory: /notification-service
35+
schedule:
36+
interval: weekly
37+
38+
- package-ecosystem: maven
39+
directory: /uploader-service
40+
schedule:
41+
interval: weekly

.github/pull_request_template.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Description
2+
<!-- What does this PR do? -->
3+
4+
## Type of change
5+
- [ ] Bug fix
6+
- [ ] New feature
7+
- [ ] Breaking change
8+
- [ ] Documentation update
9+
10+
## Services affected
11+
- [ ] api-gateway
12+
- [ ] user-service
13+
- [ ] post-service
14+
- [ ] connections-service
15+
- [ ] notification-service
16+
- [ ] uploader-service
17+
- [ ] config-server
18+
- [ ] discovery-server
19+
20+
## Testing done
21+
- [ ] Unit tests added/updated
22+
- [ ] Integration tests added/updated
23+
- [ ] Manually tested on DEV
24+
25+
## Checklist
26+
- [ ] Tests pass locally
27+
- [ ] Coverage above 70%
28+
- [ ] No hardcoded credentials
29+
- [ ] Flyway migration added if schema changed
30+
- [ ] Swagger annotations added for new endpoints
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Develop CI/CD
2+
3+
on:
4+
push:
5+
branches: [develop]
6+
7+
jobs:
8+
9+
detect-changes:
10+
name: Detect Changed Services
11+
runs-on: ubuntu-latest
12+
outputs:
13+
api-gateway: ${{ steps.changes.outputs.api-gateway }}
14+
user-service: ${{ steps.changes.outputs.user-service }}
15+
post-service: ${{ steps.changes.outputs.post-service }}
16+
connections-service: ${{ steps.changes.outputs.connections-service }}
17+
notification-service: ${{ steps.changes.outputs.notification-service }}
18+
uploader-service: ${{ steps.changes.outputs.uploader-service }}
19+
config-server: ${{ steps.changes.outputs.config-server }}
20+
discovery-server: ${{ steps.changes.outputs.discovery-server }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: dorny/paths-filter@v3
24+
id: changes
25+
with:
26+
filters: |
27+
api-gateway:
28+
- 'api-gateway/**'
29+
user-service:
30+
- 'user-service/**'
31+
post-service:
32+
- 'post-service/**'
33+
connections-service:
34+
- 'connections-service/**'
35+
notification-service:
36+
- 'notification-service/**'
37+
uploader-service:
38+
- 'uploader-service/**'
39+
config-server:
40+
- 'config-server/**'
41+
discovery-server:
42+
- 'discovery-server/**'
43+
44+
build-and-push:
45+
name: Build and Push Images
46+
runs-on: ubuntu-latest
47+
needs: detect-changes
48+
strategy:
49+
matrix:
50+
service:
51+
- { name: api-gateway, changed: "${{ needs.detect-changes.outputs.api-gateway }}" }
52+
- { name: user-service, changed: "${{ needs.detect-changes.outputs.user-service }}" }
53+
- { name: post-service, changed: "${{ needs.detect-changes.outputs.post-service }}" }
54+
- { name: connections-service, changed: "${{ needs.detect-changes.outputs.connections-service }}" }
55+
- { name: notification-service, changed: "${{ needs.detect-changes.outputs.notification-service }}" }
56+
- { name: uploader-service, changed: "${{ needs.detect-changes.outputs.uploader-service }}" }
57+
- { name: config-server, changed: "${{ needs.detect-changes.outputs.config-server }}" }
58+
- { name: discovery-server, changed: "${{ needs.detect-changes.outputs.discovery-server }}" }
59+
steps:
60+
- uses: actions/checkout@v4
61+
if: matrix.service.changed == 'true'
62+
- name: Set up JDK 17
63+
if: matrix.service.changed == 'true'
64+
uses: actions/setup-java@v4
65+
with:
66+
java-version: '17'
67+
distribution: 'corretto'
68+
cache: maven
69+
- name: Build service
70+
if: matrix.service.changed == 'true'
71+
run: cd ${{ matrix.service.name }} && mvn package -DskipTests
72+
- name: Login to DockerHub
73+
if: matrix.service.changed == 'true'
74+
uses: docker/login-action@v3
75+
with:
76+
username: ${{ secrets.DOCKER_USER }}
77+
password: ${{ secrets.DOCKER_PASS }}
78+
- name: Build and push image
79+
if: matrix.service.changed == 'true'
80+
uses: docker/build-push-action@v5
81+
with:
82+
context: ./${{ matrix.service.name }}
83+
platforms: linux/amd64
84+
push: true
85+
tags: |
86+
premtsd18/${{ matrix.service.name }}:develop
87+
premtsd18/${{ matrix.service.name }}:develop-${{ github.sha }}
88+
89+
deploy-dev:
90+
name: Deploy to DEV
91+
runs-on: ubuntu-latest
92+
needs: build-and-push
93+
environment: development
94+
steps:
95+
- name: Deploy to Hetzner DEV
96+
uses: appleboy/ssh-action@master
97+
with:
98+
host: ${{ secrets.HETZNER_IP }}
99+
username: ${{ secrets.HETZNER_USER }}
100+
key: ${{ secrets.HETZNER_SSH_KEY }}
101+
script: |
102+
cd ~/personal/linkedin
103+
git pull origin develop
104+
docker compose pull
105+
docker compose up -d --remove-orphans
106+
docker image prune -f
107+
- name: Health check
108+
run: |
109+
sleep 30
110+
curl -f http://${{ secrets.HETZNER_IP }}:10000/actuator/health
111+
echo "DEV deployment successful ✅"
112+
- name: Rollback on failure
113+
if: failure()
114+
uses: appleboy/ssh-action@master
115+
with:
116+
host: ${{ secrets.HETZNER_IP }}
117+
username: ${{ secrets.HETZNER_USER }}
118+
key: ${{ secrets.HETZNER_SSH_KEY }}
119+
script: |
120+
cd ~/personal/linkedin
121+
docker compose up -d
122+
echo "Rolled back ✅"

.github/workflows/pr-checks.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: PR Checks
2+
3+
on:
4+
pull_request:
5+
branches: [develop, main]
6+
7+
jobs:
8+
9+
detect-changes:
10+
name: Detect Changed Services
11+
runs-on: ubuntu-latest
12+
outputs:
13+
api-gateway: ${{ steps.changes.outputs.api-gateway }}
14+
user-service: ${{ steps.changes.outputs.user-service }}
15+
post-service: ${{ steps.changes.outputs.post-service }}
16+
connections-service: ${{ steps.changes.outputs.connections-service }}
17+
notification-service: ${{ steps.changes.outputs.notification-service }}
18+
uploader-service: ${{ steps.changes.outputs.uploader-service }}
19+
config-server: ${{ steps.changes.outputs.config-server }}
20+
discovery-server: ${{ steps.changes.outputs.discovery-server }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: dorny/paths-filter@v3
24+
id: changes
25+
with:
26+
filters: |
27+
api-gateway:
28+
- 'api-gateway/**'
29+
user-service:
30+
- 'user-service/**'
31+
post-service:
32+
- 'post-service/**'
33+
connections-service:
34+
- 'connections-service/**'
35+
notification-service:
36+
- 'notification-service/**'
37+
uploader-service:
38+
- 'uploader-service/**'
39+
config-server:
40+
- 'config-server/**'
41+
discovery-server:
42+
- 'discovery-server/**'
43+
44+
unit-tests:
45+
name: Unit Tests
46+
runs-on: ubuntu-latest
47+
continue-on-error: true
48+
steps:
49+
- uses: actions/checkout@v4
50+
- name: Set up JDK 17
51+
uses: actions/setup-java@v4
52+
with:
53+
java-version: '17'
54+
distribution: 'corretto'
55+
cache: maven
56+
- name: Run unit tests
57+
run: |
58+
if [ -f "pom.xml" ]; then
59+
mvn test -DskipIntegrationTests=true || true
60+
else
61+
echo "No root pom.xml found — skipping tests"
62+
fi
63+
- name: Upload test results
64+
uses: actions/upload-artifact@v4
65+
if: always()
66+
continue-on-error: true
67+
with:
68+
name: unit-test-results
69+
path: '**/target/surefire-reports/*.xml'
70+
71+
code-coverage:
72+
name: Code Coverage
73+
runs-on: ubuntu-latest
74+
continue-on-error: true
75+
steps:
76+
- uses: actions/checkout@v4
77+
- name: Set up JDK 17
78+
uses: actions/setup-java@v4
79+
with:
80+
java-version: '17'
81+
distribution: 'corretto'
82+
cache: maven
83+
- name: Run tests with coverage
84+
run: |
85+
if [ -f "pom.xml" ]; then
86+
mvn verify jacoco:report -DskipIntegrationTests=true || true
87+
else
88+
echo "No root pom.xml — skipping coverage"
89+
fi
90+
- name: Upload coverage report
91+
uses: actions/upload-artifact@v4
92+
continue-on-error: true
93+
with:
94+
name: coverage-report
95+
path: '**/target/site/jacoco/'
96+
97+
security-scan:
98+
name: Security Scan
99+
runs-on: ubuntu-latest
100+
continue-on-error: true
101+
steps:
102+
- uses: actions/checkout@v4
103+
- name: Set up JDK 17
104+
uses: actions/setup-java@v4
105+
with:
106+
java-version: '17'
107+
distribution: 'corretto'
108+
cache: maven
109+
- name: OWASP Dependency Check
110+
run: |
111+
if [ -f "pom.xml" ]; then
112+
mvn dependency-check:check \
113+
-DfailBuildOnCVSS=7 \
114+
-DskipTestScope=true || true
115+
else
116+
echo "No root pom.xml — skipping OWASP"
117+
fi
118+
continue-on-error: true
119+
- name: Upload OWASP report
120+
uses: actions/upload-artifact@v4
121+
if: always()
122+
continue-on-error: true
123+
with:
124+
name: owasp-report
125+
path: '**/target/dependency-check-report.html'
126+
127+
code-quality:
128+
name: Code Quality
129+
runs-on: ubuntu-latest
130+
continue-on-error: true
131+
steps:
132+
- uses: actions/checkout@v4
133+
with:
134+
fetch-depth: 0
135+
- name: Set up JDK 17
136+
uses: actions/setup-java@v4
137+
with:
138+
java-version: '17'
139+
distribution: 'corretto'
140+
cache: maven
141+
- name: Checkstyle
142+
run: |
143+
if [ -f "pom.xml" ]; then
144+
mvn checkstyle:check || true
145+
else
146+
echo "No root pom.xml — skipping checkstyle"
147+
fi
148+
continue-on-error: true
149+
- name: SpotBugs
150+
run: |
151+
if [ -f "pom.xml" ]; then
152+
mvn spotbugs:check || true
153+
else
154+
echo "No root pom.xml — skipping spotbugs"
155+
fi
156+
continue-on-error: true

0 commit comments

Comments
 (0)