build.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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_arm:
  16. default: true
  17. type: boolean
  18. macos:
  19. default: true
  20. type: boolean
  21. macos_legacy:
  22. default: true
  23. type: boolean
  24. windows:
  25. default: true
  26. type: boolean
  27. windows32:
  28. default: true
  29. type: boolean
  30. meta_files:
  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, yt-dlp_linux, yt-dlp_linux.zip
  55. default: true
  56. type: boolean
  57. linux_arm:
  58. description: yt-dlp_linux_aarch64, yt-dlp_linux_armv7l
  59. default: true
  60. type: boolean
  61. macos:
  62. description: yt-dlp_macos, yt-dlp_macos.zip
  63. default: true
  64. type: boolean
  65. macos_legacy:
  66. description: yt-dlp_macos_legacy
  67. default: true
  68. type: boolean
  69. windows:
  70. description: yt-dlp.exe, yt-dlp_min.exe, yt-dlp_win.zip
  71. default: true
  72. type: boolean
  73. windows32:
  74. description: yt-dlp_x86.exe
  75. default: true
  76. type: boolean
  77. meta_files:
  78. description: SHA2-256SUMS, SHA2-512SUMS, _update_spec
  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. - uses: conda-incubator/setup-miniconda@v3
  112. with:
  113. miniforge-variant: Mambaforge
  114. use-mamba: true
  115. channels: conda-forge
  116. auto-update-conda: true
  117. activate-environment: ""
  118. auto-activate-base: false
  119. - name: Install Requirements
  120. run: |
  121. sudo apt -y install zip pandoc man sed
  122. cat > ./requirements.txt << EOF
  123. python=3.10.*
  124. brotli-python
  125. EOF
  126. python devscripts/install_deps.py --print \
  127. --exclude brotli --exclude brotlicffi \
  128. --include secretstorage --include pyinstaller >> ./requirements.txt
  129. mamba create -n build --file ./requirements.txt
  130. - name: Prepare
  131. run: |
  132. python devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  133. python devscripts/update_changelog.py -vv
  134. python devscripts/make_lazy_extractors.py
  135. - name: Build Unix platform-independent binary
  136. run: |
  137. make all tar
  138. - name: Build Unix standalone binary
  139. shell: bash -l {0}
  140. run: |
  141. unset LD_LIBRARY_PATH # Harmful; set by setup-python
  142. conda activate build
  143. python -m bundle.pyinstaller --onedir
  144. (cd ./dist/yt-dlp_linux && zip -r ../yt-dlp_linux.zip .)
  145. python -m bundle.pyinstaller
  146. mv ./dist/yt-dlp_linux ./yt-dlp_linux
  147. mv ./dist/yt-dlp_linux.zip ./yt-dlp_linux.zip
  148. - name: Verify --update-to
  149. if: vars.UPDATE_TO_VERIFICATION
  150. run: |
  151. binaries=("yt-dlp" "yt-dlp_linux")
  152. for binary in "${binaries[@]}"; do
  153. chmod +x ./${binary}
  154. cp ./${binary} ./${binary}_downgraded
  155. version="$(./${binary} --version)"
  156. ./${binary}_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  157. downgraded_version="$(./${binary}_downgraded --version)"
  158. [[ "$version" != "$downgraded_version" ]]
  159. done
  160. - name: Upload artifacts
  161. uses: actions/upload-artifact@v4
  162. with:
  163. name: build-bin-${{ github.job }}
  164. path: |
  165. yt-dlp
  166. yt-dlp.tar.gz
  167. yt-dlp_linux
  168. yt-dlp_linux.zip
  169. compression-level: 0
  170. linux_arm:
  171. needs: process
  172. if: inputs.linux_arm
  173. permissions:
  174. contents: read
  175. packages: write # for creating cache
  176. runs-on: ubuntu-latest
  177. strategy:
  178. matrix:
  179. architecture:
  180. - armv7
  181. - aarch64
  182. steps:
  183. - uses: actions/checkout@v4
  184. with:
  185. path: ./repo
  186. - name: Virtualized Install, Prepare & Build
  187. uses: yt-dlp/run-on-arch-action@v2
  188. with:
  189. # Ref: https://github.com/uraimo/run-on-arch-action/issues/55
  190. env: |
  191. GITHUB_WORKFLOW: build
  192. githubToken: ${{ github.token }} # To cache image
  193. arch: ${{ matrix.architecture }}
  194. distro: ubuntu18.04 # Standalone executable should be built on minimum supported OS
  195. dockerRunArgs: --volume "${PWD}/repo:/repo"
  196. install: | # Installing Python 3.10 from the Deadsnakes repo raises errors
  197. apt update
  198. apt -y install zlib1g-dev libffi-dev python3.8 python3.8-dev python3.8-distutils python3-pip
  199. python3.8 -m pip install -U pip setuptools wheel
  200. # Cannot access any files from the repo directory at this stage
  201. python3.8 -m pip install -U Pyinstaller mutagen pycryptodomex websockets brotli certifi secretstorage cffi
  202. run: |
  203. cd repo
  204. python3.8 devscripts/install_deps.py -o --include build
  205. python3.8 devscripts/install_deps.py --include pyinstaller --include secretstorage # Cached version may be out of date
  206. python3.8 devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  207. python3.8 devscripts/make_lazy_extractors.py
  208. python3.8 -m bundle.pyinstaller
  209. if ${{ vars.UPDATE_TO_VERIFICATION && 'true' || 'false' }}; then
  210. arch="${{ (matrix.architecture == 'armv7' && 'armv7l') || matrix.architecture }}"
  211. chmod +x ./dist/yt-dlp_linux_${arch}
  212. cp ./dist/yt-dlp_linux_${arch} ./dist/yt-dlp_linux_${arch}_downgraded
  213. version="$(./dist/yt-dlp_linux_${arch} --version)"
  214. ./dist/yt-dlp_linux_${arch}_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  215. downgraded_version="$(./dist/yt-dlp_linux_${arch}_downgraded --version)"
  216. [[ "$version" != "$downgraded_version" ]]
  217. fi
  218. - name: Upload artifacts
  219. uses: actions/upload-artifact@v4
  220. with:
  221. name: build-bin-linux_${{ matrix.architecture }}
  222. path: | # run-on-arch-action designates armv7l as armv7
  223. repo/dist/yt-dlp_linux_${{ (matrix.architecture == 'armv7' && 'armv7l') || matrix.architecture }}
  224. compression-level: 0
  225. macos:
  226. needs: process
  227. if: inputs.macos
  228. runs-on: macos-11
  229. steps:
  230. - uses: actions/checkout@v4
  231. # NB: Building universal2 does not work with python from actions/setup-python
  232. - name: Install Requirements
  233. run: |
  234. brew install coreutils
  235. python3 devscripts/install_deps.py --user -o --include build
  236. python3 devscripts/install_deps.py --print --include pyinstaller_macos > requirements.txt
  237. # We need to ignore wheels otherwise we break universal2 builds
  238. python3 -m pip install -U --user --no-binary :all: -r requirements.txt
  239. # We need to fuse our own universal2 wheels for curl_cffi
  240. python3 -m pip install -U --user delocate
  241. mkdir curl_cffi_whls curl_cffi_universal2
  242. python3 devscripts/install_deps.py --print -o --include curl_cffi > requirements.txt
  243. for platform in "macosx_11_0_arm64" "macosx_11_0_x86_64"; do
  244. python3 -m pip download \
  245. --only-binary=:all: \
  246. --platform "${platform}" \
  247. --pre -d curl_cffi_whls \
  248. -r requirements.txt
  249. done
  250. python3 -m delocate.cmd.delocate_fuse curl_cffi_whls/curl_cffi*.whl -w curl_cffi_universal2
  251. python3 -m delocate.cmd.delocate_fuse curl_cffi_whls/cffi*.whl -w curl_cffi_universal2
  252. cd curl_cffi_universal2
  253. for wheel in *cffi*.whl; do mv -n -- "${wheel}" "${wheel/x86_64/universal2}"; done
  254. python3 -m pip install -U --user *cffi*.whl
  255. - name: Prepare
  256. run: |
  257. python3 devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  258. python3 devscripts/make_lazy_extractors.py
  259. - name: Build
  260. run: |
  261. python3 -m bundle.pyinstaller --target-architecture universal2 --onedir
  262. (cd ./dist/yt-dlp_macos && zip -r ../yt-dlp_macos.zip .)
  263. python3 -m bundle.pyinstaller --target-architecture universal2
  264. - name: Verify --update-to
  265. if: vars.UPDATE_TO_VERIFICATION
  266. run: |
  267. chmod +x ./dist/yt-dlp_macos
  268. cp ./dist/yt-dlp_macos ./dist/yt-dlp_macos_downgraded
  269. version="$(./dist/yt-dlp_macos --version)"
  270. ./dist/yt-dlp_macos_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  271. downgraded_version="$(./dist/yt-dlp_macos_downgraded --version)"
  272. [[ "$version" != "$downgraded_version" ]]
  273. - name: Upload artifacts
  274. uses: actions/upload-artifact@v4
  275. with:
  276. name: build-bin-${{ github.job }}
  277. path: |
  278. dist/yt-dlp_macos
  279. dist/yt-dlp_macos.zip
  280. compression-level: 0
  281. macos_legacy:
  282. needs: process
  283. if: inputs.macos_legacy
  284. runs-on: macos-latest
  285. steps:
  286. - uses: actions/checkout@v4
  287. - name: Install Python
  288. # We need the official Python, because the GA ones only support newer macOS versions
  289. env:
  290. PYTHON_VERSION: 3.10.5
  291. MACOSX_DEPLOYMENT_TARGET: 10.9 # Used up by the Python build tools
  292. run: |
  293. # Hack to get the latest patch version. Uncomment if needed
  294. #brew install python@3.10
  295. #export PYTHON_VERSION=$( $(brew --prefix)/opt/python@3.10/bin/python3 --version | cut -d ' ' -f 2 )
  296. curl https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}-macos11.pkg -o "python.pkg"
  297. sudo installer -pkg python.pkg -target /
  298. python3 --version
  299. - name: Install Requirements
  300. run: |
  301. brew install coreutils
  302. python3 devscripts/install_deps.py --user -o --include build
  303. python3 devscripts/install_deps.py --user --include pyinstaller_macos --include curl_cffi
  304. - name: Prepare
  305. run: |
  306. python3 devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  307. python3 devscripts/make_lazy_extractors.py
  308. - name: Build
  309. run: |
  310. python3 -m bundle.pyinstaller
  311. mv dist/yt-dlp_macos dist/yt-dlp_macos_legacy
  312. - name: Verify --update-to
  313. if: vars.UPDATE_TO_VERIFICATION
  314. run: |
  315. chmod +x ./dist/yt-dlp_macos_legacy
  316. cp ./dist/yt-dlp_macos_legacy ./dist/yt-dlp_macos_legacy_downgraded
  317. version="$(./dist/yt-dlp_macos_legacy --version)"
  318. ./dist/yt-dlp_macos_legacy_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  319. downgraded_version="$(./dist/yt-dlp_macos_legacy_downgraded --version)"
  320. [[ "$version" != "$downgraded_version" ]]
  321. - name: Upload artifacts
  322. uses: actions/upload-artifact@v4
  323. with:
  324. name: build-bin-${{ github.job }}
  325. path: |
  326. dist/yt-dlp_macos_legacy
  327. compression-level: 0
  328. windows:
  329. needs: process
  330. if: inputs.windows
  331. runs-on: windows-latest
  332. steps:
  333. - uses: actions/checkout@v4
  334. - uses: actions/setup-python@v5
  335. with: # 3.8 is used for Win7 support
  336. python-version: "3.8"
  337. - name: Install Requirements
  338. run: | # Custom pyinstaller built with https://github.com/yt-dlp/pyinstaller-builds
  339. python devscripts/install_deps.py -o --include build
  340. python devscripts/install_deps.py --include py2exe --include curl_cffi
  341. python -m pip install -U "https://yt-dlp.github.io/Pyinstaller-Builds/x86_64/pyinstaller-5.8.0-py3-none-any.whl"
  342. - name: Prepare
  343. run: |
  344. python devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  345. python devscripts/make_lazy_extractors.py
  346. - name: Build
  347. run: |
  348. python -m bundle.py2exe
  349. Move-Item ./dist/yt-dlp.exe ./dist/yt-dlp_min.exe
  350. python -m bundle.pyinstaller
  351. python -m bundle.pyinstaller --onedir
  352. Compress-Archive -Path ./dist/yt-dlp/* -DestinationPath ./dist/yt-dlp_win.zip
  353. - name: Verify --update-to
  354. if: vars.UPDATE_TO_VERIFICATION
  355. run: |
  356. foreach ($name in @("yt-dlp","yt-dlp_min")) {
  357. Copy-Item "./dist/${name}.exe" "./dist/${name}_downgraded.exe"
  358. $version = & "./dist/${name}.exe" --version
  359. & "./dist/${name}_downgraded.exe" -v --update-to yt-dlp/yt-dlp@2023.03.04
  360. $downgraded_version = & "./dist/${name}_downgraded.exe" --version
  361. if ($version -eq $downgraded_version) {
  362. exit 1
  363. }
  364. }
  365. - name: Upload artifacts
  366. uses: actions/upload-artifact@v4
  367. with:
  368. name: build-bin-${{ github.job }}
  369. path: |
  370. dist/yt-dlp.exe
  371. dist/yt-dlp_min.exe
  372. dist/yt-dlp_win.zip
  373. compression-level: 0
  374. windows32:
  375. needs: process
  376. if: inputs.windows32
  377. runs-on: windows-latest
  378. steps:
  379. - uses: actions/checkout@v4
  380. - uses: actions/setup-python@v5
  381. with:
  382. python-version: "3.8"
  383. architecture: "x86"
  384. - name: Install Requirements
  385. run: |
  386. python devscripts/install_deps.py -o --include build
  387. python devscripts/install_deps.py
  388. python -m pip install -U "https://yt-dlp.github.io/Pyinstaller-Builds/i686/pyinstaller-5.8.0-py3-none-any.whl"
  389. - name: Prepare
  390. run: |
  391. python devscripts/update-version.py -c "${{ inputs.channel }}" -r "${{ needs.process.outputs.origin }}" "${{ inputs.version }}"
  392. python devscripts/make_lazy_extractors.py
  393. - name: Build
  394. run: |
  395. python -m bundle.pyinstaller
  396. - name: Verify --update-to
  397. if: vars.UPDATE_TO_VERIFICATION
  398. run: |
  399. foreach ($name in @("yt-dlp_x86")) {
  400. Copy-Item "./dist/${name}.exe" "./dist/${name}_downgraded.exe"
  401. $version = & "./dist/${name}.exe" --version
  402. & "./dist/${name}_downgraded.exe" -v --update-to yt-dlp/yt-dlp@2023.03.04
  403. $downgraded_version = & "./dist/${name}_downgraded.exe" --version
  404. if ($version -eq $downgraded_version) {
  405. exit 1
  406. }
  407. }
  408. - name: Upload artifacts
  409. uses: actions/upload-artifact@v4
  410. with:
  411. name: build-bin-${{ github.job }}
  412. path: |
  413. dist/yt-dlp_x86.exe
  414. compression-level: 0
  415. meta_files:
  416. if: inputs.meta_files && always() && !cancelled()
  417. needs:
  418. - process
  419. - unix
  420. - linux_arm
  421. - macos
  422. - macos_legacy
  423. - windows
  424. - windows32
  425. runs-on: ubuntu-latest
  426. steps:
  427. - uses: actions/download-artifact@v4
  428. with:
  429. path: artifact
  430. pattern: build-bin-*
  431. merge-multiple: true
  432. - name: Make SHA2-SUMS files
  433. run: |
  434. cd ./artifact/
  435. sha256sum * > ../SHA2-256SUMS
  436. sha512sum * > ../SHA2-512SUMS
  437. - name: Make Update spec
  438. run: |
  439. cat >> _update_spec << EOF
  440. # This file is used for regulating self-update
  441. lock 2022.08.18.36 .+ Python 3\.6
  442. lock 2023.11.16 (?!win_x86_exe).+ Python 3\.7
  443. lock 2023.11.16 win_x86_exe .+ Windows-(?:Vista|2008Server)
  444. lockV2 yt-dlp/yt-dlp 2022.08.18.36 .+ Python 3\.6
  445. lockV2 yt-dlp/yt-dlp 2023.11.16 (?!win_x86_exe).+ Python 3\.7
  446. lockV2 yt-dlp/yt-dlp 2023.11.16 win_x86_exe .+ Windows-(?:Vista|2008Server)
  447. lockV2 yt-dlp/yt-dlp-nightly-builds 2023.11.15.232826 (?!win_x86_exe).+ Python 3\.7
  448. lockV2 yt-dlp/yt-dlp-nightly-builds 2023.11.15.232826 win_x86_exe .+ Windows-(?:Vista|2008Server)
  449. lockV2 yt-dlp/yt-dlp-master-builds 2023.11.15.232812 (?!win_x86_exe).+ Python 3\.7
  450. lockV2 yt-dlp/yt-dlp-master-builds 2023.11.15.232812 win_x86_exe .+ Windows-(?:Vista|2008Server)
  451. EOF
  452. - name: Sign checksum files
  453. env:
  454. GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
  455. if: env.GPG_SIGNING_KEY != ''
  456. run: |
  457. gpg --batch --import <<< "${{ secrets.GPG_SIGNING_KEY }}"
  458. for signfile in ./SHA*SUMS; do
  459. gpg --batch --detach-sign "$signfile"
  460. done
  461. - name: Upload artifacts
  462. uses: actions/upload-artifact@v4
  463. with:
  464. name: build-${{ github.job }}
  465. path: |
  466. _update_spec
  467. SHA*SUMS*
  468. compression-level: 0
  469. overwrite: true