From b2ebdc0dc5b87d37c6825af9698a6739f42da15a Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Sat, 31 Oct 2020 19:28:57 +0100 Subject: [PATCH] Move Docker tests to GitHub Actions --- .appveyor.yml | 22 +++------------------- .github/workflows/test.yml | 26 ++++++++++++++++++++++++++ test/Dockerfile.nanoserver.ps1 | 17 ----------------- test/Dockerfile.windowsservercore.ps1 | 18 ------------------ test/Prepare-Dockerfile.ps1 | 11 +++++++++++ 5 files changed, 40 insertions(+), 54 deletions(-) delete mode 100644 test/Dockerfile.nanoserver.ps1 delete mode 100644 test/Dockerfile.windowsservercore.ps1 create mode 100644 test/Prepare-Dockerfile.ps1 diff --git a/.appveyor.yml b/.appveyor.yml index 49f57ea..639f144 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -22,10 +22,6 @@ skip_commits: environment: PsgKey: secure: tlhLuUS6x8FcP159+X/EIBDlj9m+u5KCTTuqwzsiNHlPX6K4AolpaZcfAP4ClOdB - matrix: - - DOCKER_IMAGE: - - DOCKER_IMAGE: nanoserver - - DOCKER_IMAGE: windowsservercore cache: - test\download-cache -> .appveyor.yml @@ -36,23 +32,11 @@ cache: build: off install: - - ps: | - if ($null -eq $Env:DOCKER_IMAGE -or $Env:DOCKER_IMAGE -eq '') { - .\test\setup.ps1 - } else { - & ".\test\Dockerfile.$Env:DOCKER_IMAGE.ps1" - } - + - ps: .\test\setup.ps1 test_script: - ps: | - if ($null -eq $Env:DOCKER_IMAGE -or $Env:DOCKER_IMAGE -eq '') { - $pesterResult = .\test\pester.ps1 - $failCount = $pesterResult.FailedCount - } else { - $volume="$($Env:APPVEYOR_BUILD_FOLDER):C:\App" - docker run --rm --volume $volume --workdir C:\App --env "PM_TEST_DOCKER=1" phpmanager/test powershell.exe 'Set-Location -LiteralPath C:\App; $pesterResult=.\test\pester.ps1; exit $pesterResult.FailedCount' - $failCount = $LASTEXITCODE - } + $pesterResult = .\test\pester.ps1 + $failCount = $pesterResult.FailedCount (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path -LiteralPath .\TestsResults.xml)) if ($failCount -ne 0) { throw "$failCount tests failed!" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55cb7ed..013ac37 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,3 +57,29 @@ jobs: if ($pesterResult.FailedCount -ne 0) { throw "$($pesterResult.FailedCount) tests failed!" } + docker: + strategy: + matrix: + docker-image: + - nanoserver + - windowsservercore + name: Docker (${{ matrix.docker-image }}) + runs-on: windows-latest + steps: + - name: Enabling Windows containers + run: "& 'C:\\Program Files\\Docker\\DockerCli.exe' -SwitchWindowsEngine" + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Prepare files for Docker image + run: .\test\Prepare-Dockerfile.ps1 "${{ matrix.docker-image }}" + - name: Build Docker image + run: docker build --tag phpmanager/test .\test\docker-build + - name: Test + run: | + docker run --rm --volume "$($Env:GITHUB_WORKSPACE):C:\App" --workdir C:\App --env "PM_TEST_DOCKER=1" phpmanager/test powershell.exe 'pesterResult=.\test\pester.ps1; exit $pesterResult.FailedCount' + $failCount = $LASTEXITCODE + if ($failCount -ne 0) { + throw "$failCount tests failed!" + } diff --git a/test/Dockerfile.nanoserver.ps1 b/test/Dockerfile.nanoserver.ps1 deleted file mode 100644 index e08d2a5..0000000 --- a/test/Dockerfile.nanoserver.ps1 +++ /dev/null @@ -1,17 +0,0 @@ -$dockerBuildPath = Join-Path -Path $PSScriptRoot -ChildPath docker-build -if (-Not(Test-Path -LiteralPath $dockerBuildPath)) { - New-Item -ItemType Directory -Path $dockerBuildPath | Out-Null -} -$me = Get-Item -LiteralPath $PSCommandPath -try { - Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcruntime140.dll" -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup-nodejs.ps1) -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup.ps1) -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath $me.BaseName) -Destination (Join-Path -Path $dockerBuildPath -ChildPath Dockerfile) - docker build --rm --force-rm --tag phpmanager/test $dockerBuildPath -} finally { - try { - Remove-Item -LiteralPath $dockerBuildPath -Recurse - } catch { - } -} diff --git a/test/Dockerfile.windowsservercore.ps1 b/test/Dockerfile.windowsservercore.ps1 deleted file mode 100644 index b736214..0000000 --- a/test/Dockerfile.windowsservercore.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -$dockerBuildPath = Join-Path -Path $PSScriptRoot -ChildPath docker-build -if (-Not(Test-Path -LiteralPath $dockerBuildPath)) { - New-Item -ItemType Directory -Path $dockerBuildPath | Out-Null -} -$me = Get-Item -LiteralPath $PSCommandPath -try { - Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcruntime140.dll" -Destination $dockerBuildPath - Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcomp140.dll" -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup-nodejs.ps1) -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup.ps1) -Destination $dockerBuildPath - Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath $me.BaseName) -Destination (Join-Path -Path $dockerBuildPath -ChildPath Dockerfile) - docker build --rm --force-rm --tag phpmanager/test $dockerBuildPath -} finally { - try { - Remove-Item -LiteralPath $dockerBuildPath -Recurse - } catch { - } -} diff --git a/test/Prepare-Dockerfile.ps1 b/test/Prepare-Dockerfile.ps1 new file mode 100644 index 0000000..9ca337c --- /dev/null +++ b/test/Prepare-Dockerfile.ps1 @@ -0,0 +1,11 @@ +param ([string] $DockerImage) + +$dockerBuildPath = Join-Path -Path $PSScriptRoot -ChildPath docker-build +if (-Not(Test-Path -LiteralPath $dockerBuildPath)) { + New-Item -ItemType Directory -Path $dockerBuildPath | Out-Null +} +Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcruntime140.dll" -Destination $dockerBuildPath +Copy-Item -LiteralPath "$($Env:SystemRoot)\System32\vcomp140.dll" -Destination $dockerBuildPath +Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup-nodejs.ps1) -Destination $dockerBuildPath +Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath setup.ps1) -Destination $dockerBuildPath +Copy-Item -LiteralPath (Join-Path -Path $PSScriptRoot -ChildPath "Dockerfile.$DockerImage") -Destination (Join-Path -Path $dockerBuildPath -ChildPath Dockerfile)