-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (151 loc) · 8.3 KB
/
maven.yml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: POD Booking System Server CI with Maven and SonarCloud
on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main", "develop" ]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
# Generate application.yml from environment variables
- name: Generate application.yml
run: |
mkdir -p src/main/resources
echo "server:" >> src/main/resources/application.yaml
echo " port: 8080" >> src/main/resources/application.yaml
echo "" >> src/main/resources/application.yaml
echo "openapi:" >> src/main/resources/application.yaml
echo " service: " >> src/main/resources/application.yaml
echo " api-docs: api-service" >> src/main/resources/application.yaml
echo " server: \"${{ secrets.SERVER_API_URL }}\"" >> src/main/resources/application.yaml
echo " title: API Service" >> src/main/resources/application.yaml
echo " version: 1.0.0" >> src/main/resources/application.yaml
echo "spring:" >> src/main/resources/application.yaml
echo " datasource:" >> src/main/resources/application.yaml
echo " url: \"${{ secrets.DATABASE_URL }}\"" >> src/main/resources/application.yaml
echo " username: \"${{ secrets.DATABASE_USERNAME }}\"" >> src/main/resources/application.yaml
echo " password: \"${{ secrets.DATABASE_PASSWORD }}\"" >> src/main/resources/application.yaml
echo " driver-class-name: com.mysql.cj.jdbc.Driver" >> src/main/resources/application.yaml
echo " jpa:" >> src/main/resources/application.yaml
echo " hibernate:" >> src/main/resources/application.yaml
echo " ddl-auto: update" >> src/main/resources/application.yaml
echo " naming:" >> src/main/resources/application.yaml
echo " implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl" >> src/main/resources/application.yaml
echo " physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl" >> src/main/resources/application.yaml
echo " show-sql: true" >> src/main/resources/application.yaml
echo " mail:" >> src/main/resources/application.yaml
echo " host: \"${{ secrets.MAIL_HOST }}\"" >> src/main/resources/application.yaml
echo " port: \"${{ secrets.MAIL_PORT }}\"" >> src/main/resources/application.yaml
echo " username: \"${{ secrets.MAIL_USERNAME }}\"" >> src/main/resources/application.yaml
echo " password: \"${{ secrets.MAIL_PASSWORD }}\"" >> src/main/resources/application.yaml
echo " properties:" >> src/main/resources/application.yaml
echo " mail:" >> src/main/resources/application.yaml
echo " smtp:" >> src/main/resources/application.yaml
echo " auth: true" >> src/main/resources/application.yaml
echo " starttls:" >> src/main/resources/application.yaml
echo " enable: true" >> src/main/resources/application.yaml
echo " security:" >> src/main/resources/application.yaml
echo " oauth2:" >> src/main/resources/application.yaml
echo " client:" >> src/main/resources/application.yaml
echo " registration:" >> src/main/resources/application.yaml
echo " google:" >> src/main/resources/application.yaml
echo " client-id: \"${{ secrets.GOOGLE_CLIENT_ID }}\"" >> src/main/resources/application.yaml
echo " client-secret: \"${{ secrets.GOOGLE_CLIENT_SECRET }}\"" >> src/main/resources/application.yaml
echo " scope:" >> src/main/resources/application.yaml
echo " - email" >> src/main/resources/application.yaml
echo " - profile" >> src/main/resources/application.yaml
echo "" >> src/main/resources/application.yaml
echo "jwt:" >> src/main/resources/application.yaml
echo " JWT_SECRET_ACCESS_TOKEN: \"${{ secrets.JWT_SECRET_ACCESS_TOKEN }}\"" >> src/main/resources/application.yaml
echo " JWT_SECRET_REFRESH_TOKEN: \"${{ secrets.JWT_SECRET_REFRESH_TOKEN }}\"" >> src/main/resources/application.yaml
echo "" >> src/main/resources/application.yaml
echo "google:" >> src/main/resources/application.yaml
echo " success: \"${{ secrets.GOOGLE_SUCCESS }}\"" >> src/main/resources/application.yaml
echo " failure: \"${{ secrets.GOOGLE_FAILURE }}\"" >> src/main/resources/application.yaml
echo "vnpay:" >> src/main/resources/application.yaml
echo " tmn-code: \"${{ secrets.VNPAY_TMN_CODE }}\"" >> src/main/resources/application.yaml
echo " hash-secret: \"${{ secrets.VNPAY_HASH_SECRET }}\"" >> src/main/resources/application.yaml
echo " return-url: \"${{ secrets.VNPAY_RETURN_URL }}\"" >> src/main/resources/application.yaml
echo " url: \"${{ secrets.VNPAY_URL }}\"" >> src/main/resources/application.yaml
- name: Build, test and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.jacoco:jacoco-maven-plugin:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=Hoang-Nguyen-Huy_pod-booking-system-server
- name: Build application
run: mvn clean package -DskipTests
- name: Save JAR artifact
uses: actions/upload-artifact@v3
with:
name: pod-booking-system-server
path: target/*.jar
deploy:
name: Deploy to Server
runs-on: ubuntu-22.04
needs: build # Job deploy depend on job build
steps:
- name: Check out code
uses: actions/checkout@v4
# Download the JAR artifact from the previous step
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: pod-booking-system-server
# Ensure JAR is in the context of Docker build
- name: Prepare Docker context
run: |
mkdir -p target
mv pod-booking-system-server-0.0.1-SNAPSHOT.jar target/pod-booking-system-server.jar
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and tag Docker image
run: |
docker build -t hoanghuynguyen/pod-booking-system-server:latest .
- name: Push Docker image to Docker Hub
run: |
docker push hoanghuynguyen/pod-booking-system-server:latest
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd swp
docker pull hoanghuynguyen/pod-booking-system-server:latest
docker compose up -d
# # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
# - name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6