forked from carlossg/docker-maven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-action.sh
executable file
·76 lines (65 loc) · 1.99 KB
/
github-action.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -eu
dir="${1:-}"
docker_username="${2:-}"
docker_password="${3:-}"
cd "$(dirname "${BASH_SOURCE[0]}")"
. common.sh
if [ -n "${DOCKER_REPOSITORY:-}" ]; then
DOCKER_REPOSITORIES=("${DOCKER_REPOSITORY}")
else
DOCKER_REPOSITORIES=(csanchez/maven ghcr.io/carlossg/maven)
fi
DOCKER_PUSH=${DOCKER_PUSH:-}
# only push from master
ref="${GITHUB_REF:-}"
branch="${ref##*/}"
echo "Running on branch ${branch} (${ref})"
if [ "${branch}" != "master" ]; then
DOCKER_PUSH=""
fi
build-version() {
local version=$1
local versionAliases=("${@:2}")
pushd "$version"
echo "Building docker image: maven:$version"
docker build -t "maven:$version" .
if [ -n "$DOCKER_PUSH" ]; then
for repository in "${DOCKER_REPOSITORIES[@]}"; do
echo "Pushing $repository:$version"
docker tag "maven:$version" "$repository:$version"
docker push "$repository:$version"
done
fi
for versionAlias in "${versionAliases[@]}"; do
for repository in "${DOCKER_REPOSITORIES[@]}"; do
echo "Tagging $repository:$versionAlias"
docker tag "maven:$version" "$repository:$versionAlias"
if [ -n "$DOCKER_PUSH" ]; then
echo "Pushing $repository:$versionAlias"
docker push "$repository:$versionAlias"
fi
done
done
popd
}
if [ -n "$DOCKER_PUSH" ]; then
echo "Docker login"
echo "${docker_password:?}" | docker login -u "${docker_username:?}" --password-stdin
if [ -n "${CR_PAT:-}" ]; then
echo "GitHub Container Registry login"
echo "${CR_PAT}" | docker login ghcr.io -u carlossg --password-stdin
fi
fi
if [ -z "${dir}" ]; then
versions=( "${all_dirs[@]}" )
else
versions=( "${dir}" )
fi
for version in "${versions[@]}"; do
echo "Building $version"
mapfile -t versionAliases < <(version-aliases "$version" master)
build-version "$version" "${versionAliases[@]}"
echo "Testing $version"
TAG=$version bats tests
done