build.yml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. name: Build Artifacts
  2. on:
  3. workflow_call:
  4. inputs:
  5. version:
  6. required: true
  7. type: string
  8. channel:
  9. required: false
  10. default: stable
  11. type: string
  12. unix:
  13. default: true
  14. type: boolean
  15. linux_static:
  16. default: true
  17. type: boolean
  18. linux_arm:
  19. default: true
  20. type: boolean
  21. macos:
  22. default: true
  23. type: boolean
  24. macos_legacy:
  25. default: true
  26. type: boolean
  27. windows:
  28. default: true
  29. type: boolean
  30. windows32:
  31. default: true
  32. type: boolean
  33. origin:
  34. required: false
  35. default: ''
  36. type: string
  37. secrets:
  38. GPG_SIGNING_KEY:
  39. required: false
  40. workflow_dispatch:
  41. inputs:
  42. version:
  43. description: |
  44. VERSION: yyyy.mm.dd[.rev] or rev
  45. required: true
  46. type: string
  47. channel:
  48. description: |
  49. SOURCE of this build's updates: stable/nightly/master/<repo>
  50. required: true
  51. default: stable
  52. type: string
  53. unix:
  54. description: yt-dlp, yt-dlp.tar.gz
  55. default: true
  56. type: boolean
  57. linux_static:
  58. description: yt-dlp_linux
  59. default: true
  60. type: boolean
  61. linux_arm:
  62. description: yt-dlp_linux_aarch64, yt-dlp_linux_armv7l
  63. default: true
  64. type: boolean
  65. macos:
  66. description: yt-dlp_macos, yt-dlp_macos.zip
  67. default: true
  68. type: boolean
  69. macos_legacy:
  70. description: yt-dlp_macos_legacy
  71. default: true
  72. type: boolean
  73. windows:
  74. description: yt-dlp.exe, yt-dlp_min.exe, yt-dlp_win.zip
  75. default: true
  76. type: boolean
  77. windows32:
  78. description: yt-dlp_x86.exe
  79. default: true
  80. type: boolean
  81. origin:
  82. description: Origin
  83. required: false
  84. default: 'current repo'
  85. type: choice
  86. options:
  87. - 'current repo'
  88. permissions:
  89. contents: read
  90. jobs:
  91. process:
  92. runs-on: ubuntu-latest
  93. outputs:
  94. origin: ${{ steps.process_origin.outputs.origin }}
  95. steps:
  96. - name: Process origin
  97. id: process_origin
  98. run: |
  99. echo "origin=${{ inputs.origin == 'current repo' && github.repository || inputs.origin }}" | tee "$GITHUB_OUTPUT"
  100. unix:
  101. needs: process
  102. if: inputs.unix
  103. runs-on: ubuntu-latest
  104. steps:
  105. - uses: actions/checkout@v4
  106. with:
  107. fetch-depth: 0 # Needed for changelog
  108. - uses: actions/setup-python@v5
  109. with:
  110. python-version: "3.10"
  111. - name: Install Requirements
  112. run: |
  113. sudo apt -y install zip pandoc man sed
  114. - name: Prepare
  115. run: |
  116. python devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  117. python devscripts/update_changelog.py -vv
  118. python devscripts/make_lazy_extractors.py
  119. - name: Build Unix platform-independent binary
  120. run: |
  121. make all tar
  122. - name: Verify --update-to
  123. if: vars.UPDATE_TO_VERIFICATION
  124. run: |
  125. chmod +x ./yt-dlp
  126. cp ./yt-dlp ./yt-dlp_downgraded
  127. version="$(./yt-dlp --version)"
  128. ./yt-dlp_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  129. downgraded_version="$(./yt-dlp_downgraded --version)"
  130. [[ "$version" != "$downgraded_version" ]]
  131. - name: Upload artifacts
  132. uses: actions/upload-artifact@v4
  133. with:
  134. name: build-bin-${{ github.job }}
  135. path: |
  136. yt-dlp
  137. yt-dlp.tar.gz
  138. compression-level: 0
  139. linux_static:
  140. needs: process
  141. if: inputs.linux_static
  142. runs-on: ubuntu-latest
  143. steps:
  144. - uses: actions/checkout@v4
  145. - name: Build static executable
  146. env:
  147. channel: ${{ inputs.channel }}
  148. origin: ${{ needs.process.outputs.origin }}
  149. version: ${{ inputs.version }}
  150. run: |
  151. mkdir ~/build
  152. cd bundle/docker
  153. docker compose up --build static
  154. sudo chown "${USER}:docker" ~/build/yt-dlp_linux
  155. - name: Verify --update-to
  156. if: vars.UPDATE_TO_VERIFICATION
  157. run: |
  158. chmod +x ~/build/yt-dlp_linux
  159. cp ~/build/yt-dlp_linux ~/build/yt-dlp_linux_downgraded
  160. version="$(~/build/yt-dlp_linux --version)"
  161. ~/build/yt-dlp_linux_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  162. downgraded_version="$(~/build/yt-dlp_linux_downgraded --version)"
  163. [[ "$version" != "$downgraded_version" ]]
  164. - name: Upload artifacts
  165. uses: actions/upload-artifact@v4
  166. with:
  167. name: build-bin-${{ github.job }}
  168. path: |
  169. ~/build/yt-dlp_linux
  170. compression-level: 0
  171. linux_arm:
  172. needs: process
  173. if: inputs.linux_arm
  174. permissions:
  175. contents: read
  176. packages: write # for creating cache
  177. runs-on: ubuntu-latest
  178. strategy:
  179. matrix:
  180. architecture:
  181. - armv7
  182. - aarch64
  183. steps:
  184. - uses: actions/checkout@v4
  185. with:
  186. path: ./repo
  187. - name: Virtualized Install, Prepare & Build
  188. uses: yt-dlp/run-on-arch-action@v2
  189. with:
  190. # Ref: https://github.com/uraimo/run-on-arch-action/issues/55
  191. env: |
  192. GITHUB_WORKFLOW: build
  193. githubToken: ${{ github.token }} # To cache image
  194. arch: ${{ matrix.architecture }}
  195. distro: ubuntu18.04 # Standalone executable should be built on minimum supported OS
  196. dockerRunArgs: --volume "${PWD}/repo:/repo"
  197. install: | # Installing Python 3.10 from the Deadsnakes repo raises errors
  198. apt update
  199. apt -y install zlib1g-dev libffi-dev python3.8 python3.8-dev python3.8-distutils python3-pip
  200. python3.8 -m pip install -U pip setuptools wheel
  201. # Cannot access any files from the repo directory at this stage
  202. python3.8 -m pip install -U Pyinstaller mutagen pycryptodomex websockets brotli certifi secretstorage cffi
  203. run: |
  204. cd repo
  205. python3.8 devscripts/install_deps.py -o --include build
  206. python3.8 devscripts/install_deps.py --include pyinstaller --include secretstorage # Cached version may be out of date
  207. python3.8 devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  208. python3.8 devscripts/make_lazy_extractors.py
  209. python3.8 -m bundle.pyinstaller
  210. if ${{ vars.UPDATE_TO_VERIFICATION && 'true' || 'false' }}; then
  211. arch="${{ (matrix.architecture == 'armv7' && 'armv7l') || matrix.architecture }}"
  212. chmod +x ./dist/yt-dlp_linux_${arch}
  213. cp ./dist/yt-dlp_linux_${arch} ./dist/yt-dlp_linux_${arch}_downgraded
  214. version="$(./dist/yt-dlp_linux_${arch} --version)"
  215. ./dist/yt-dlp_linux_${arch}_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  216. downgraded_version="$(./dist/yt-dlp_linux_${arch}_downgraded --version)"
  217. [[ "$version" != "$downgraded_version" ]]
  218. fi
  219. - name: Upload artifacts
  220. uses: actions/upload-artifact@v4
  221. with:
  222. name: build-bin-linux_${{ matrix.architecture }}
  223. path: | # run-on-arch-action designates armv7l as armv7
  224. repo/dist/yt-dlp_linux_${{ (matrix.architecture == 'armv7' && 'armv7l') || matrix.architecture }}
  225. compression-level: 0
  226. macos:
  227. needs: process
  228. if: inputs.macos
  229. permissions:
  230. contents: read
  231. actions: write # For cleaning up cache
  232. runs-on: macos-12
  233. steps:
  234. - uses: actions/checkout@v4
  235. # NB: Building universal2 does not work with python from actions/setup-python
  236. - name: Restore cached requirements
  237. id: restore-cache
  238. uses: actions/cache/restore@v4
  239. env:
  240. SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1
  241. with:
  242. path: |
  243. ~/yt-dlp-build-venv
  244. key: cache-reqs-${{ github.job }}
  245. - name: Install Requirements
  246. run: |
  247. brew install coreutils
  248. python3 -m venv ~/yt-dlp-build-venv
  249. source ~/yt-dlp-build-venv/bin/activate
  250. python3 devscripts/install_deps.py -o --include build
  251. python3 devscripts/install_deps.py --print --include pyinstaller > requirements.txt
  252. # We need to ignore wheels otherwise we break universal2 builds
  253. python3 -m pip install -U --no-binary :all: -r requirements.txt
  254. # We need to fuse our own universal2 wheels for curl_cffi
  255. python3 -m pip install -U delocate
  256. mkdir curl_cffi_whls curl_cffi_universal2
  257. python3 devscripts/install_deps.py --print -o --include curl-cffi > requirements.txt
  258. for platform in "macosx_11_0_arm64" "macosx_11_0_x86_64"; do
  259. python3 -m pip download \
  260. --only-binary=:all: \
  261. --platform "${platform}" \
  262. -d curl_cffi_whls \
  263. -r requirements.txt
  264. done
  265. ( # Overwrite x86_64-only libs with fat/universal2 libs or else Pyinstaller will do the opposite
  266. # See https://github.com/yt-dlp/yt-dlp/pull/10069
  267. cd curl_cffi_whls
  268. mkdir -p curl_cffi/.dylibs
  269. python_libdir=$(python3 -c 'import sys; from pathlib import Path; print(Path(sys.path[1]).parent)')
  270. for dylib in lib{ssl,crypto}.3.dylib; do
  271. cp "${python_libdir}/${dylib}" "curl_cffi/.dylibs/${dylib}"
  272. for wheel in curl_cffi*macos*x86_64.whl; do
  273. zip "${wheel}" "curl_cffi/.dylibs/${dylib}"
  274. done
  275. done
  276. )
  277. python3 -m delocate.cmd.delocate_fuse curl_cffi_whls/curl_cffi*.whl -w curl_cffi_universal2
  278. python3 -m delocate.cmd.delocate_fuse curl_cffi_whls/cffi*.whl -w curl_cffi_universal2
  279. for wheel in curl_cffi_universal2/*cffi*.whl; do
  280. mv -n -- "${wheel}" "${wheel/x86_64/universal2}"
  281. done
  282. python3 -m pip install --force-reinstall -U curl_cffi_universal2/*cffi*.whl
  283. - name: Prepare
  284. run: |
  285. python3 devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  286. python3 devscripts/make_lazy_extractors.py
  287. - name: Build
  288. run: |
  289. source ~/yt-dlp-build-venv/bin/activate
  290. python3 -m bundle.pyinstaller --target-architecture universal2 --onedir
  291. (cd ./dist/yt-dlp_macos && zip -r ../yt-dlp_macos.zip .)
  292. python3 -m bundle.pyinstaller --target-architecture universal2
  293. - name: Verify --update-to
  294. if: vars.UPDATE_TO_VERIFICATION
  295. run: |
  296. chmod +x ./dist/yt-dlp_macos
  297. cp ./dist/yt-dlp_macos ./dist/yt-dlp_macos_downgraded
  298. version="$(./dist/yt-dlp_macos --version)"
  299. ./dist/yt-dlp_macos_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  300. downgraded_version="$(./dist/yt-dlp_macos_downgraded --version)"
  301. [[ "$version" != "$downgraded_version" ]]
  302. - name: Upload artifacts
  303. uses: actions/upload-artifact@v4
  304. with:
  305. name: build-bin-${{ github.job }}
  306. path: |
  307. dist/yt-dlp_macos
  308. dist/yt-dlp_macos.zip
  309. compression-level: 0
  310. - name: Cleanup cache
  311. if: steps.restore-cache.outputs.cache-hit == 'true'
  312. env:
  313. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  314. cache_key: cache-reqs-${{ github.job }}
  315. repository: ${{ github.repository }}
  316. branch: ${{ github.ref }}
  317. run: |
  318. gh extension install actions/gh-actions-cache
  319. gh actions-cache delete "${cache_key}" -R "${repository}" -B "${branch}" --confirm
  320. - name: Cache requirements
  321. uses: actions/cache/save@v4
  322. with:
  323. path: |
  324. ~/yt-dlp-build-venv
  325. key: cache-reqs-${{ github.job }}
  326. macos_legacy:
  327. needs: process
  328. if: inputs.macos_legacy
  329. runs-on: macos-12
  330. steps:
  331. - uses: actions/checkout@v4
  332. - name: Install Python
  333. # We need the official Python, because the GA ones only support newer macOS versions
  334. env:
  335. PYTHON_VERSION: 3.10.5
  336. MACOSX_DEPLOYMENT_TARGET: 10.9 # Used up by the Python build tools
  337. run: |
  338. # Hack to get the latest patch version. Uncomment if needed
  339. #brew install python@3.10
  340. #export PYTHON_VERSION=$( $(brew --prefix)/opt/python@3.10/bin/python3 --version | cut -d ' ' -f 2 )
  341. curl "https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}-macos11.pkg" -o "python.pkg"
  342. sudo installer -pkg python.pkg -target /
  343. python3 --version
  344. - name: Install Requirements
  345. run: |
  346. brew install coreutils
  347. python3 devscripts/install_deps.py --user -o --include build
  348. python3 devscripts/install_deps.py --user --include pyinstaller
  349. - name: Prepare
  350. run: |
  351. python3 devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  352. python3 devscripts/make_lazy_extractors.py
  353. - name: Build
  354. run: |
  355. python3 -m bundle.pyinstaller
  356. mv dist/yt-dlp_macos dist/yt-dlp_macos_legacy
  357. - name: Verify --update-to
  358. if: vars.UPDATE_TO_VERIFICATION
  359. run: |
  360. chmod +x ./dist/yt-dlp_macos_legacy
  361. cp ./dist/yt-dlp_macos_legacy ./dist/yt-dlp_macos_legacy_downgraded
  362. version="$(./dist/yt-dlp_macos_legacy --version)"
  363. ./dist/yt-dlp_macos_legacy_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  364. downgraded_version="$(./dist/yt-dlp_macos_legacy_downgraded --version)"
  365. [[ "$version" != "$downgraded_version" ]]
  366. - name: Upload artifacts
  367. uses: actions/upload-artifact@v4
  368. with:
  369. name: build-bin-${{ github.job }}
  370. path: |
  371. dist/yt-dlp_macos_legacy
  372. compression-level: 0
  373. windows:
  374. needs: process
  375. if: inputs.windows
  376. runs-on: windows-latest
  377. steps:
  378. - uses: actions/checkout@v4
  379. - uses: actions/setup-python@v5
  380. with: # 3.8 is used for Win7 support
  381. python-version: "3.8"
  382. - name: Install Requirements
  383. run: | # Custom pyinstaller built with https://github.com/yt-dlp/pyinstaller-builds
  384. python devscripts/install_deps.py -o --include build
  385. python devscripts/install_deps.py --include curl-cffi
  386. python -m pip install -U "https://yt-dlp.github.io/Pyinstaller-Builds/x86_64/pyinstaller-6.7.0-py3-none-any.whl"
  387. - name: Prepare
  388. run: |
  389. python devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  390. python devscripts/make_lazy_extractors.py
  391. - name: Build
  392. run: |
  393. python -m bundle.pyinstaller
  394. python -m bundle.pyinstaller --onedir
  395. Move-Item ./dist/yt-dlp.exe ./dist/yt-dlp_real.exe
  396. Compress-Archive -Path ./dist/yt-dlp/* -DestinationPath ./dist/yt-dlp_win.zip
  397. - name: Install Requirements (py2exe)
  398. run: |
  399. python devscripts/install_deps.py --include py2exe
  400. - name: Build (py2exe)
  401. run: |
  402. python -m bundle.py2exe
  403. Move-Item ./dist/yt-dlp.exe ./dist/yt-dlp_min.exe
  404. Move-Item ./dist/yt-dlp_real.exe ./dist/yt-dlp.exe
  405. - name: Verify --update-to
  406. if: vars.UPDATE_TO_VERIFICATION
  407. run: |
  408. foreach ($name in @("yt-dlp","yt-dlp_min")) {
  409. Copy-Item "./dist/${name}.exe" "./dist/${name}_downgraded.exe"
  410. $version = & "./dist/${name}.exe" --version
  411. & "./dist/${name}_downgraded.exe" -v --update-to yt-dlp/yt-dlp@2023.03.04
  412. $downgraded_version = & "./dist/${name}_downgraded.exe" --version
  413. if ($version -eq $downgraded_version) {
  414. exit 1
  415. }
  416. }
  417. - name: Upload artifacts
  418. uses: actions/upload-artifact@v4
  419. with:
  420. name: build-bin-${{ github.job }}
  421. path: |
  422. dist/yt-dlp.exe
  423. dist/yt-dlp_min.exe
  424. dist/yt-dlp_win.zip
  425. compression-level: 0
  426. windows32:
  427. needs: process
  428. if: inputs.windows32
  429. runs-on: windows-latest
  430. steps:
  431. - uses: actions/checkout@v4
  432. - uses: actions/setup-python@v5
  433. with:
  434. python-version: "3.8"
  435. architecture: "x86"
  436. - name: Install Requirements
  437. run: |
  438. python devscripts/install_deps.py -o --include build
  439. python devscripts/install_deps.py
  440. python -m pip install -U "https://yt-dlp.github.io/Pyinstaller-Builds/i686/pyinstaller-6.7.0-py3-none-any.whl"
  441. - name: Prepare
  442. run: |
  443. python devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  444. python devscripts/make_lazy_extractors.py
  445. - name: Build
  446. run: |
  447. python -m bundle.pyinstaller
  448. - name: Verify --update-to
  449. if: vars.UPDATE_TO_VERIFICATION
  450. run: |
  451. foreach ($name in @("yt-dlp_x86")) {
  452. Copy-Item "./dist/${name}.exe" "./dist/${name}_downgraded.exe"
  453. $version = & "./dist/${name}.exe" --version
  454. & "./dist/${name}_downgraded.exe" -v --update-to yt-dlp/yt-dlp@2023.03.04
  455. $downgraded_version = & "./dist/${name}_downgraded.exe" --version
  456. if ($version -eq $downgraded_version) {
  457. exit 1
  458. }
  459. }
  460. - name: Upload artifacts
  461. uses: actions/upload-artifact@v4
  462. with:
  463. name: build-bin-${{ github.job }}
  464. path: |
  465. dist/yt-dlp_x86.exe
  466. compression-level: 0
  467. meta_files:
  468. if: always() && !cancelled()
  469. needs:
  470. - process
  471. - unix
  472. - linux_static
  473. - linux_arm
  474. - macos
  475. - macos_legacy
  476. - windows
  477. - windows32
  478. runs-on: ubuntu-latest
  479. steps:
  480. - uses: actions/download-artifact@v4
  481. with:
  482. path: artifact
  483. pattern: build-bin-*
  484. merge-multiple: true
  485. - name: Make SHA2-SUMS files
  486. run: |
  487. cd ./artifact/
  488. # make sure SHA sums are also printed to stdout
  489. sha256sum -- * | tee ../SHA2-256SUMS
  490. sha512sum -- * | tee ../SHA2-512SUMS
  491. # also print as permanent annotations to the summary page
  492. while read -r shasum; do
  493. echo "::notice title=${shasum##* }::sha256: ${shasum% *}"
  494. done < ../SHA2-256SUMS
  495. - name: Make Update spec
  496. run: |
  497. cat >> _update_spec << EOF
  498. # This file is used for regulating self-update
  499. lock 2022.08.18.36 .+ Python 3\.6
  500. lock 2023.11.16 (?!win_x86_exe).+ Python 3\.7
  501. lock 2023.11.16 win_x86_exe .+ Windows-(?:Vista|2008Server)
  502. lockV2 yt-dlp/yt-dlp 2022.08.18.36 .+ Python 3\.6
  503. lockV2 yt-dlp/yt-dlp 2023.11.16 (?!win_x86_exe).+ Python 3\.7
  504. lockV2 yt-dlp/yt-dlp 2023.11.16 win_x86_exe .+ Windows-(?:Vista|2008Server)
  505. lockV2 yt-dlp/yt-dlp-nightly-builds 2023.11.15.232826 (?!win_x86_exe).+ Python 3\.7
  506. lockV2 yt-dlp/yt-dlp-nightly-builds 2023.11.15.232826 win_x86_exe .+ Windows-(?:Vista|2008Server)
  507. lockV2 yt-dlp/yt-dlp-master-builds 2023.11.15.232812 (?!win_x86_exe).+ Python 3\.7
  508. lockV2 yt-dlp/yt-dlp-master-builds 2023.11.15.232812 win_x86_exe .+ Windows-(?:Vista|2008Server)
  509. EOF
  510. - name: Sign checksum files
  511. env:
  512. GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
  513. if: env.GPG_SIGNING_KEY != ''
  514. run: |
  515. gpg --batch --import <<< "${{ secrets.GPG_SIGNING_KEY }}"
  516. for signfile in ./SHA*SUMS; do
  517. gpg --batch --detach-sign "$signfile"
  518. done
  519. - name: Upload artifacts
  520. uses: actions/upload-artifact@v4
  521. with:
  522. name: build-${{ github.job }}
  523. path: |
  524. _update_spec
  525. SHA*SUMS*
  526. compression-level: 0
  527. overwrite: true