build.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. secrets:
  34. GPG_SIGNING_KEY:
  35. required: false
  36. workflow_dispatch:
  37. inputs:
  38. version:
  39. description: Version tag (YYYY.MM.DD[.REV])
  40. required: true
  41. type: string
  42. channel:
  43. description: Update channel (stable/nightly/...)
  44. required: true
  45. default: stable
  46. type: string
  47. unix:
  48. description: yt-dlp, yt-dlp.tar.gz, yt-dlp_linux, yt-dlp_linux.zip
  49. default: true
  50. type: boolean
  51. linux_arm:
  52. description: yt-dlp_linux_aarch64, yt-dlp_linux_armv7l
  53. default: true
  54. type: boolean
  55. macos:
  56. description: yt-dlp_macos, yt-dlp_macos.zip
  57. default: true
  58. type: boolean
  59. macos_legacy:
  60. description: yt-dlp_macos_legacy
  61. default: true
  62. type: boolean
  63. windows:
  64. description: yt-dlp.exe, yt-dlp_min.exe, yt-dlp_win.zip
  65. default: true
  66. type: boolean
  67. windows32:
  68. description: yt-dlp_x86.exe
  69. default: true
  70. type: boolean
  71. meta_files:
  72. description: SHA2-256SUMS, SHA2-512SUMS, _update_spec
  73. default: true
  74. type: boolean
  75. permissions:
  76. contents: read
  77. jobs:
  78. unix:
  79. if: inputs.unix
  80. runs-on: ubuntu-latest
  81. steps:
  82. - uses: actions/checkout@v3
  83. - uses: actions/setup-python@v4
  84. with:
  85. python-version: "3.10"
  86. - uses: conda-incubator/setup-miniconda@v2
  87. with:
  88. miniforge-variant: Mambaforge
  89. use-mamba: true
  90. channels: conda-forge
  91. auto-update-conda: true
  92. activate-environment: ""
  93. auto-activate-base: false
  94. - name: Install Requirements
  95. run: |
  96. sudo apt-get -y install zip pandoc man sed
  97. python -m pip install -U pip setuptools wheel
  98. python -m pip install -U Pyinstaller -r requirements.txt
  99. reqs=$(mktemp)
  100. cat > $reqs << EOF
  101. python=3.10.*
  102. pyinstaller
  103. cffi
  104. brotli-python
  105. EOF
  106. sed '/^brotli.*/d' requirements.txt >> $reqs
  107. mamba create -n build --file $reqs
  108. - name: Prepare
  109. run: |
  110. python devscripts/update-version.py -c ${{ inputs.channel }} ${{ inputs.version }}
  111. python devscripts/make_lazy_extractors.py
  112. - name: Build Unix platform-independent binary
  113. run: |
  114. make all tar
  115. - name: Build Unix standalone binary
  116. shell: bash -l {0}
  117. run: |
  118. unset LD_LIBRARY_PATH # Harmful; set by setup-python
  119. conda activate build
  120. python pyinst.py --onedir
  121. (cd ./dist/yt-dlp_linux && zip -r ../yt-dlp_linux.zip .)
  122. python pyinst.py
  123. mv ./dist/yt-dlp_linux ./yt-dlp_linux
  124. mv ./dist/yt-dlp_linux.zip ./yt-dlp_linux.zip
  125. - name: Verify --update-to
  126. if: vars.UPDATE_TO_VERIFICATION
  127. run: |
  128. binaries=("yt-dlp" "yt-dlp_linux")
  129. for binary in "${binaries[@]}"; do
  130. chmod +x ./${binary}
  131. cp ./${binary} ./${binary}_downgraded
  132. version="$(./${binary} --version)"
  133. ./${binary}_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  134. downgraded_version="$(./${binary}_downgraded --version)"
  135. [[ "$version" != "$downgraded_version" ]]
  136. done
  137. - name: Upload artifacts
  138. uses: actions/upload-artifact@v3
  139. with:
  140. path: |
  141. yt-dlp
  142. yt-dlp.tar.gz
  143. yt-dlp_linux
  144. yt-dlp_linux.zip
  145. linux_arm:
  146. if: inputs.linux_arm
  147. permissions:
  148. contents: read
  149. packages: write # for creating cache
  150. runs-on: ubuntu-latest
  151. strategy:
  152. matrix:
  153. architecture:
  154. - armv7
  155. - aarch64
  156. steps:
  157. - uses: actions/checkout@v3
  158. with:
  159. path: ./repo
  160. - name: Virtualized Install, Prepare & Build
  161. uses: yt-dlp/run-on-arch-action@v2
  162. with:
  163. # Ref: https://github.com/uraimo/run-on-arch-action/issues/55
  164. env: |
  165. GITHUB_WORKFLOW: build
  166. githubToken: ${{ github.token }} # To cache image
  167. arch: ${{ matrix.architecture }}
  168. distro: ubuntu18.04 # Standalone executable should be built on minimum supported OS
  169. dockerRunArgs: --volume "${PWD}/repo:/repo"
  170. install: | # Installing Python 3.10 from the Deadsnakes repo raises errors
  171. apt update
  172. apt -y install zlib1g-dev python3.8 python3.8-dev python3.8-distutils python3-pip
  173. python3.8 -m pip install -U pip setuptools wheel
  174. # Cannot access requirements.txt from the repo directory at this stage
  175. python3.8 -m pip install -U Pyinstaller mutagen pycryptodomex websockets brotli certifi
  176. run: |
  177. cd repo
  178. python3.8 -m pip install -U Pyinstaller -r requirements.txt # Cached version may be out of date
  179. python3.8 devscripts/update-version.py -c ${{ inputs.channel }} ${{ inputs.version }}
  180. python3.8 devscripts/make_lazy_extractors.py
  181. python3.8 pyinst.py
  182. if ${{ vars.UPDATE_TO_VERIFICATION && 'true' || 'false' }}; then
  183. arch="${{ (matrix.architecture == 'armv7' && 'armv7l') || matrix.architecture }}"
  184. chmod +x ./dist/yt-dlp_linux_${arch}
  185. cp ./dist/yt-dlp_linux_${arch} ./dist/yt-dlp_linux_${arch}_downgraded
  186. version="$(./dist/yt-dlp_linux_${arch} --version)"
  187. ./dist/yt-dlp_linux_${arch}_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  188. downgraded_version="$(./dist/yt-dlp_linux_${arch}_downgraded --version)"
  189. [[ "$version" != "$downgraded_version" ]]
  190. fi
  191. - name: Upload artifacts
  192. uses: actions/upload-artifact@v3
  193. with:
  194. path: | # run-on-arch-action designates armv7l as armv7
  195. repo/dist/yt-dlp_linux_${{ (matrix.architecture == 'armv7' && 'armv7l') || matrix.architecture }}
  196. macos:
  197. if: inputs.macos
  198. runs-on: macos-11
  199. steps:
  200. - uses: actions/checkout@v3
  201. # NB: Building universal2 does not work with python from actions/setup-python
  202. - name: Install Requirements
  203. run: |
  204. brew install coreutils
  205. python3 -m pip install -U --user pip setuptools wheel
  206. # We need to ignore wheels otherwise we break universal2 builds
  207. python3 -m pip install -U --user --no-binary :all: Pyinstaller -r requirements.txt
  208. - name: Prepare
  209. run: |
  210. python3 devscripts/update-version.py -c ${{ inputs.channel }} ${{ inputs.version }}
  211. python3 devscripts/make_lazy_extractors.py
  212. - name: Build
  213. run: |
  214. python3 pyinst.py --target-architecture universal2 --onedir
  215. (cd ./dist/yt-dlp_macos && zip -r ../yt-dlp_macos.zip .)
  216. python3 pyinst.py --target-architecture universal2
  217. - name: Verify --update-to
  218. if: vars.UPDATE_TO_VERIFICATION
  219. run: |
  220. chmod +x ./dist/yt-dlp_macos
  221. cp ./dist/yt-dlp_macos ./dist/yt-dlp_macos_downgraded
  222. version="$(./dist/yt-dlp_macos --version)"
  223. ./dist/yt-dlp_macos_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  224. downgraded_version="$(./dist/yt-dlp_macos_downgraded --version)"
  225. [[ "$version" != "$downgraded_version" ]]
  226. - name: Upload artifacts
  227. uses: actions/upload-artifact@v3
  228. with:
  229. path: |
  230. dist/yt-dlp_macos
  231. dist/yt-dlp_macos.zip
  232. macos_legacy:
  233. if: inputs.macos_legacy
  234. runs-on: macos-latest
  235. steps:
  236. - uses: actions/checkout@v3
  237. - name: Install Python
  238. # We need the official Python, because the GA ones only support newer macOS versions
  239. env:
  240. PYTHON_VERSION: 3.10.5
  241. MACOSX_DEPLOYMENT_TARGET: 10.9 # Used up by the Python build tools
  242. run: |
  243. # Hack to get the latest patch version. Uncomment if needed
  244. #brew install python@3.10
  245. #export PYTHON_VERSION=$( $(brew --prefix)/opt/python@3.10/bin/python3 --version | cut -d ' ' -f 2 )
  246. curl https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}-macos11.pkg -o "python.pkg"
  247. sudo installer -pkg python.pkg -target /
  248. python3 --version
  249. - name: Install Requirements
  250. run: |
  251. brew install coreutils
  252. python3 -m pip install -U --user pip setuptools wheel
  253. python3 -m pip install -U --user Pyinstaller -r requirements.txt
  254. - name: Prepare
  255. run: |
  256. python3 devscripts/update-version.py -c ${{ inputs.channel }} ${{ inputs.version }}
  257. python3 devscripts/make_lazy_extractors.py
  258. - name: Build
  259. run: |
  260. python3 pyinst.py
  261. mv dist/yt-dlp_macos dist/yt-dlp_macos_legacy
  262. - name: Verify --update-to
  263. if: vars.UPDATE_TO_VERIFICATION
  264. run: |
  265. chmod +x ./dist/yt-dlp_macos_legacy
  266. cp ./dist/yt-dlp_macos_legacy ./dist/yt-dlp_macos_legacy_downgraded
  267. version="$(./dist/yt-dlp_macos_legacy --version)"
  268. ./dist/yt-dlp_macos_legacy_downgraded -v --update-to yt-dlp/yt-dlp@2023.03.04
  269. downgraded_version="$(./dist/yt-dlp_macos_legacy_downgraded --version)"
  270. [[ "$version" != "$downgraded_version" ]]
  271. - name: Upload artifacts
  272. uses: actions/upload-artifact@v3
  273. with:
  274. path: |
  275. dist/yt-dlp_macos_legacy
  276. windows:
  277. if: inputs.windows
  278. runs-on: windows-latest
  279. steps:
  280. - uses: actions/checkout@v3
  281. - uses: actions/setup-python@v4
  282. with: # 3.8 is used for Win7 support
  283. python-version: "3.8"
  284. - name: Install Requirements
  285. run: | # Custom pyinstaller built with https://github.com/yt-dlp/pyinstaller-builds
  286. python -m pip install -U pip setuptools wheel py2exe
  287. pip install -U "https://yt-dlp.github.io/Pyinstaller-Builds/x86_64/pyinstaller-5.8.0-py3-none-any.whl" -r requirements.txt
  288. - name: Prepare
  289. run: |
  290. python devscripts/update-version.py -c ${{ inputs.channel }} ${{ inputs.version }}
  291. python devscripts/make_lazy_extractors.py
  292. - name: Build
  293. run: |
  294. python setup.py py2exe
  295. Move-Item ./dist/yt-dlp.exe ./dist/yt-dlp_min.exe
  296. python pyinst.py
  297. python pyinst.py --onedir
  298. Compress-Archive -Path ./dist/yt-dlp/* -DestinationPath ./dist/yt-dlp_win.zip
  299. - name: Verify --update-to
  300. if: vars.UPDATE_TO_VERIFICATION
  301. run: |
  302. foreach ($name in @("yt-dlp","yt-dlp_min")) {
  303. Copy-Item "./dist/${name}.exe" "./dist/${name}_downgraded.exe"
  304. $version = & "./dist/${name}.exe" --version
  305. & "./dist/${name}_downgraded.exe" -v --update-to yt-dlp/yt-dlp@2023.03.04
  306. $downgraded_version = & "./dist/${name}_downgraded.exe" --version
  307. if ($version -eq $downgraded_version) {
  308. exit 1
  309. }
  310. }
  311. - name: Upload artifacts
  312. uses: actions/upload-artifact@v3
  313. with:
  314. path: |
  315. dist/yt-dlp.exe
  316. dist/yt-dlp_min.exe
  317. dist/yt-dlp_win.zip
  318. windows32:
  319. if: inputs.windows32
  320. runs-on: windows-latest
  321. steps:
  322. - uses: actions/checkout@v3
  323. - uses: actions/setup-python@v4
  324. with: # 3.7 is used for Vista support. See https://github.com/yt-dlp/yt-dlp/issues/390
  325. python-version: "3.7"
  326. architecture: "x86"
  327. - name: Install Requirements
  328. run: |
  329. python -m pip install -U pip setuptools wheel
  330. pip install -U "https://yt-dlp.github.io/Pyinstaller-Builds/i686/pyinstaller-5.8.0-py3-none-any.whl" -r requirements.txt
  331. - name: Prepare
  332. run: |
  333. python devscripts/update-version.py -c ${{ inputs.channel }} ${{ inputs.version }}
  334. python devscripts/make_lazy_extractors.py
  335. - name: Build
  336. run: |
  337. python pyinst.py
  338. - name: Verify --update-to
  339. if: vars.UPDATE_TO_VERIFICATION
  340. run: |
  341. foreach ($name in @("yt-dlp_x86")) {
  342. Copy-Item "./dist/${name}.exe" "./dist/${name}_downgraded.exe"
  343. $version = & "./dist/${name}.exe" --version
  344. & "./dist/${name}_downgraded.exe" -v --update-to yt-dlp/yt-dlp@2023.03.04
  345. $downgraded_version = & "./dist/${name}_downgraded.exe" --version
  346. if ($version -eq $downgraded_version) {
  347. exit 1
  348. }
  349. }
  350. - name: Upload artifacts
  351. uses: actions/upload-artifact@v3
  352. with:
  353. path: |
  354. dist/yt-dlp_x86.exe
  355. meta_files:
  356. if: inputs.meta_files && always() && !cancelled()
  357. needs:
  358. - unix
  359. - linux_arm
  360. - macos
  361. - macos_legacy
  362. - windows
  363. - windows32
  364. runs-on: ubuntu-latest
  365. steps:
  366. - uses: actions/download-artifact@v3
  367. - name: Make SHA2-SUMS files
  368. run: |
  369. cd ./artifact/
  370. sha256sum * > ../SHA2-256SUMS
  371. sha512sum * > ../SHA2-512SUMS
  372. - name: Make Update spec
  373. run: |
  374. cat >> _update_spec << EOF
  375. # This file is used for regulating self-update
  376. lock 2022.08.18.36 .+ Python 3.6
  377. EOF
  378. - name: Sign checksum files
  379. env:
  380. GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
  381. if: env.GPG_SIGNING_KEY != ''
  382. run: |
  383. gpg --batch --import <<< "${{ secrets.GPG_SIGNING_KEY }}"
  384. for signfile in ./SHA*SUMS; do
  385. gpg --batch --detach-sign "$signfile"
  386. done
  387. - name: Upload artifacts
  388. uses: actions/upload-artifact@v3
  389. with:
  390. path: |
  391. SHA*SUMS*
  392. _update_spec