release.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. name: Release
  2. on:
  3. workflow_call:
  4. inputs:
  5. source:
  6. required: false
  7. default: ''
  8. type: string
  9. target:
  10. required: false
  11. default: ''
  12. type: string
  13. version:
  14. required: false
  15. default: ''
  16. type: string
  17. prerelease:
  18. required: false
  19. default: true
  20. type: boolean
  21. workflow_dispatch:
  22. inputs:
  23. source:
  24. description: |
  25. SOURCE of this release's updates:
  26. channel, repo, tag, or channel/repo@tag
  27. (default: <current_repo>)
  28. required: false
  29. default: ''
  30. type: string
  31. target:
  32. description: |
  33. TARGET to publish this release to:
  34. channel, tag, or channel@tag
  35. (default: <source> if writable else <current_repo>[@source_tag])
  36. required: false
  37. default: ''
  38. type: string
  39. version:
  40. description: |
  41. VERSION: yyyy.mm.dd[.rev] or rev
  42. (default: auto-generated)
  43. required: false
  44. default: ''
  45. type: string
  46. prerelease:
  47. description: Pre-release
  48. default: false
  49. type: boolean
  50. permissions:
  51. contents: read
  52. jobs:
  53. prepare:
  54. permissions:
  55. contents: write
  56. runs-on: ubuntu-latest
  57. outputs:
  58. channel: ${{ steps.setup_variables.outputs.channel }}
  59. version: ${{ steps.setup_variables.outputs.version }}
  60. target_repo: ${{ steps.setup_variables.outputs.target_repo }}
  61. target_repo_token: ${{ steps.setup_variables.outputs.target_repo_token }}
  62. target_tag: ${{ steps.setup_variables.outputs.target_tag }}
  63. pypi_project: ${{ steps.setup_variables.outputs.pypi_project }}
  64. pypi_suffix: ${{ steps.setup_variables.outputs.pypi_suffix }}
  65. head_sha: ${{ steps.get_target.outputs.head_sha }}
  66. steps:
  67. - uses: actions/checkout@v4
  68. with:
  69. fetch-depth: 0
  70. - uses: actions/setup-python@v5
  71. with:
  72. python-version: "3.10"
  73. - name: Process inputs
  74. id: process_inputs
  75. run: |
  76. cat << EOF
  77. ::group::Inputs
  78. prerelease=${{ inputs.prerelease }}
  79. source=${{ inputs.source }}
  80. target=${{ inputs.target }}
  81. version=${{ inputs.version }}
  82. ::endgroup::
  83. EOF
  84. IFS='@' read -r source_repo source_tag <<<"${{ inputs.source }}"
  85. IFS='@' read -r target_repo target_tag <<<"${{ inputs.target }}"
  86. cat << EOF >> "$GITHUB_OUTPUT"
  87. source_repo=${source_repo}
  88. source_tag=${source_tag}
  89. target_repo=${target_repo}
  90. target_tag=${target_tag}
  91. EOF
  92. - name: Setup variables
  93. id: setup_variables
  94. env:
  95. source_repo: ${{ steps.process_inputs.outputs.source_repo }}
  96. source_tag: ${{ steps.process_inputs.outputs.source_tag }}
  97. target_repo: ${{ steps.process_inputs.outputs.target_repo }}
  98. target_tag: ${{ steps.process_inputs.outputs.target_tag }}
  99. run: |
  100. # unholy bash monstrosity (sincere apologies)
  101. fallback_token () {
  102. if ${{ !secrets.ARCHIVE_REPO_TOKEN }}; then
  103. echo "::error::Repository access secret ${target_repo_token^^} not found"
  104. exit 1
  105. fi
  106. target_repo_token=ARCHIVE_REPO_TOKEN
  107. return 0
  108. }
  109. source_is_channel=0
  110. [[ "${source_repo}" == 'stable' ]] && source_repo='yt-dlp/yt-dlp'
  111. if [[ -z "${source_repo}" ]]; then
  112. source_repo='${{ github.repository }}'
  113. elif [[ '${{ vars[format('{0}_archive_repo', env.source_repo)] }}' ]]; then
  114. source_is_channel=1
  115. source_channel='${{ vars[format('{0}_archive_repo', env.source_repo)] }}'
  116. elif [[ -z "${source_tag}" && "${source_repo}" != */* ]]; then
  117. source_tag="${source_repo}"
  118. source_repo='${{ github.repository }}'
  119. fi
  120. resolved_source="${source_repo}"
  121. if [[ "${source_tag}" ]]; then
  122. resolved_source="${resolved_source}@${source_tag}"
  123. elif [[ "${source_repo}" == 'yt-dlp/yt-dlp' ]]; then
  124. resolved_source='stable'
  125. fi
  126. revision="${{ (inputs.prerelease || !vars.PUSH_VERSION_COMMIT) && '$(date -u +"%H%M%S")' || '' }}"
  127. version="$(
  128. python devscripts/update-version.py \
  129. -c "${resolved_source}" -r "${{ github.repository }}" ${{ inputs.version || '$revision' }} | \
  130. grep -Po "version=\K\d+\.\d+\.\d+(\.\d+)?")"
  131. if [[ "${target_repo}" ]]; then
  132. if [[ -z "${target_tag}" ]]; then
  133. if [[ '${{ vars[format('{0}_archive_repo', env.target_repo)] }}' ]]; then
  134. target_tag="${source_tag:-${version}}"
  135. else
  136. target_tag="${target_repo}"
  137. target_repo='${{ github.repository }}'
  138. fi
  139. fi
  140. if [[ "${target_repo}" != '${{ github.repository}}' ]]; then
  141. target_repo='${{ vars[format('{0}_archive_repo', env.target_repo)] }}'
  142. target_repo_token='${{ env.target_repo }}_archive_repo_token'
  143. ${{ !!secrets[format('{0}_archive_repo_token', env.target_repo)] }} || fallback_token
  144. pypi_project='${{ vars[format('{0}_pypi_project', env.target_repo)] }}'
  145. pypi_suffix='${{ vars[format('{0}_pypi_suffix', env.target_repo)] }}'
  146. fi
  147. else
  148. target_tag="${source_tag:-${version}}"
  149. if ((source_is_channel)); then
  150. target_repo="${source_channel}"
  151. target_repo_token='${{ env.source_repo }}_archive_repo_token'
  152. ${{ !!secrets[format('{0}_archive_repo_token', env.source_repo)] }} || fallback_token
  153. pypi_project='${{ vars[format('{0}_pypi_project', env.source_repo)] }}'
  154. pypi_suffix='${{ vars[format('{0}_pypi_suffix', env.source_repo)] }}'
  155. else
  156. target_repo='${{ github.repository }}'
  157. fi
  158. fi
  159. if [[ "${target_repo}" == '${{ github.repository }}' ]] && ${{ !inputs.prerelease }}; then
  160. pypi_project='${{ vars.PYPI_PROJECT }}'
  161. fi
  162. echo "::group::Output variables"
  163. cat << EOF | tee -a "$GITHUB_OUTPUT"
  164. channel=${resolved_source}
  165. version=${version}
  166. target_repo=${target_repo}
  167. target_repo_token=${target_repo_token}
  168. target_tag=${target_tag}
  169. pypi_project=${pypi_project}
  170. pypi_suffix=${pypi_suffix}
  171. EOF
  172. echo "::endgroup::"
  173. - name: Update documentation
  174. env:
  175. version: ${{ steps.setup_variables.outputs.version }}
  176. target_repo: ${{ steps.setup_variables.outputs.target_repo }}
  177. if: |
  178. !inputs.prerelease && env.target_repo == github.repository
  179. run: |
  180. python devscripts/update_changelog.py -vv
  181. make doc
  182. - name: Push to release
  183. id: push_release
  184. env:
  185. version: ${{ steps.setup_variables.outputs.version }}
  186. target_repo: ${{ steps.setup_variables.outputs.target_repo }}
  187. if: |
  188. !inputs.prerelease && env.target_repo == github.repository
  189. run: |
  190. git config --global user.name "github-actions[bot]"
  191. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  192. git add -u
  193. git commit -m "Release ${{ env.version }}" \
  194. -m "Created by: ${{ github.event.sender.login }}" -m ":ci skip all"
  195. git push origin --force ${{ github.event.ref }}:release
  196. - name: Get target commitish
  197. id: get_target
  198. run: |
  199. echo "head_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
  200. - name: Update master
  201. env:
  202. target_repo: ${{ steps.setup_variables.outputs.target_repo }}
  203. if: |
  204. vars.PUSH_VERSION_COMMIT != '' && !inputs.prerelease && env.target_repo == github.repository
  205. run: git push origin ${{ github.event.ref }}
  206. build:
  207. needs: prepare
  208. uses: ./.github/workflows/build.yml
  209. with:
  210. version: ${{ needs.prepare.outputs.version }}
  211. channel: ${{ needs.prepare.outputs.channel }}
  212. origin: ${{ needs.prepare.outputs.target_repo }}
  213. permissions:
  214. contents: read
  215. packages: write # For package cache
  216. actions: write # For cleaning up cache
  217. secrets:
  218. GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
  219. publish_pypi:
  220. needs: [prepare, build]
  221. if: ${{ needs.prepare.outputs.pypi_project }}
  222. runs-on: ubuntu-latest
  223. permissions:
  224. id-token: write # mandatory for trusted publishing
  225. steps:
  226. - uses: actions/checkout@v4
  227. with:
  228. fetch-depth: 0
  229. - uses: actions/setup-python@v5
  230. with:
  231. python-version: "3.10"
  232. - name: Install Requirements
  233. run: |
  234. sudo apt -y install pandoc man
  235. python devscripts/install_deps.py -o --include build
  236. - name: Prepare
  237. env:
  238. version: ${{ needs.prepare.outputs.version }}
  239. suffix: ${{ needs.prepare.outputs.pypi_suffix }}
  240. channel: ${{ needs.prepare.outputs.channel }}
  241. target_repo: ${{ needs.prepare.outputs.target_repo }}
  242. pypi_project: ${{ needs.prepare.outputs.pypi_project }}
  243. run: |
  244. python devscripts/update-version.py -c "${{ env.channel }}" -r "${{ env.target_repo }}" -s "${{ env.suffix }}" "${{ env.version }}"
  245. python devscripts/update_changelog.py -vv
  246. python devscripts/make_lazy_extractors.py
  247. sed -i -E '0,/(name = ")[^"]+(")/s//\1${{ env.pypi_project }}\2/' pyproject.toml
  248. - name: Build
  249. run: |
  250. rm -rf dist/*
  251. make pypi-files
  252. printf '%s\n\n' \
  253. 'Official repository: <https://github.com/yt-dlp/yt-dlp>' \
  254. '**PS**: Some links in this document will not work since this is a copy of the README.md from Github' > ./README.md.new
  255. cat ./README.md >> ./README.md.new && mv -f ./README.md.new ./README.md
  256. python devscripts/set-variant.py pip -M "You installed yt-dlp with pip or using the wheel from PyPi; Use that to update"
  257. make clean-cache
  258. python -m build --no-isolation .
  259. - name: Upload artifacts
  260. if: github.event_name != 'workflow_dispatch'
  261. uses: actions/upload-artifact@v4
  262. with:
  263. name: build-pypi
  264. path: |
  265. dist/*
  266. compression-level: 0
  267. - name: Publish to PyPI
  268. if: github.event_name == 'workflow_dispatch'
  269. uses: pypa/gh-action-pypi-publish@release/v1
  270. with:
  271. verbose: true
  272. publish:
  273. needs: [prepare, build]
  274. permissions:
  275. contents: write
  276. runs-on: ubuntu-latest
  277. steps:
  278. - uses: actions/checkout@v4
  279. with:
  280. fetch-depth: 0
  281. - uses: actions/download-artifact@v4
  282. with:
  283. path: artifact
  284. pattern: build-*
  285. merge-multiple: true
  286. - uses: actions/setup-python@v5
  287. with:
  288. python-version: "3.10"
  289. - name: Generate release notes
  290. env:
  291. head_sha: ${{ needs.prepare.outputs.head_sha }}
  292. target_repo: ${{ needs.prepare.outputs.target_repo }}
  293. target_tag: ${{ needs.prepare.outputs.target_tag }}
  294. run: |
  295. printf '%s' \
  296. '[![Installation](https://img.shields.io/badge/-Which%20file%20to%20download%3F-white.svg?style=for-the-badge)]' \
  297. '(https://github.com/${{ github.repository }}#installation "Installation instructions") ' \
  298. '[![Discord](https://img.shields.io/discord/807245652072857610?color=blue&labelColor=555555&label=&logo=discord&style=for-the-badge)]' \
  299. '(https://discord.gg/H5MNcFW63r "Discord") ' \
  300. '[![Donate](https://img.shields.io/badge/_-Donate-red.svg?logo=githubsponsors&labelColor=555555&style=for-the-badge)]' \
  301. '(https://github.com/yt-dlp/yt-dlp/blob/master/Collaborators.md#collaborators "Donate") ' \
  302. '[![Documentation](https://img.shields.io/badge/-Docs-brightgreen.svg?style=for-the-badge&logo=GitBook&labelColor=555555)]' \
  303. '(https://github.com/${{ github.repository }}' \
  304. '${{ env.target_repo == github.repository && format('/tree/{0}', env.target_tag) || '' }}#readme "Documentation") ' \
  305. ${{ env.target_repo == 'yt-dlp/yt-dlp' && '\
  306. "[![Nightly](https://img.shields.io/badge/Nightly%20builds-purple.svg?style=for-the-badge)]" \
  307. "(https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/latest \"Nightly builds\") " \
  308. "[![Master](https://img.shields.io/badge/Master%20builds-lightblue.svg?style=for-the-badge)]" \
  309. "(https://github.com/yt-dlp/yt-dlp-master-builds/releases/latest \"Master builds\")"' || '' }} > ./RELEASE_NOTES
  310. printf '\n\n' >> ./RELEASE_NOTES
  311. cat >> ./RELEASE_NOTES << EOF
  312. #### A description of the various files is in the [README](https://github.com/${{ github.repository }}#release-files)
  313. ---
  314. $(python ./devscripts/make_changelog.py -vv --collapsible)
  315. EOF
  316. printf '%s\n\n' '**This is a pre-release build**' >> ./PRERELEASE_NOTES
  317. cat ./RELEASE_NOTES >> ./PRERELEASE_NOTES
  318. printf '%s\n\n' 'Generated from: https://github.com/${{ github.repository }}/commit/${{ env.head_sha }}' >> ./ARCHIVE_NOTES
  319. cat ./RELEASE_NOTES >> ./ARCHIVE_NOTES
  320. - name: Publish to archive repo
  321. env:
  322. GH_TOKEN: ${{ secrets[needs.prepare.outputs.target_repo_token] }}
  323. GH_REPO: ${{ needs.prepare.outputs.target_repo }}
  324. version: ${{ needs.prepare.outputs.version }}
  325. channel: ${{ needs.prepare.outputs.channel }}
  326. if: |
  327. inputs.prerelease && env.GH_TOKEN != '' && env.GH_REPO != '' && env.GH_REPO != github.repository
  328. run: |
  329. title="${{ startswith(env.GH_REPO, 'yt-dlp/') && 'yt-dlp ' || '' }}${{ env.channel }}"
  330. gh release create \
  331. --notes-file ARCHIVE_NOTES \
  332. --title "${title} ${{ env.version }}" \
  333. ${{ env.version }} \
  334. artifact/*
  335. - name: Prune old release
  336. env:
  337. GH_TOKEN: ${{ github.token }}
  338. version: ${{ needs.prepare.outputs.version }}
  339. target_repo: ${{ needs.prepare.outputs.target_repo }}
  340. target_tag: ${{ needs.prepare.outputs.target_tag }}
  341. if: |
  342. env.target_repo == github.repository && env.target_tag != env.version
  343. run: |
  344. gh release delete --yes --cleanup-tag "${{ env.target_tag }}" || true
  345. git tag --delete "${{ env.target_tag }}" || true
  346. sleep 5 # Enough time to cover deletion race condition
  347. - name: Publish release
  348. env:
  349. GH_TOKEN: ${{ github.token }}
  350. version: ${{ needs.prepare.outputs.version }}
  351. target_repo: ${{ needs.prepare.outputs.target_repo }}
  352. target_tag: ${{ needs.prepare.outputs.target_tag }}
  353. head_sha: ${{ needs.prepare.outputs.head_sha }}
  354. if: |
  355. env.target_repo == github.repository
  356. run: |
  357. title="${{ github.repository == 'yt-dlp/yt-dlp' && 'yt-dlp ' || '' }}"
  358. title+="${{ env.target_tag != env.version && format('{0} ', env.target_tag) || '' }}"
  359. gh release create \
  360. --notes-file ${{ inputs.prerelease && 'PRERELEASE_NOTES' || 'RELEASE_NOTES' }} \
  361. --target ${{ env.head_sha }} \
  362. --title "${title}${{ env.version }}" \
  363. ${{ inputs.prerelease && '--prerelease' || '' }} \
  364. ${{ env.target_tag }} \
  365. artifact/*