forked from FunkinCrew/Funkin
-
Notifications
You must be signed in to change notification settings - Fork 7
273 lines (257 loc) · 9.48 KB
/
build-game.yml
File metadata and controls
273 lines (257 loc) · 9.48 KB
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
# Builds the game on all platforms, to ensure it compiles on all target platforms.
# This helps to ensure workers focus on the master branch.
name: Build and Upload nightly game builds
on:
workflow_dispatch:
inputs:
build-defines:
type: string
description: Build defines to use
default: '-DGITHUB_BUILD'
save-artifact:
type: boolean
description: Save the build artifact to Github Actions (sends to itch otherwise)
default: false
push:
jobs:
gather-changes:
runs-on: build-set
outputs:
trigger-build: ${{ steps.should-trigger.outputs.result }}
steps:
- name: Checkout repo
uses: funkincrew/ci-checkout@v7.3.3
with:
submodules: false
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ github.ref }}
filters: |
docker:
- '.github/workflows/build-game.yml'
- '**/Dockerfile'
- uses: actions/github-script@v8
id: should-trigger
with:
result-encoding: string
script: |
const { payload } = context
const changes = ${{ steps.filter.outputs.changes }}
const manual = payload?.commits
.some(c => c.message.toLowerCase().replace(/\W/g, " ").includes("docker rebuild"))
console.log({ payload, changes, manual, commits: payload.commits })
return payload.created
|| payload.forced
|| changes.includes("docker")
|| manual
gather-tags:
runs-on: build-set
outputs:
primary: ${{ steps.build-tags.outputs.primary }}
list: ${{ steps.build-tags.outputs.list }}
steps:
- name: Gather build tags
uses: actions/github-script@v7
id: build-tags
with:
script: |
const base = "ghcr.io/funkincrew/build-dependencies"
const default_branch = "rewrite/master"
const ref_path = context.ref.split("/").slice(2)
const ref = ref_path.join("/")
const ref_tag = ref_path.join("-")
const tags = [ref_tag, context.sha]
if (ref === default_branch) tags.push("latest")
console.log([
`ref: ${ref}`,
`default_branch: ${default_branch}`,
`tags: ${tags.join(", ")}`
].join('\n'))
const tag_list = tags
.map(tag => `${base}:${tag}`)
.join("\n")
core.setOutput("primary", ref_tag)
core.setOutput("list", tag_list)
docker-image:
needs: [gather-changes, gather-tags]
if: needs.gather-changes.outputs.trigger-build == 'true'
runs-on: build-set
permissions:
contents: read
packages: write
steps:
- name: Checkout repo
uses: funkincrew/ci-checkout@v7.3.3
with:
submodules: false
- name: Log into GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./build
push: true
tags: ${{ needs.gather-tags.outputs.list }}
labels: |
org.opencontainers.image.description=precooked haxe build dependencies
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.title=${{ github.repository_owner }}/build-dependencies
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ github.sha }}
build-game-on-host:
strategy:
fail-fast: false
matrix:
include:
- target: windows
runs-on: windows
- target: macos
runs-on: macos
# TODO: Install XCode to build iOS
# - target: ios
# runs-on: macos
runs-on:
- ${{ matrix.runs-on }}
defaults:
run:
shell: bash
env:
BUILD_DEFINES: ${{ github.event.inputs.build-defines || '-DGITHUB_BUILD' }}
steps:
- name: Make git happy
run: |
git config --global --replace-all safe.directory $GITHUB_WORKSPACE
- name: Get checkout token
uses: actions/create-github-app-token@v1
id: app_token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PEM }}
owner: ${{ github.repository_owner }}
- name: Checkout repo
uses: funkincrew/ci-checkout@v7.3.3
with:
submodules: 'recursive'
token: ${{ steps.app_token.outputs.token }}
persist-credentials: false
submodule-aliases: |
https://github.com/FunkinCrew/Funkin.assets > https://github.com/FunkinCrew/Funkin-assets-secret
https://github.com/FunkinCrew/Funkin.art > https://github.com/FunkinCrew/Funkin-art-secret
- name: Setup build environment
uses: ./.github/actions/setup-haxe
with:
gh-token: ${{ steps.app_token.outputs.token }}
- name: Setup HXCPP dev commit
run: |
cd .haxelib/hxcpp/git/tools/hxcpp
haxe compile.hxml
cd ../../../../..
- name: Populate .env
run: |
touch .env
grep API_NG_APP_ID .env || echo API_NG_APP_ID=${{ secrets.API_NG_APP_ID }} >> .env
grep API_NG_ENC_KEY .env || echo API_NG_ENC_KEY=${{ secrets.API_NG_ENC_KEY }} >> .env
- name: Build game (windows)
if: ${{ matrix.target == 'windows' }}
run: |
haxelib run lime build windows -v -release $BUILD_DEFINES
timeout-minutes: 120
- name: Build game (unix)
if: ${{ matrix.target != 'windows' }}
run: |
haxelib run lime build ${{ matrix.target }} -v -release --times $BUILD_DEFINES
timeout-minutes: 120
- name: Save build artifact to Github Actions
if: ${{ github.event.inputs.save-artifact }}
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.target }}
path: export/release/${{matrix.target}}/bin/
- name: Upload build artifacts
uses: ./.github/actions/upload-itch
with:
butler-key: ${{ secrets.BUTLER_API_KEY}}
target: ${{ matrix.target }}
build-game-in-container:
needs: [gather-tags, docker-image]
if: ${{ ! cancelled() }}
runs-on: build-set
container: ghcr.io/funkincrew/build-dependencies:${{ needs.gather-tags.outputs.primary }}
strategy:
matrix:
include:
- target: linux
- target: html5
# - target: android
defaults:
run:
shell: bash
env:
BUILD_DEFINES: ${{ github.event.inputs.build-defines || '-DGITHUB_BUILD' }}
steps:
- name: Get checkout token
uses: actions/create-github-app-token@v1
id: app_token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PEM }}
owner: ${{ github.repository_owner }}
- name: Checkout repo
uses: funkincrew/ci-checkout@v7.3.3
with:
submodules: 'recursive'
token: ${{ steps.app_token.outputs.token }}
persist-credentials: false
submodule-aliases: |
https://github.com/FunkinCrew/Funkin.assets > https://github.com/FunkinCrew/Funkin-assets-secret
https://github.com/FunkinCrew/Funkin.art > https://github.com/FunkinCrew/Funkin-art-secret
- name: Config haxelib
run: |
haxelib --never newrepo
echo "HAXEPATH=$(haxelib config)" >> "$GITHUB_ENV"
- name: Restore cached dependencies
id: cache-hmm
uses: actions/cache@v4
with:
path: .haxelib
key: haxe-hmm-${{ runner.os }}-${{ hashFiles('**/hmm.json') }}
- if: ${{ steps.cache-hmm.outputs.cache-hit != 'true' }}
name: Install dependencies
run: |
git config --global 'url.https://x-access-token:${{ steps.app_token.outputs.token }}@github.com/.insteadOf' https://github.com/
git config --global advice.detachedHead false
haxelib --global run hmm install -q
cd .haxelib/hxcpp/git/tools/hxcpp && haxe compile.hxml
- if: ${{ matrix.target != 'html5' }}
name: Restore hxcpp cache
uses: actions/cache@v4
with:
path: /usr/share/hxcpp
key: haxe-hxcpp-${{ runner.os }}-${{ github.ref_name }}-${{ github.sha }}
restore-keys: haxe-hxcpp-${{ runner.os }}-${{ github.ref_name }}
- name: Populate .env
run: |
touch .env
grep API_NG_APP_ID .env || echo API_NG_APP_ID=${{ secrets.API_NG_APP_ID }} >> .env
grep API_NG_ENC_KEY .env || echo API_NG_ENC_KEY=${{ secrets.API_NG_ENC_KEY }} >> .env
- name: Build game
run: |
haxelib run lime build ${{ matrix.target }} -v -release --times $BUILD_DEFINES
timeout-minutes: 120
- name: Save build artifact to Github Actions
if: ${{ github.event.inputs.save-artifact }}
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.target }}
path: export/release/${{matrix.target}}/bin/
- name: Upload build artifacts
uses: ./.github/actions/upload-itch
with:
butler-key: ${{ secrets.BUTLER_API_KEY}}
target: ${{ matrix.target }}