generated from ayutaz/unity_template_repository
-
-
Notifications
You must be signed in to change notification settings - Fork 27
256 lines (221 loc) · 9.22 KB
/
build.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
name: Run build
on:
workflow_dispatch:
inputs:
build_windows:
description: 'Build for Windows'
required: true
default: true
type: boolean
build_mac:
description: 'Build for macOS'
required: true
default: true
type: boolean
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
schedule:
- cron: '0 0 * * *' # 毎日UTCで午前0時に実行
jobs:
check-branch:
runs-on: ubuntu-latest
outputs:
current_version: ${{ steps.check_branch.outputs.current_version }}
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0 # すべての履歴とタグを取得
- name: Check event type and branch
id: check_branch
run: |
echo "イベント名: ${{ github.event_name }}"
# ProjectSettings.assetから現在のバージョンを取得
current_version=$(grep -m1 'bundleVersion:' ProjectSettings/ProjectSettings.asset | awk '{print $2}')
echo "current_version=${current_version}" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "これはプルリクエストイベントです。"
echo "PRのソースブランチ: ${{ github.head_ref }}"
echo "PRのターゲットブランチ: ${{ github.base_ref }}"
if [ "${{ github.head_ref }}" == "develop" ] && [ "${{ github.base_ref }}" == "main" ]; then
echo "これは 'develop' から 'main' へのPRです。バージョンチェックを実行します。"
# gitからバージョンタグのリストを取得
git fetch --tags
version_tags=$(git tag -l 'v*' | grep -v '^v99\.99\.99$')
echo "既存のバージョンタグ: $version_tags"
# タグからバージョン番号を抽出
versions=()
for tag in $version_tags; do
versions+=("${tag#v}")
done
if [ ${#versions[@]} -eq 0 ]; then
highest_version="0.0.0"
else
highest_version=$(printf '%s\n' "${versions[@]}" | sort -V | tail -n1)
fi
echo "最高の既存バージョン: $highest_version"
# 現在のバージョンと最高の既存バージョンを比較
if [ "$(printf '%s\n' "$highest_version" "$current_version" | sort -V | tail -n1)" != "$current_version" ]; then
echo "エラー: 現在のバージョン ($current_version) は最高の既存バージョン ($highest_version) よりも高くありません。"
exit 1
else
echo "現在のバージョン ($current_version) は最高の既存バージョン ($highest_version) よりも高いです。"
fi
else
echo "これは 'develop' から 'main' へのPRではありません。バージョンチェックをスキップします。"
fi
else
echo "プルリクエストイベントではありません。チェックをスキップします。"
fi
build-windows:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'schedule' || inputs.build_windows }}
needs: [check-branch]
runs-on: windows-latest
steps:
- name: Check out my unity project.
uses: actions/[email protected]
- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/[email protected]
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
- name: Git LFS Pull
run: |
git lfs pull
git add .
git reset --hard
- uses: actions/[email protected]
with:
path: Library
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
restore-keys: |
Library-
- name: Run the build for StandaloneWindows64
uses: game-ci/[email protected]
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
targetPlatform: StandaloneWindows64
unityVersion: '6000.0.31f1'
buildName: 'uDesktopMascot'
versioning: Custom
version: ${{ needs.check-branch.outputs.current_version }}
- name: Update setup.iss
if: ${{ github.event_name != 'pull_request' && github.ref != 'refs/heads/develop' }}
shell: bash
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
# 変更の有無をチェック
if [ -z "$(git status --porcelain setup.iss)" ]; then
echo "setup.issに変更はありません"
exit 0
fi
# ブランチ名を取得
if [ "${{ github.event_name }}" == "pull_request" ]; then
TARGET_BRANCH="${{ github.base_ref }}" # refs/heads/main
SOURCE_BRANCH="${{ github.head_ref }}" # refs/heads/develop
else
TARGET_BRANCH="${{ github.ref }}" # refs/heads/current-branch
SOURCE_BRANCH="${{ github.ref }}"
fi
# refs/heads/プレフィックスを除去
TARGET_BRANCH=${TARGET_BRANCH#refs/heads/}
SOURCE_BRANCH=${SOURCE_BRANCH#refs/heads/}
# 現在の変更をスタッシュに保存
git stash push -u -m "temp setup.iss changes"
# ソースブランチを直接チェックアウト
git fetch origin $SOURCE_BRANCH
git checkout $SOURCE_BRANCH
git pull origin $SOURCE_BRANCH
# スタッシュから変更を復元
git stash pop
git add setup.iss
if ! git diff --cached --quiet; then
git commit -m "Update setup.iss"
git push origin $SOURCE_BRANCH
else
echo "変更が競合解決後に消失しました"
fi
- name: Change build folder name
run: |
cd build
mv "StandaloneWindows64" "uDesktopMascot"
cd ..
- name: Upload the Build for StandaloneWindows64
uses: actions/[email protected]
with:
name: Build-StandaloneWindows64-v${{ needs.check-branch.outputs.current_version }}
path: build/uDesktopMascot
- name: Set up Inno Setup
uses: Minionguyjpro/[email protected]
with:
path: 'setup.iss'
- name: Upload Installer
uses: actions/[email protected]
with:
name: uDesktopMascot_win64_installer_v${{ needs.check-branch.outputs.current_version }}
path: "uDesktopMascot_win64_installer_v${{ needs.check-branch.outputs.current_version }}.exe"
build-mac:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'schedule' || inputs.build_mac }}
needs: [check-branch]
runs-on: macos-latest
steps:
- name: Check out my unity project.
uses: actions/[email protected]
- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/[email protected]
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
- name: Git LFS Pull
run: |
git lfs pull
git add .
git reset --hard
- uses: actions/[email protected]
with:
path: Library
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
restore-keys: |
Library-
- name: Run the build for StandaloneOSX
uses: game-ci/[email protected]
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
targetPlatform: StandaloneOSX
unityVersion: '6000.0.31f1'
buildName: 'uDesktopMascot'
versioning: Custom
version: ${{ needs.check-branch.outputs.current_version }}
- name: Change build folder name
run: |
cd build
mv "StandaloneOSX" "uDesktopMascot"
cd ..
- name: Upload the Build for StandaloneOSX
uses: actions/[email protected]
with:
name: Build-StandaloneOSX-v${{ needs.check-branch.outputs.current_version }}
path: build/uDesktopMascot
- name: Set up Installer
run: |
cd build
productbuild --component uDesktopMascot/uDesktopMascot.app /Applications ./uDesktopMascot_mac_installer_v${{ needs.check-branch.outputs.current_version }}.pkg
- name: Upload Installer
uses: actions/[email protected]
with:
name: uDesktopMascot_mac_installer_v${{ needs.check-branch.outputs.current_version }}
path: build/uDesktopMascot_mac_installer_v${{ needs.check-branch.outputs.current_version }}.pkg