-
Notifications
You must be signed in to change notification settings - Fork 4
120 lines (99 loc) · 3.29 KB
/
develop-cicd-gradle.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
name: Java CI with Gradle and Deploy to Raspberry Pi
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
permissions:
contents: read
checks: write
pull-requests: write
env:
IMAGE_TAG: ${{ github.sha }}
SSH_HOST: ${{ secrets.SSH_HOST }} # GitHub Secrets에서 SSH 호스트 (IP)
SSH_PRIVATE_KEY: ${{ secrets.DEV_SSH_PRIVATE_KEY }} # GitHub Secrets에서 SSH 개인 키
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: true
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/[email protected]
- name: Add +x permission to gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: build-libs
path: build/libs/*.jar
- name: Test Coverage Report
id: jacoco
uses: madrapps/[email protected]
with:
title: 📝 Jacoco Test Coverage
paths: ${{ github.workspace }}/**/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.ACTION_TOKEN }}
min-coverage-overall: 30
min-coverage-changed-files: 50
update-comment: true
- name: Write Test Report
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
comment_title: 🧪 Test Results
files: "**/build/test-results/test/TEST-*.xml"
- name: Comment(Annotation) for Failed Test
uses: mikepenz/action-junit-report@v4
if: always()
with:
report_paths: "**/build/test-results/test/TEST-*.xml"
deploy:
needs: build
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: build-libs
path: build/libs
- name: Build Docker image and generate tar
run: |
docker build -t kumoh_talk:latest .
docker save kumoh_talk:latest | gzip > kumoh_talk.tar.gz
- name: Upload tar.gz as artifact
uses: actions/upload-artifact@v4
with:
name: kumoh_talk-tar
path: kumoh_talk.tar.gz
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEV_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -p 101 -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Send tar.gz file to Raspberry Pi via SCP
run: |
scp -P 101 kumoh_talk.tar.gz admin@${{ secrets.SSH_HOST }}:/home/admin
- name: Unzip and load Docker image on Raspberry Pi
run: |
ssh -p 101 admin@${{ secrets.SSH_HOST }} <<EOF
gunzip -f /home/admin/kumoh_talk.tar.gz
docker load < /home/admin/kumoh_talk.tar
docker compose -f /home/admin/docker-compose.yml up -d
EOF