-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (76 loc) · 2.59 KB
/
Copy pathci-cd.yml
File metadata and controls
94 lines (76 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: CI/CD Pipeline
on:
push:
branches: [ "main", "develop" ]
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
build-test:
runs-on: ubuntu-latest
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
cache: maven
- name: Build and test
run: mvn -B clean verify -Dspring.profiles.active=test
- name: Cache Sonar packages
if: ${{ env.SONAR_TOKEN != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: SonarQube Cloud analysis
if: ${{ env.SONAR_TOKEN != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
-Dspring.profiles.active=test
-Dsonar.qualitygate.wait=true
- name: Upload JAR
uses: actions/upload-artifact@v4
with:
name: app-jar
path: target/*.jar
docker:
needs: build-test
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment: Test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download JAR
uses: actions/download-artifact@v4
with:
name: app-jar
path: target
- name: Verify JAR exists
run: ls -la target
- name: Login Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set image tag
run: echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/ordermanagement:latest \
-t ${{ secrets.DOCKERHUB_USERNAME }}/ordermanagement:${IMAGE_TAG} .
- name: Push image
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/ordermanagement:latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/ordermanagement:${IMAGE_TAG}