forked from carlossg/docker-maven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-action.ps1
52 lines (45 loc) · 1.34 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
Install-Module -Name Pester -Force -RequiredVersion 5.0.4
Write-Host "Starting"
$dir = $args[0]
$username = $args[1]
$password = $args[2]
$tags = @('3.9.3', '3.9', '3')
# only push from main
$ref=$env:GITHUB_REF
$branch=$ref.substring($ref.LastIndexOf("/") +1)
echo "Running on branch ${branch} (${ref})"
if($branch -ne 'main') {
$env:DOCKER_PUSH=""
}
Push-Location
Write-Host "Image: $dir"
# TODO manually copied from Dockerfiles
if(($dir.Contains('amazoncorretto')) -or ($dir.Contains('azulzulu'))) {
$windowsDockerTag = 'ltsc2019'
}
if(($dir.Contains('eclipse-temurin')) -or ($dir.Contains('openjdk'))) {
$windowsDockerTag = '1809'
}
# run tests
Write-Host "Running tests: $dir"
Push-Location
$env:TAG=$dir
Invoke-Pester -Path tests -CI
Remove-Item env:\TAG
Pop-Location
$tags | ForEach-Object {
Push-Location $dir
$tag = ('csanchez/maven:{0}-{1}-{2}' -f $_,$dir,$windowsDockerTag)
Write-Host "Building: $tag"
docker build --tag $tag .
if($env:DOCKER_PUSH -eq 'true') {
# 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