-
Notifications
You must be signed in to change notification settings - Fork 1
234 lines (199 loc) · 8.88 KB
/
Copy pathmediainfo-builder.yml
File metadata and controls
234 lines (199 loc) · 8.88 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
name: Build MediaInfo
on:
push:
paths-ignore:
- '**.md'
- 'LICENSE'
schedule:
# Runs Every Week At 12:13 AM UTC On Tuesdays, Thursdays & Saturdays.
- cron: '13 0 * * 2,4,6'
workflow_dispatch:
permissions:
contents: write
jobs:
check-version:
name: Pre Checks
runs-on: ubuntu-26.04
timeout-minutes: 140
outputs:
build_needed: ${{ steps.check.outputs.build_needed || 'False' }}
version: ${{ steps.check.outputs.version || 'Skipped' }}
steps:
- name: Checkout
uses: actions/checkout@v7
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
- name: Check Upstream Version
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
echo "Fetching Latest MediaInfo Source..."
MI_URL=$(curl -fsSL "https://mediaarea.net/download/binary/mediainfo/" | grep -oP '(?<=href=")\d+(?:\.\d+)+(?=/")' | sort -Vu | tail -n 1)
test -n "$MI_URL" || { echo "❌ FATAL ERROR: Failed to detect latest MediaInfo version."; exit 1; }
echo "💡 Latest MediaInfo version detected: $MI_URL"
# Fetch latest release tag from this repo (suppress error if no releases exist yet)
LATEST_RELEASE=$(gh release view --json tagName -q .tagName 2>/dev/null || echo "none")
echo "💡 Current repository latest release: $LATEST_RELEASE"
if [ "v$MI_URL" == "$LATEST_RELEASE" ]; then
echo "✅ Version v$MI_URL is already built. Forcing rebuild for security updates. 💚"
echo "build_needed=true" >> $GITHUB_OUTPUT
echo "version=$MI_URL" >> $GITHUB_OUTPUT
else
echo "🚀 New version detected! Proceeding to build v$MI_URL."
echo "build_needed=true" >> $GITHUB_OUTPUT
echo "version=$MI_URL" >> $GITHUB_OUTPUT
fi
build-binaries:
name: Compile Binaries
needs: check-version
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && needs.check-version.outputs.build_needed == 'true'
# Uses the visual_arch (x64 and ARM64)
runs-on: ${{ matrix.visual_arch == 'LinuxARM64' && 'ubuntu-26.04-arm' || 'ubuntu-26.04' }}
timeout-minutes: 240 # 4-hour safety net for heavy compilation
strategy:
matrix:
visual_arch: [Linux64, LinuxARM64]
steps:
- name: Free Disk-Space
run: df -h && sudo apt-get clean && docker system prune -a -f && sudo rm -rf /opt/ghc /usr/local/.ghcup /usr/local/lib/android && df -h
- name: Checkout
uses: actions/checkout@v7
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Base Image
id: vars
run: |
set -euo pipefail
case "${{ matrix.visual_arch }}" in
Linux64) echo "arch=amd64" >> $GITHUB_OUTPUT; echo "ext_name=linux64" >> $GITHUB_OUTPUT ;;
LinuxARM64) echo "arch=arm64" >> $GITHUB_OUTPUT; echo "ext_name=linuxarm64" >> $GITHUB_OUTPUT ;;
esac
- name: Build, Extract & Archive MediaInfo Binary
run: |
set -euo pipefail
mkdir -p ./output ./artifacts
# 🔜 Disabled Docker Cache, Re-Enable Later If Needed.
# --cache-to type=gha,mode=max,scope=mediainfo-${{ matrix.arch }} \
# --cache-from type=gha,scope=mediainfo-${{ matrix.arch }} \
docker buildx build \
--platform linux/${{ steps.vars.outputs.arch }} \
--build-arg MI_VERSION=${{ needs.check-version.outputs.version }} \
--output type=local,dest=./output \
-f Dockerfile .
# Navigate to output, make executable, and compress into a real tar.xz archive
cd ./output
chmod +x mediainfo
TAR_FILENAME="mediainfo-master-latest-${{ steps.vars.outputs.ext_name }}-gpl.tar.xz"
tar -cJf "../artifacts/$TAR_FILENAME" mediainfo
cd ..
- name: Upload Artifacts
uses: actions/upload-artifact@v7
with:
name: mediainfo-${{ steps.vars.outputs.arch }}
path: ./artifacts/mediainfo-master-latest-${{ steps.vars.outputs.ext_name }}-gpl.tar.xz
retention-days: 1
release-and-cleanup:
name: Publish Release & Purge Old
needs: [check-version, build-binaries]
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && needs.check-version.outputs.build_needed == 'true'
runs-on: ubuntu-26.04
timeout-minutes: 72 # Safety net for GitHub API uploads
steps:
- name: Free Disk-Space
run: df -h && sudo apt-get clean && docker system prune -a -f && sudo rm -rf /opt/ghc /usr/local/.ghcup /usr/local/lib/android && df -h
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 2 # Required to fetch the previous commit hash
- name: Download Artifacts
uses: actions/download-artifact@v8
with:
path: ./artifacts
merge-multiple: true
- name: Generate Checksums
run: |
set -euo pipefail
cd ./artifacts
echo "Generating SHA256 checksums..."
sha256sum * > checksums.sha256
cat checksums.sha256
- name: Strip 'Latest' Tag From Previous Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
OLD_RELEASE_TAG=$(gh release view --json tagName -q .tagName 2>/dev/null || echo "none")
if [ "$OLD_RELEASE_TAG" != "none" ]; then
OLD_TITLE=$(gh release view "$OLD_RELEASE_TAG" --json name -q .name)
# Instantly remove the " - Latest" string from the old title
NEW_OLD_TITLE=$(echo "$OLD_TITLE" | sed 's/ - Latest//g')
echo "Renaming old release '$OLD_TITLE' to '$NEW_OLD_TITLE'"
gh release edit "$OLD_RELEASE_TAG" --title "$NEW_OLD_TITLE" || true
fi
- name: Create Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.check-version.outputs.version }}
run: |
set -euo pipefail
TAG_NAME="v$VERSION"
# Defensive check: Ensure release doesn't already exist to prevent race conditions
if gh release view "$TAG_NAME" >/dev/null 2>&1; then
echo "♻️ Release $TAG_NAME already exists. Deleting to recreate a fresh build... ☣️"
gh release delete "$TAG_NAME" --cleanup-tag -y
sleep 5
fi
# Generate dynamic text variables
DATE_STR=$(date -u +'%d/%m/%Y At %I:%M %p')
COMMIT_MSG=$(git log -1 --pretty=%B | head -n 1)
PREV_HASH=$(git log -2 --pretty=%H | tail -n 1)
# Create The Release Body.
cat <<EOF > release_notes.txt
**This Latest Stable Automated Build Of MediaInfo Created On $DATE_STR**
\`$COMMIT_MSG\`
\`This Reverts Commit\` $PREV_HASH.
EOF
echo "Creating release for $TAG_NAME..."
gh release create "$TAG_NAME" ./artifacts/* \
--title "MediaInfo $VERSION (Executable) - Latest" \
--notes-file release_notes.txt
- name: Cleanup Old Releases
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
echo "Fetching all releases..."
# Get all releases sorted by creation date (newest first)
RELEASES=$(gh release list --limit 100 | awk '{print $1}')
COUNT=0
for REL in $RELEASES; do
COUNT=$((COUNT+1))
if [ $COUNT -gt 4 ]; then
echo "🗑️ Deleting old release: $REL"
gh release delete "$REL" --cleanup-tag -y
else
echo "✅ Keeping release: $REL"
fi
done
keepalive:
name: Repository Keepalive
runs-on: ubuntu-26.04
if: github.event_name == 'schedule'
timeout-minutes: 61 # Safety net for git push
steps:
- name: Free Disk-Space
run: df -h && sudo apt-get clean && docker system prune -a -f && sudo rm -rf /opt/ghc /usr/local/.ghcup /usr/local/lib/android && df -h
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Push Commit
run: |
set -euo pipefail
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git checkout -B dev
git commit --allow-empty -m "chore: keepalive to prevent GitHub Actions cron pause [skip ci]"
git push origin dev --force