-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (114 loc) · 4.59 KB
/
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
name: CI Pipeline
# Event: Pull Request가 test 브랜치로 들어올 때 실행
on:
pull_request:
branches:
- test
env:
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
PULL_REQUEST_URL: ${{ github.event.pull_request.html_url }}
PULL_REQUEST_AUTHOR: ${{ github.event.pull_request.user.login }}
PULL_REQUEST_EVENT_NAME: ${{ github.event_name }}
PULL_REQUEST_LOGS_URL: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}
PULL_REQUEST_COMMIT_URL: ${{ github.event.pull_request.head.repo.html_url }}/commit/${{ github.event.pull_request.head.sha }}
# Jobs: 필요한 Job을 병렬 또는 순차적으로 실행
jobs:
# Build Job
build:
runs-on: ubuntu-latest
steps:
# 1. 리포지토리에서 소스 코드를 체크아웃
- name: Checkout code
uses: actions/checkout@v3
# 2. Gradle 라이브러리 캐싱
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# 3. Java 17 설치
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
# 4. gradlew에 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# 5. 의존성 설치 및 빌드
- name: Build with Gradle
run: ./gradlew build --no-daemon
# 6. 슬랙 채널로 빌드의 성공 또는 실패에 따라 알림 보내기
- name: Slack message with build result
if: always() # 이전의 Step들의 성공과 실패 여부에 상관 없이 항상 실행
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
if_mention: failure,cancelled
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# - name: Slack message with build result
# if: success() || failure()
# uses: slackapi/[email protected]
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
# PULL_REQUEST_JOB_STATUS: ${{ job.status }}
# PULL_REQUEST_JOB_STATUS_COLOR: ${{ job.status == 'success' && vars.COLOR_GREEN || job.status == 'failure' && vars.COLOR_RED || vars.COLOR_ORANGE }}
# with:
# channel-id: C07L4BQTKGE
# payload-file-path: ./slack/ci_slack_message.json
# --- 아래 방법은 버그 발생 ---
# https://github.com/slackapi/slack-github-action/issues/203 참고
# - name: Notify Slack on Success
# if: success() # 이전 스텝이 모두 성공하면 해당 스텝을 실행하는 조건문
# id: slack-success
# uses: slackapi/[email protected]
# with:
# payload-file-path: "./slack/success-payload-content.json" # 미리 정의된 json 파일에 payload를 정의해서 사용가능
# # payload를 json 형태로 직접 제공해서 사용할 수 있다
# # payload는 payload-file-path 보다 높은 우선순위를 가진다
# # payload: |
# # {
# # "key": "value",
# # "foo": "bar"
# # }
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
#
#
# - name: Notify Slack on Failure
# if: failure() # 이전 스텝 중 하나라도 실패하면 해당 스텝을 실행하는 조건문
# id: slack-failure
# uses: slackapi/[email protected]
# with:
# payload-file-path: "./slack/failure-payload-content.json"
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
# Test Job
# 빌드에서 테스트를 진행하기 때문에 해당 Job은 제외해도 된다. 그러나 needs를 설명하기 위해 편의상 추가했다.
# test:
# runs-on: ubuntu-latest
# needs: build # build Job이 완료된 후 실행됨
#
# steps:
# # 기타 설정 과정
# - name: Checkout code
# uses: actions/checkout@v3
#
# - name: Set up JDK 17
# uses: actions/setup-java@v3
# with:
# distribution: 'temurin'
# java-version: '17'
#
# # 7. 테스트 실행
# - name: Run tests
# run: ./gradlew test --no-daemon