forked from carlossg/docker-maven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-action.ps1
53 lines (46 loc) · 1.77 KB
/
github-action.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Install-Module -Name Pester -Force -RequiredVersion 4.9.0
Write-Host "Starting"
$event_name = $args[0]
$username = $args[1]
$password = $args[2]
$tags = @('3.6.3', '3.6', '3')
Get-ChildItem -Path windows\* -File -Include "Dockerfile.windows-*" | ForEach-Object {
Push-Location
$dockerfile = $_
Write-Host "Dockerfile: $dockerfile"
$windowsType = '-windowsservercore'
$windowsDockerTag = 'ltsc2019'
$windowsReleaseId = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseID | Select-Object ReleaseID).ReleaseID
if($dockerfile.Name.Contains('nanoserver')) {
$windowsType = ''
$windowsDockerTag = $windowsReleaseId
}
if($dockerfile.Name.Contains('jdk-')) {
$windowsDockerTag = $windowsReleaseId
}
# run tests
Write-Host "Running tests: $dockerfile"
Push-Location
$env:TAG=$dockerfile.Name.Replace('Dockerfile.windows-', '')
$env:WINDOWS_DOCKER_TAG=$windowsDockerTag
Invoke-Pester -Path tests
Remove-Item env:\TAG
Remove-Item env:\WINDOWS_DOCKER_TAG
Pop-Location
$tags | ForEach-Object {
Push-Location windows
$tag = ('csanchez/maven:{0}-{1}{2}-{3}' -f $_,$dockerfile.Name.Replace('Dockerfile.windows-', ''),$windowsType,$windowsDockerTag)
Write-Host "Building: $tag"
docker build -f $dockerfile --tag $tag --build-arg WINDOWS_DOCKER_TAG=${windowsDockerTag} .
if($event_name -eq 'push') {
# docker login with cause a warning which will cause this to fail unless we SilentlyContinue
$ErrorActionPreference = 'SilentlyContinue'
$password | & docker login --username $username --password-stdin
$ErrorActionPreference = 'Stop'
Write-Host "Pushing $tag"
& docker push $tag
}
Pop-Location
}
Pop-Location
}