This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
forked from media-kit/libmpv-win32-video-build
-
Notifications
You must be signed in to change notification settings - Fork 0
438 lines (414 loc) · 17.3 KB
/
mpv.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
name: MPV
run-name: ${{ inputs.run_name }}
on:
# schedule:
# - cron: '0 12 * * *'
workflow_dispatch:
inputs:
build_target:
description: "Build target"
required: false
default: "all-64bit"
type: choice
options:
- 32bit
- 64bit
- 64bit-v3
- all-64bit
- all
needclean:
description: 'Build without cache'
required: false
default: false
type: boolean
release:
description: "Publish a release"
required: false
default: false
type: boolean
command:
description: 'input command you want to run before build'
required: false
cache_id:
description: 'input cache_id if you want to renew cache'
required: false
run_name:
description: 'The name displayed in the list of workflow runs'
required: false
# Workflow level env does not work properly in all fields.
# https://github.com/actions/runner/issues/480
env:
release: false
jobs:
# https://github.com/actions/runner/issues/480#issuecomment-1055373623
params:
runs-on: ubuntu-latest
outputs:
params: ${{ steps.env-vars.outputs.params }}
matrix: ${{ steps.script.outputs.matrix }}
steps:
- name: Generate cache_id
run: |
if [ "${{ inputs.cache_id }}" ] ; then
echo "cache_id=${{ inputs.cache_id }}" >> $GITHUB_ENV
else
echo "cache_id=$(echo $RANDOM | md5sum | head -c 20)" >> $GITHUB_ENV
fi
- id: script
uses: actions/github-script@v6
with:
script: |
const commit = await github.rest.repos.getCommit({
owner: 'mpv-player',
repo: 'mpv',
ref: `master`
})
core.exportVariable('sha', String(commit.data.sha))
let matrix = {};
let build_target = "${{ inputs.build_target }}"
switch ( build_target ) {
case "32bit":
matrix.bit = ["32"];
break;
case "64bit":
matrix.bit = ["64"];
break;
case "64bit-v3":
matrix.bit = ["64-v3"];
break;
case "all-64bit":
matrix.bit = ["64","64-v3"];
break;
case "all":
matrix.bit = ["32","64","64-v3"];
break;
default:
matrix.bit = ["64","64-v3"];
break;
}
core.setOutput("matrix",JSON.stringify(matrix));
- id: env-vars
name: Output environment variables
run: echo "params=$(echo $(jq -n 'env'))" >> $GITHUB_OUTPUT
build_mpv:
name: Build MPV
needs: params
runs-on: ubuntu-latest
container:
image: archlinux/archlinux:base-devel
continue-on-error: true
strategy:
matrix: ${{ fromJson(needs.params.outputs.matrix) }}
steps:
- name: Install Dependencies
run: |
sudo echo -e "[multilib]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm --needed git gyp mercurial subversion ninja cmake ragel yasm nasm asciidoc enca gperf unzip xz gcc-multilib clang python-pip curl lib32-glib2 wget python-cairo
mkdir -p /home/opt/7zip
wget -qO - https://www.7-zip.org/a/7z2301-linux-x64.tar.xz | tar -xJf - -C /home/opt/7zip 7zzs
sudo ln -s /home/opt/7zip/7zzs /usr/bin/7z
pip3 install -U --break-system-packages setuptools rst2pdf mako jsonschema meson
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global pull.rebase true
git config --global rebase.autoStash true
git config --global fetch.prune true
- uses: actions/checkout@v3
- name: Checkout toolchain
uses: actions/checkout@v3
with:
repository: media-kit/libmpv-win32-audio-cmake
path: mpv-winbuild-cmake
- name: Get Params
run: |
echo "sha=${{ fromJson(needs.params.outputs.params).sha }}" >> $GITHUB_ENV
echo "short_time=$(date "+%Y-%m-%d")" >> $GITHUB_ENV
echo "cache_id=${{ fromJson(needs.params.outputs.params).cache_id }}" >> $GITHUB_ENV
echo "cache_suffix=$(date "+%Y-%m-%d")-${{ fromJson(needs.params.outputs.params).sha }}-${{ fromJson(needs.params.outputs.params).cache_id }}" >> $GITHUB_ENV
- name: Restore Source Cache
if: ${{ github.event.inputs.needclean != 'true' }}
uses: actions/cache/[email protected]
id: cache_source
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/src_packages
key: ${{ runner.os }}-source-${{ env.cache_suffix }}
restore-keys: |
${{ runner.os }}-source
- name: Restore Rust Cache
if: ${{ github.event.inputs.needclean != 'true' }}
uses: actions/cache/[email protected]
id: cache_rust
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/install_rustup
key: ${{ runner.os }}-rust-${{ env.cache_suffix }}
restore-keys: |
${{ runner.os }}-rust
- name: Restore Build Cache
if: ${{ github.event.inputs.needclean != 'true' }}
uses: actions/cache/[email protected]
id: cache_build
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/build${{ matrix.bit }}
key: ${{ runner.os }}-mpv-build${{ matrix.bit }}-${{ env.cache_suffix }}
restore-keys: |
${{ runner.os }}-mpv-build${{ matrix.bit }}
- name: Running custom command
if: ${{ inputs.command != '' }}
shell: bash
continue-on-error: true
run: |
cd mpv-winbuild-cmake
bit="${{ matrix.bit }}"
gitdir=$(pwd)
buildroot=$(pwd)
srcdir=$(pwd)/src_packages
builddir=$buildroot/build$bit
if [ $bit == "32" ]; then
arch="i686"
elif [ $bit == "64" ]; then
arch="x86_64"
elif [ $bit == "64-v3" ]; then
arch="x86_64"
gcc_arch=-DGCC_ARCH=x86-64-v3
x86_64_level=-v3
fi
retry-tool() {
local RETRY_COUNTER=0
local MAX_RETRY=3
while [[ $RETRY_COUNTER -lt $MAX_RETRY ]]; do
$@ && break || sleep 2
RETRY_COUNTER=$(( $RETRY_COUNTER + 1 ))
echo "Retry $RETRY_COUNTER..."
done
if [[ $RETRY_COUNTER -ge $MAX_RETRY ]]; then
echo "Max retry count exceeded."
fi
}
set -x
${{ inputs.command }}
- name: Build
id: build
shell: bash
run: |
chmod +x build.sh
cd mpv-winbuild-cmake
if [[ "$(ls -A ../patch/*.patch)" ]]; then
for patch in ../patch/*.patch ; do
git am --3way "$patch" || git am --abort
done
fi
bash ../build.sh '${{ matrix.bit }}'
- name: Collect logs
if: ${{ always() }}
run: |
sudo 7z a logs.7z $(find mpv-winbuild-cmake/build${{ matrix.bit }} -type f -iname "*-*.log" -or -wholename "*/ffbuild/config.log")
- name: upload logs
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: ${{ matrix.bit }}_logs
path: logs.7z
- name: "Get artifacts' name and path"
id: get_files
uses: actions/github-script@v6
with:
script: |
const path = require('path');
const types = ["mpv-debug", "mpv-dev", "mpv"];
let arch="";
switch ( "${{ matrix.bit }}" ) {
case "32":
arch = "i686";
break;
case "64":
arch = "x86_64";
break;
case "64-v3":
arch = "x86_64-v3";
break;
}
for (let type of types) {
const globber = await glob.create(`mpv-winbuild-cmake/release/${type}-${arch}-*.7z`);
const files = await globber.glob();
if ( files.length > 0 ) {
const file = files[0];
core.exportVariable( `${type}_name`, path.basename(file) );
core.exportVariable( `${type}_path`, file );
}
}
// let { stdout: ffmpeg_hash } = await exec.getExecOutput("git -C mpv-winbuild-cmake/src_packages/ffmpeg rev-parse --short HEAD");
// ffmpeg_hash = ffmpeg_hash.trim();
// const ffmpeg_name = `ffmpeg-${arch}-git-${ffmpeg_hash}`;
// core.exportVariable( 'ffmpeg_name', ffmpeg_name );
// await exec.exec(`7z a -m0=lzma2 -mx=9 -ms=on mpv-winbuild-cmake/release/${ffmpeg_name}.7z ./mpv-winbuild-cmake/build${{ matrix.bit }}/install/mingw/bin/ffmpeg.exe`)
- name: upload mpv-debug
uses: actions/upload-artifact@v3
if: ${{ env.mpv-debug_name && env.mpv-debug_path }}
with:
name: ${{ env.mpv-debug_name }}
path: ${{ env.mpv-debug_path }}
- name: upload mpv-dev
uses: actions/upload-artifact@v3
if: ${{ env.mpv-dev_name && env.mpv-dev_path }}
with:
name: ${{ env.mpv-dev_name }}
path: ${{ env.mpv-dev_path }}
- name: upload mpv
uses: actions/upload-artifact@v3
if: ${{ env.mpv_name && env.mpv_path }}
with:
name: ${{ env.mpv_name }}
path: ${{ env.mpv_path }}
# - name: upload ffmpeg
# uses: actions/upload-artifact@v3
# if: ${{ env.ffmpeg_name }}
# with:
# name: ${{ env.ffmpeg_name }}
# path: mpv-winbuild-cmake/release/${{ env.ffmpeg_name }}.7z
- name: Save Sources Cache
if: ${{ github.ref_name == 'main' }}
uses: actions/cache/[email protected]
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/src_packages
key: ${{ runner.os }}-source-${{ env.cache_suffix }}
- name: Save Rust Cache
if: ${{ github.ref_name == 'main' }}
uses: actions/cache/[email protected]
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/install_rustup
key: ${{ runner.os }}-rust-${{ env.cache_suffix }}
- name: Save Build Cache
if: ${{ github.ref_name == 'main' }}
uses: actions/cache/[email protected]
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/build${{ matrix.bit }}
key: ${{ runner.os }}-mpv-build${{ matrix.bit }}-${{ env.cache_suffix }}
- name: "Job summary"
uses: actions/github-script@v6
continue-on-error: true
if: ${{ always() }}
with:
script: |
const path = require('path');
const { readdirSync,existsSync } = require('fs');
const myExec = async (command, args = null) => await exec.getExecOutput(command,args,{silent: true}).then(result => result.stdout.trim()).catch(err => '');
const toolchainDir = path.resolve("mpv-winbuild-cmake");
const workdir = path.resolve(toolchainDir,"src_packages");
const isGitSync = dirname => existsSync(path.join(workdir, dirname, '.git'));
const getGithubUrl = (hash,remote) => remote.replace(/\.git$/,"") + `/commit/${hash}`;
const getGitlabUrl = (hash,remote) => remote.replace(/\.git$/,"") + `/-/commit/${hash}`;
const getBitbucketUrl = (hash,remote) => remote.replace(/\.git$/,"") + `/commits/${hash}`;
const getGoogleSourceUrl = (hash,remote) => remote + `/+/${hash}`;
const gethGitVideolanUrl = (hash,remote) => remote.replace(/\/git\//,"/?p=") + `;a=commit;h=${hash}`;
const getCgitUrl = (hash,remote) => remote + `/commit/?id=${hash}`;
function getCommitUrl(hash,remote) {
let url = "";
switch (true) {
case /github\.com/.test(remote):
url = getGithubUrl(hash,remote);
break;
case /(gitlab\.com|code\.videolan\.org|gitlab\.gnome\.org)/.test(remote):
url = getGitlabUrl(hash,remote);
break;
case /bitbucket\.org/.test(remote):
url = getBitbucketUrl(hash,remote);
break;
case /googlesource\.com/.test(remote):
url = getGoogleSourceUrl(hash,remote);
break;
case /git\.videolan\.org/.test(remote):
url = gethGitVideolanUrl(hash,remote);
break;
case /git\.libssh\.org/.test(remote):
url = getCgitUrl(hash,remote);
break;
default:
url = remote;
break;
}
return url;
}
const dirs = readdirSync(workdir, { withFileTypes: true }).filter(dirent => dirent.isDirectory() && isGitSync(dirent.name) ).map(dirent => path.join(workdir, dirent.name));
let packages_table = [[{data: 'Package', header: true}, {data: 'Local commit', header: true}, {data: 'Status', header: true}, {data: 'Remote commit', header: true}]];
for (let dir of dirs) {
let local_hash = await myExec(`git -C ${dir} rev-parse --short=7 HEAD`);
let remote_branch = await myExec(`git -C ${dir} rev-parse --abbrev-ref HEAD@{upstream}`);
let remote_hash = await myExec(`git -C ${dir} rev-parse ${remote_branch}`);
let status = await myExec(`git -C ${dir} status -sb`).then(s => s.split("\n",1)[0].replace(/^## */,""));
let remote = await myExec(`git -C ${dir} config --get remote.origin.url`);
let url = getCommitUrl(remote_hash, remote);
let package_name = path.basename(dir);
packages_table.push([package_name, local_hash, status, `<a href="${url}">${remote_hash.slice(0,7)}</a>`]);
}
let toolchain_hash = await myExec(`git -C ${toolchainDir} rev-parse HEAD`);
let toolchain_remote = await myExec(`git -C ${toolchainDir} config --get remote.origin.url`);
let toolchain_url = getCommitUrl(toolchain_hash, toolchain_remote);
await core.summary
.addHeading('Basic Info')
.addRaw(`toolchain: <a href="${toolchain_url}">${toolchain_hash.slice(0,7)}</a>`,true)
.addHeading('Packages Version')
.addTable(packages_table)
.write();
publish_release:
name: Publish release
needs: [build_mpv,params]
if: ${{ (github.event.inputs.release != null && github.event.inputs.release == 'true') || (github.event.inputs.release == null && fromJson(needs.params.outputs.params).release ) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: "Check artifacts"
uses: actions/github-script@v6
with:
script: |
const globber = await glob.create(`artifacts/*/mpv*.7z`);
const files = await globber.glob();
if ( files.length == 0 ) {
core.setFailed("Artifact does not exist!");
}
- name: Get current time
run: |
echo "long_time=$(date "+%Y-%m-%d %H:%M")" >> $GITHUB_ENV
echo "short_time=$(date "+%Y-%m-%d")" >> $GITHUB_ENV
- name: Commit version & remove existing tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
git fetch --tags
git checkout version || git checkout -b version origin/version || ( git checkout --orphan version && git rm -rf . )
echo -e "${{ env.short_time }}" > version
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add version
git diff-index --quiet HEAD || ( git commit -m "${{ env.short_time }}" && git push origin version )
if [ $(git tag -l "${{ env.short_time }}") ] ;then
gh release delete "${{ env.short_time }}" || true
git push --delete origin "${{ env.short_time }}" || true
git tag -d "${{ env.short_time }}" || true
fi
git checkout main
- name: Create release
uses: ncipollo/release-action@v1
with:
artifacts: "artifacts/*/mpv*.7z" # "artifacts/*/mpv*.7z,artifacts/*/ffmpeg*.7z"
commit: version
name: "${{ env.short_time }}"
body: "https://github.com/mpv-player/mpv/commit/${{ fromJson(needs.params.outputs.params).sha }}"
tag: "${{ env.short_time }}"
allowUpdates: true
artifactErrorsFailBuild: true
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
- name: Prune old releases
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
git checkout main
bash prunetags.sh