build.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. name: Build FFmpeg
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. doRelease:
  6. description: 'Publish new release'
  7. type: boolean
  8. default: false
  9. required: false
  10. buildOnly:
  11. description: 'Only build ffmpeg'
  12. type: boolean
  13. default: false
  14. required: false
  15. schedule:
  16. - cron: '42 13 * * *'
  17. env:
  18. DOCKER_BUILDKIT: 1
  19. jobs:
  20. pre_check:
  21. name: Pre Checks
  22. if: ${{ github.event.inputs.buildOnly != 'true' }}
  23. runs-on: ubuntu-latest
  24. steps:
  25. - name: Repo Check
  26. run: |
  27. if [[ "$GITHUB_REPOSITORY" != "yt-dlp/FFmpeg-Builds" ]]; then
  28. echo "When forking this repository to make your own builds, you have to adjust this check."
  29. echo "When doing so make sure to randomize the scheduled cron time above, in order to spread out the various build times as much as possible."
  30. echo "This has been put in place due to the enormous amounts of traffic hundreds/thousands of parallel builds can cause on external infrastructure."
  31. exit 1
  32. fi
  33. exit 0
  34. build_base:
  35. name: Build base image
  36. if: ${{ github.event.inputs.buildOnly != 'true' }}
  37. needs: pre_check
  38. runs-on: ubuntu-latest
  39. steps:
  40. - name: Free Disk-Space
  41. run: df -h && sudo apt-get clean && docker system prune -a -f && sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc && df -h
  42. - name: Checkout
  43. uses: actions/checkout@v4
  44. - name: Install buildx
  45. uses: docker/setup-buildx-action@v3
  46. with:
  47. buildkitd-config: .github/buildkit.toml
  48. - name: Login to Docker
  49. uses: docker/login-action@v3
  50. with:
  51. registry: ghcr.io
  52. username: ${{ github.actor }}
  53. password: ${{ github.token }}
  54. - name: Image Name
  55. id: imagename
  56. run: |
  57. IMG="${GITHUB_REPOSITORY,,}/base"
  58. echo "name=ghcr.io/${IMG/ /-}" >> $GITHUB_OUTPUT
  59. echo "rawname=${IMG/ /-}" >> $GITHUB_OUTPUT
  60. - name: Stop Commands
  61. run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
  62. - name: Build target base image
  63. uses: docker/build-push-action@v5
  64. with:
  65. context: images/base
  66. pull: true
  67. push: true
  68. provenance: false
  69. tags: ${{ steps.imagename.outputs.name }}:latest
  70. cache-to: type=registry,mode=max,ref=${{ steps.imagename.outputs.name }}:cache
  71. cache-from: type=registry,ref=${{ steps.imagename.outputs.name }}:cache
  72. - name: Get download cache key
  73. id: dl_cache
  74. run: |
  75. echo "dltagname=$(./util/get_dl_cache_tag.sh)" >> $GITHUB_OUTPUT
  76. - name: Cache
  77. uses: actions/cache@v4
  78. with:
  79. path: .cache/downloads
  80. key: download-cache-${{ steps.dl_cache.outputs.dltagname }}
  81. restore-keys: |
  82. download-cache-
  83. - name: Update Cache
  84. run: |
  85. set -e
  86. ./download.sh
  87. ./util/clean_cache.sh
  88. - name: Cleanup
  89. continue-on-error: true
  90. uses: BtbN/delete-untagged-ghcr-action@main
  91. with:
  92. token: ${{ github.token }}
  93. package_name: ${{ steps.imagename.outputs.rawname }}
  94. repository_owner: ${{ github.repository_owner }}
  95. repository: ${{ github.repository }}
  96. owner_type: user
  97. untagged_only: true
  98. build_target_bases:
  99. name: Build target base image
  100. if: ${{ github.event.inputs.buildOnly != 'true' }}
  101. needs: build_base
  102. runs-on: ubuntu-latest
  103. strategy:
  104. fail-fast: false
  105. matrix:
  106. target: [win32,win64,winarm64,linux64,linuxarm64]
  107. steps:
  108. - name: Free Disk-Space
  109. run: df -h && sudo apt-get clean && docker system prune -a -f && sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc && df -h
  110. - name: Checkout
  111. uses: actions/checkout@v4
  112. - name: Install buildx
  113. uses: docker/setup-buildx-action@v3
  114. with:
  115. buildkitd-config: .github/buildkit.toml
  116. - name: Login to Docker
  117. uses: docker/login-action@v3
  118. with:
  119. registry: ghcr.io
  120. username: ${{ github.actor }}
  121. password: ${{ github.token }}
  122. - name: Image Name
  123. id: imagename
  124. run: |
  125. IMG="${GITHUB_REPOSITORY,,}/base-${{ matrix.target }}"
  126. echo "name=ghcr.io/${IMG/ /-}" >> $GITHUB_OUTPUT
  127. echo "rawname=${IMG/ /-}" >> $GITHUB_OUTPUT
  128. echo "gh_repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
  129. - name: Stop Commands
  130. run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
  131. - name: Build target base image
  132. uses: docker/build-push-action@v5
  133. with:
  134. context: images/base-${{ matrix.target }}
  135. pull: true
  136. push: true
  137. provenance: false
  138. tags: ${{ steps.imagename.outputs.name }}:latest
  139. cache-to: type=registry,mode=max,ref=${{ steps.imagename.outputs.name }}:cache
  140. cache-from: type=registry,ref=${{ steps.imagename.outputs.name }}:cache
  141. build-args: |
  142. GH_REPO=ghcr.io/${{ steps.imagename.outputs.gh_repo }}
  143. - name: Cleanup
  144. continue-on-error: true
  145. uses: BtbN/delete-untagged-ghcr-action@main
  146. with:
  147. token: ${{ github.token }}
  148. package_name: ${{ steps.imagename.outputs.rawname }}
  149. repository_owner: ${{ github.repository_owner }}
  150. repository: ${{ github.repository }}
  151. owner_type: user
  152. untagged_only: true
  153. build_targets:
  154. name: Build target-variant image
  155. if: ${{ github.event.inputs.buildOnly != 'true' }}
  156. needs: build_target_bases
  157. runs-on: ubuntu-latest
  158. strategy:
  159. fail-fast: false
  160. matrix:
  161. target: [win32,win64,winarm64]
  162. variant: [gpl,gpl 7.1,gpl-shared,gpl-shared 7.1]
  163. include:
  164. - target: linux64
  165. variant: gpl
  166. - target: linux64
  167. variant: gpl 7.1
  168. - target: linuxarm64
  169. variant: gpl
  170. - target: linuxarm64
  171. variant: gpl 7.1
  172. steps:
  173. - name: Free Disk-Space
  174. run: df -h && sudo apt-get clean && docker system prune -a -f && sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc && df -h
  175. - name: Checkout
  176. uses: actions/checkout@v4
  177. - name: Install buildx
  178. uses: docker/setup-buildx-action@v3
  179. with:
  180. buildkitd-config: .github/buildkit.toml
  181. - name: Login to Docker
  182. uses: docker/login-action@v3
  183. with:
  184. registry: ghcr.io
  185. username: ${{ github.actor }}
  186. password: ${{ github.token }}
  187. - name: Image Name
  188. id: imagename
  189. run: |
  190. IMG="${GITHUB_REPOSITORY,,}/${{ matrix.target }}-${{ matrix.variant }}"
  191. echo "name=ghcr.io/${IMG/ /-}" >> $GITHUB_OUTPUT
  192. echo "rawname=${IMG/ /-}" >> $GITHUB_OUTPUT
  193. - name: Get download cache key
  194. id: dl_cache
  195. run: |
  196. echo "dltagname=$(./util/get_dl_cache_tag.sh)" >> $GITHUB_OUTPUT
  197. - name: Stop Commands
  198. run: T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
  199. - name: Generate Dockerfile
  200. run: ./generate.sh ${{ matrix.target }} ${{ matrix.variant }}
  201. - name: Cache
  202. uses: actions/cache/restore@v4
  203. with:
  204. path: .cache/downloads
  205. key: download-cache-${{ steps.dl_cache.outputs.dltagname }}
  206. fail-on-cache-miss: true
  207. - name: Build target base image
  208. uses: docker/build-push-action@v5
  209. with:
  210. context: .
  211. pull: true
  212. push: true
  213. provenance: false
  214. tags: ${{ steps.imagename.outputs.name }}:latest
  215. cache-to: type=registry,mode=max,ref=${{ steps.imagename.outputs.name }}:cache
  216. cache-from: type=registry,ref=${{ steps.imagename.outputs.name }}:cache
  217. - name: Cleanup
  218. continue-on-error: true
  219. uses: BtbN/delete-untagged-ghcr-action@main
  220. with:
  221. token: ${{ github.token }}
  222. package_name: ${{ steps.imagename.outputs.rawname }}
  223. repository_owner: ${{ github.repository_owner }}
  224. repository: ${{ github.repository }}
  225. owner_type: user
  226. untagged_only: true
  227. build_ffmpeg:
  228. name: Build ffmpeg
  229. if: ${{ ( github.event.inputs.buildOnly == 'true' && !cancelled() ) || success() }}
  230. needs: build_targets
  231. runs-on: ubuntu-latest
  232. strategy:
  233. fail-fast: false
  234. matrix:
  235. target: [win32,win64,winarm64]
  236. variant: [gpl,gpl 7.1,gpl-shared,gpl-shared 7.1]
  237. include:
  238. - target: linux64
  239. variant: gpl
  240. - target: linux64
  241. variant: gpl 7.1
  242. - target: linuxarm64
  243. variant: gpl
  244. - target: linuxarm64
  245. variant: gpl 7.1
  246. steps:
  247. - name: Free Disk-Space
  248. run: df -h && sudo apt-get clean && docker system prune -a -f && sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc && df -h
  249. - name: Checkout
  250. uses: actions/checkout@v4
  251. - name: Login to Docker
  252. uses: docker/login-action@v3
  253. with:
  254. registry: ghcr.io
  255. username: ${{ github.actor }}
  256. password: ${{ github.token }}
  257. - name: Build ffmpeg
  258. run: |
  259. T="$(echo -n ${{ github.token }} | sha256sum | head -c 64)" && echo -e "::add-mask::${T}\n::stop-commands::${T}"
  260. ./build.sh ${{ matrix.target }} ${{ matrix.variant }}
  261. - name: Replace spaces in string
  262. id: strs
  263. run: |
  264. SLUG="${{ matrix.target }}-${{ matrix.variant }}"
  265. echo "artifact_slug=${SLUG// /-}" >> $GITHUB_OUTPUT
  266. - name: Upload artifacts
  267. uses: actions/upload-artifact@v4
  268. with:
  269. name: ffmpeg-${{ steps.strs.outputs.artifact_slug }}
  270. overwrite: true
  271. path: artifacts/*
  272. publish_release:
  273. name: Publish release
  274. if: ${{ !cancelled() && ( github.event_name == 'schedule' || github.event.inputs.doRelease == 'true' ) && needs.build_ffmpeg.result == 'success' }}
  275. needs: build_ffmpeg
  276. runs-on: ubuntu-latest
  277. steps:
  278. - name: Free Disk-Space
  279. run: df -h && sudo apt-get clean && docker system prune -a -f && sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc && df -h
  280. - name: Checkout
  281. uses: actions/checkout@v4
  282. - name: Download artifacts
  283. uses: actions/download-artifact@v4
  284. with:
  285. pattern: ffmpeg-*
  286. merge-multiple: true
  287. path: artifacts
  288. - name: Create release
  289. id: create_release
  290. run: |
  291. set -xe
  292. shopt -s nullglob
  293. RELDATE="$(date +'%Y-%m-%d %H:%M')"
  294. NAME="Auto-Build $RELDATE"
  295. TAGNAME="autobuild-$(date +'%Y-%m-%d-%H-%M')"
  296. gh release create "$TAGNAME" --target "master" --title "$NAME" artifacts/*.{zip,tar.xz}
  297. echo "tag_name=${TAGNAME}" >> $GITHUB_OUTPUT
  298. echo "rel_date=${RELDATE}" >> $GITHUB_OUTPUT
  299. env:
  300. GITHUB_TOKEN: ${{ github.token }}
  301. - name: Update Latest
  302. run: |
  303. set -xe
  304. shopt -s nullglob
  305. mkdir latest_artifacts
  306. ./util/repack_latest.sh latest_artifacts artifacts/*.{zip,tar.xz}
  307. NAME="Latest Auto-Build (${{ steps.create_release.outputs.rel_date }})"
  308. TAGNAME="latest"
  309. gh release delete --cleanup-tag --yes "$TAGNAME" || true
  310. sleep 15
  311. gh release create "$TAGNAME" --target "master" --title "$NAME" latest_artifacts/*
  312. env:
  313. GITHUB_TOKEN: ${{ github.token }}
  314. - name: Update Wiki
  315. run: ./util/update_wiki.sh artifacts ${{ steps.create_release.outputs.tag_name }}
  316. env:
  317. GITHUB_TOKEN: ${{ github.token }}
  318. - name: Prune old releases
  319. run: ./util/prunetags.sh
  320. env:
  321. GITHUB_TOKEN: ${{ github.token }}