-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (121 loc) · 4.8 KB
/
docker-ci.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
# Workflow 이름은 구별이 가능할 정도로 자유롭게 적어주어도 된다.
# 필수 옵션은 아니다.
name: Java CI with Gradle
# main 브랜치에 PR 이벤트가 발생하면 Workflow가 실행된다.
# 브랜치 구분이 없으면 on: [pull_request]로 해주어도 된다.
on:
pull_request:
branches: [ "develop" ]
# 테스트 결과 작성을 위해 쓰기권한 추가
permissions:
checks: write
pull-requests: write
# Job 실행
jobs:
build:
runs-on: ubuntu-22.04
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: synergy_db
MYSQL_USER: rivkode
MYSQL_PASSWORD: ${{ secrets.MYSQL_DB_PASSWORD }}
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_DB_PASSWORD }}
ports:
- 3306:3306
redis:
image: redis:latest
ports:
- 6379:6379
mongodb:
image: mongo:4.4.6
env:
MONGO_INITDB_ROOT_USERNAME: rivkode
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_DB_PASSWORD }}
MONGO_INITDB_DATABASE: synergy_db
ports:
- 27017:27017
options: >-
--health-cmd mongo
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: 레포지토리 체크아웃
uses: actions/checkout@v4
# - name: 기본 MySQL 종료 (SUDO 필요)
# run: sudo service mysql stop # 기본 MySQL 종료
- name: JDK 17 설치
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# - name: MySQL 설치
# uses: mirromutth/mysql-action@v1
# with:
# mysql version: '8.0' # Optional, default value is "latest". The version of the MySQL
# mysql database: synergy_db # Optional, default value is "test". The specified database which will be create
# mysql user: rivkode # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Of course you can use secrets, too
# mysql password: ${{ secrets.MYSQL_DB_PASSWORD }}
- name: Wait for MySQL
run: |
while ! mysqladmin ping --host=127.0.0.1 --password=$DB_PASSWORD --silent; do
sleep 1
done
- name: Install mongosh
run: |
sudo apt-get install gnupg
wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-7.0.asc
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-mongosh
mongosh --version
- name: Initalize MongoDB
run: |
mongosh --host localhost:27017 -u rivkode -p ${{ secrets.MONGO_DB_PASSWORD }} --authenticationDatabase admin <<EOF
db = db.getSiblingDB('APP-DB');
db.createUser({ user: 'rivkode', pwd: ${{ secrets.MONGO_DB_PASSWORD }} , roles: [{ role: 'readWrite', db: 'APP-DB' }] })
db.createCollection('APP-COLLECTION');
EOF
# Do whatever you like in here
- name: properties 파일 생성
run: |
cd ./src/main
mkdir resources
cd ./resources
touch ./application.properties
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./application.properties
- name: Verify application.properties
run: cat ./src/main/resources/application.properties
shell: bash
- name: Verify MySQL is running
run: sudo netstat -tlnp | grep 3306
# gradle 실행 허가
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: 빌드 진행
run: ./gradlew build -x test
- name: 테스트 코드 실행
run: ./gradlew --info test
- name: 테스트 결과 PR에 코멘트 작성
uses: EnricoMi/publish-unit-test-result-action@v2
if: always() # 테스트가 실패했을때만 or 테스트가 성공했을때만 알려주기(여기선 둘다!)
with:
files: |
**/build/test-results/**/*.xml
# Files changed에서 어디에서 잘못되었는지 가르쳐준다.
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'