-
Notifications
You must be signed in to change notification settings - Fork 36
274 lines (245 loc) · 10 KB
/
build_and_deploy.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
name: Build and deploy
on:
push:
branches:
- develop
- master
pull_request:
branches:
- develop
jobs:
build_test_and_upload:
env:
BUILD_ENVIRONMENT_IS_CI_OR_LOCAL: "CI"
runs-on: ubuntu-22.04
container: ghcr.io/giganticminecraft/seichiassist-builder:1a64049
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Prepare build dependencies cache
uses: actions/cache@v3
env:
cache-name: cache-build-dependencies
cache-version: v-5
with:
# sbt等は$HOMEではなくユーザーディレクトリを見ているようで、
# GH Actionsでの ~ は /github/home/ に展開されるにもかかわらず
# 実際のキャッシュは /root/ 以下に配備される。
#
# /root/.ivy/cache, /root/.sbt - sbt関連のキャッシュ
# /root/.m2 - ビルドログを観察した感じprotoc等はここを利用する
# /root/.cache - cousierがscalasbt等をキャッシュするのに使っている
path: |
/root/.ivy2/cache
/root/.sbt
/root/.m2
/root/.cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-${{ github.ref }}-${{ hashFiles('**/build.sbt') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-${{ github.ref }}-
${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-
- name: Prepare build cache
if: github.ref != 'refs/heads/master'
uses: actions/cache@v3
env:
cache-name: cache-build
cache-version: v-5
with:
path: |
target
project/target
project/project/target
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-${{ github.ref }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-${{ github.ref }}-
${{ runner.os }}-build-${{ env.cache-name }}-${{ env.cache-version }}-
# CIでのcheckoutはファイルのタイムスタンプをチェックアウト時刻に設定するため、
# そのままビルドするとlocalDependenciesにあるjarに変更が行われたと見なされ
# 不要なインクリメンタルコンパイルが走る
# タイムスタンプをコミット時刻に設定することでこれが回避できる
- name: Restore localDependencies' timestamps
# 参考: https://qiita.com/tomlla/items/219cea9dd071c8a9e147
run: |
for jar in localDependencies/*.jar; do
timestamp=`git log -1 --pretty=format:'%cd' --date=format:'%Y%m%d%H%M.%S' $jar`
touch -t "$timestamp" $jar
done
# scalapbは.protoの再コンパイルの必要性を判定する際にタイムスタンプを見ているから、コミット時刻に合わせる
- name: Restore protocol timestamps
## 参考: https://qiita.com/tomlla/items/219cea9dd071c8a9e147
run: |
for proto in protocol/*.proto; do
timestamp=`git log -1 --pretty=format:'%cd' --date=format:'%Y%m%d%H%M.%S' $proto`
touch -t "$timestamp" $proto
done
- name: Check format with Scalafmt
run: sbt scalafmtCheckAll
- name: Run reviewdog for Scalafmt
uses: ./.github/actions/run-reviewdog
if: ${{ (github.event_name == 'pull_request') && failure() }}
with:
reviewdog-name: scalafmt
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run scalafix check
# cf. https://scalacenter.github.io/scalafix/docs/users/installation.html#enforce-in-ci
run: sbt "scalafix --check"
- name: Annotate scalafix diagnostics with reviewdog
uses: ./.github/actions/run-reviewdog
if: ${{ (github.event_name == 'pull_request') && failure() }}
with:
reviewdog-name: scalafix
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Test and build artifact
run: sbt assembly
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: SeichiAssist-build
path: target/build/SeichiAssist.jar
- name: Clean build artifact for caching target folder
run: rm -r target/build
- name: Notify discord webhook
uses: sarisia/actions-status-discord@v1
if: always()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: "ビルド+テスト+アップロード"
description: "テスト及びビルドをし、アーティファクトをアップロードする"
username: GitHub Actions
avatar_url: ${{ secrets.DISCORD_AVATAR_URL }}
output-sha:
name: 最終コミットのSHA値を取得する
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.output-sha.outputs.sha }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Outputs the value
id: output-sha
run: |
VALUE=$(git log --format='%h' -n 1)
echo "sha=$VALUE" >> $GITHUB_OUTPUT
shell: bash
create_prerelease:
name: GitHub ReleasesにPreReleaseを作成する
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
needs:
- build_test_and_upload
- output-sha
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Create and push a tag
id: tag-name
run: |
TAG_NAME=sha-${{ needs.output-sha.outputs.sha }}
git tag $TAG_NAME
git push origin $TAG_NAME
echo "value=$TAG_NAME" >> $GITHUB_OUTPUT
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: SeichiAssist-build
id: download
- name: Create release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: ./SeichiAssist.jar
tag_name: ${{ steps.tag-name.outputs.value }}
draft: false
prerelease: true
push_artifact_to_debug_server_definition:
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/develop'
needs:
- build_test_and_upload
- output-sha
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: SeichiAssist-build
id: download
- name: Inspect artifact
run: du -h --max-depth=2 ${{ steps.download.outputs.download-path }}
- name: Extract default config
run: |
cd ${{ steps.download.outputs.download-path }}
mkdir SeichiAssist
cd SeichiAssist
jar xf ../SeichiAssist.jar config.yml
# 二回pushするのを防ぐため、gitコマンドを直操作している
- name: Push jar and config.yml
run: |
API_TOKEN_GITHUB=${{ secrets.SERVER_DEFINITION_REPOSITORY_PUSH_TOKEN }}
user_name=${{ secrets.SERVER_DEFINITION_REPOSITORY_PUSH_USER }}
destination_folder=debug-servers/services/spigot/files/base/plugins
short_sha=${{ needs.output-sha.outputs.sha }}
commit_url=https://github.com/GiganticMinecraft/SeichiAssist/commit/$GITHUB_SHA
git clone --depth 1 \
https://$user_name:[email protected]/GiganticMinecraft/seichi_servers \
server_definition
cd server_definition
git config user.name "$user_name"
git config user.email "${{ secrets.SERVER_DEFINITION_REPOSITORY_PUSH_EMAIL }}"
cp -f \
${{ steps.download.outputs.download-path }}/SeichiAssist.jar \
$destination_folder
(git add . && git commit \
-m "[SeichiAssist] jarを自動更新する ($short_sha)" \
-m "$commit_url") || true
cp -f \
${{ steps.download.outputs.download-path }}/SeichiAssist/config.yml \
$destination_folder/SeichiAssist
(git add . && git commit \
-m "[SeichiAssist] config.ymlを自動更新する ($short_sha)" \
-m "$commit_url") || true
git push origin master
- name: Notify debug-server update to discord
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_DEBUG_SERVER_NOTIFICATION_WEBHOOK }}
title: "デバッグサーバーへデプロイ"
description: "deb_s1等にプラグインを配置しました。30分程度で再起動します。"
username: GitHub Actions
noprefix: true
avatar_url: ${{ secrets.DISCORD_AVATAR_URL }}
deploy_artifact_to_production:
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/master'
needs:
- build_test_and_upload
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: SeichiAssist-build
id: download
- name: Inspect artifact
run: du -h --max-depth=2 ${{ steps.download.outputs.download-path }}
- name: Write SSH key to a file
run: |
mkdir -p ~/.ssh
echo "${{ secrets.PRODUCTION_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: Deploy to staging environment
run: |
scp -v -oStrictHostKeyChecking=no \
-P ${{ secrets.PRODUCTION_PORT }} \
${{ steps.download.outputs.download-path }}/SeichiAssist.jar \
"${{ secrets.PRODUCTION_USERNAME }}@${{ secrets.PRODUCTION_HOST }}:${{ secrets.PRODUCTION_REMOTE_DIR }}"
- name: Notify discord webhook
uses: sarisia/actions-status-discord@v1
if: always()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: "本番サーバーへデプロイ"
description: "s1、s2等の本番環境にプラグインを配置する"
username: GitHub Actions
avatar_url: ${{ secrets.DISCORD_AVATAR_URL }}