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