diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index c78f9fd24ec..de84d0f5f1b 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -194,3 +194,31 @@ jobs: steps: - name: Success run: echo Windows Test Successful + + docker: + runs-on: windows-2019 + timeout-minutes: 45 + + name: Docker Python 3.7 x86 + + steps: + - uses: actions/checkout@v1 + + - uses: actions/checkout@v1 + with: + repository: python-pillow/pillow-depends + ref: master + + - name: Build system information + run: python .github/workflows/system-info.py + + - name: Build Docker Image + run: | + # & $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchWindowsEngine + echo "This step takes about 20 minutes, please be patient..." + docker build -m 2G -t python-pillow-build:latest winbuild\docker + shell: pwsh + + - name: Run Docker + run: docker run --name PillowBuild -v ${env:GITHUB_WORKSPACE}:C:\Pillow -v ${env:RUNNER_WORKSPACE}\pillow-depends:C:\pillow-depends python-pillow-build C:\Pillow\winbuild\docker\build.cmd + shell: pwsh diff --git a/Tests/helper.py b/Tests/helper.py index feccce6bcf9..814c6048b5a 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -316,6 +316,19 @@ def is_win32(): return sys.platform.startswith("win32") +def is_win32_docker(): + try: + import winreg + + key = winreg.OpenKey( + winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control" + ) + winreg.QueryValueEx(key, "ContainerType") # fails if not in Docker container + return True + except (ImportError, OSError): + return False + + def is_pypy(): return hasattr(sys, "pypy_translation_info") diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index fa2291582d4..120310134de 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -6,13 +6,14 @@ from PIL import Image, ImageGrab -from .helper import assert_image_equal_tofile, skip_unless_feature +from .helper import assert_image_equal_tofile, is_win32_docker, skip_unless_feature class TestImageGrab: @pytest.mark.skipif( sys.platform not in ("win32", "darwin"), reason="requires Windows or macOS" ) + @pytest.mark.skipif(is_win32_docker(), reason="running on headless Windows") def test_grab(self): ImageGrab.grab() ImageGrab.grab(include_layered_windows=True) diff --git a/winbuild/docker/Dockerfile b/winbuild/docker/Dockerfile new file mode 100644 index 00000000000..a61dd54a64d --- /dev/null +++ b/winbuild/docker/Dockerfile @@ -0,0 +1,40 @@ +# escape=` + +# Use the latest Windows Server Core image with .NET Framework 4.8. +FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019 + +# Restore the default Windows shell for correct batch processing. +SHELL ["cmd", "/S", "/C"] + +RUN powershell.exe -Command ` + $ErrorActionPreference = 'Stop'; ` + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ` + wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/win64/nasm-2.14.02-win64.zip -OutFile c:\nasm.zip ; ` + Expand-Archive c:\nasm.zip -DestinationPath c:\ + +ARG PYTHON=3.7.3 +ARG PYTHON_DIR=Python37 +RUN powershell.exe -Command ` + $ErrorActionPreference = 'Stop'; ` + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ` + wget https://www.python.org/ftp/python/%PYTHON%/python-%PYTHON%.exe -OutFile c:\python-%PYTHON%.exe ; ` + Start-Process c:\python-%PYTHON%.exe -ArgumentList '/quiet TargetDir=c:\%PYTHON_DIR%\ InstallAllUsers=1 PrependPath=1' -Wait ; ` + Remove-Item c:\python-%PYTHON%.exe -Force ; ` + setx /M PYTHON C:\%PYTHON_DIR% + +RUN C:\%PYTHON_DIR%\Scripts\pip.exe install pytest pytest-cov + +# Default to PowerShell if no other command specified. +CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] + +# Download the Build Tools bootstrapper. +ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\vs_buildtools.exe + +# Install Build Tools excluding workloads and components with known issues. +RUN C:\vs_buildtools.exe --quiet --wait --norestart --nocache ` + --installPath C:\BuildTools ` + --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended ` + || IF "%ERRORLEVEL%"=="3010" EXIT 0 + +# Default to PowerShell if no other command specified. +CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] diff --git a/winbuild/docker/build.cmd b/winbuild/docker/build.cmd new file mode 100644 index 00000000000..a7e0b57468a --- /dev/null +++ b/winbuild/docker/build.cmd @@ -0,0 +1,18 @@ + +set CI=true +path C:\nasm-2.14.02\;%PATH% +xcopy /s c:\pillow-depends\test_images\* c:\pillow\tests\images + +cd c:\pillow\winbuild\ +c:\python37\python.exe build_prepare.py -v --depends=C:\pillow-depends +if errorlevel 1 echo Build prepare failed! && exit /B 1 +call build\build_dep_all.cmd +if errorlevel 1 echo Build dependencies failed! && exit /B 1 +call build\build_pillow.cmd install +if errorlevel 1 echo Build failed! && exit /B 1 + +cd c:\pillow +path c:\pillow\winbuild\build\bin;%PATH% +c:\python37\python.exe selftest.py --installed +if errorlevel 1 echo Selftest failed! && exit /B 1 +c:\python37\python.exe -m pytest -vx -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests