mirror of
https://github.com/factoriotools/factorio-docker.git
synced 2024-11-07 03:07:24 +01:00
Fix ci script for manual runs
This commit is contained in:
parent
a5d6466f0b
commit
39fd391e9b
44
build.sh
44
build.sh
@ -4,7 +4,7 @@ set -eoux pipefail
|
||||
if [[ -z ${1:-} ]] && [[ -n ${CI:-} ]]; then
|
||||
echo 'Usage: ./build.sh VERSION_SHORT'
|
||||
exit 1
|
||||
elif [[ $CI == true ]]; then
|
||||
elif [[ ${CI:-} == true ]] || [[ -n ${1:-} ]]; then
|
||||
VERSION_SHORT="$1"
|
||||
else
|
||||
VERSION_SHORT=$(find . -maxdepth 1 -type d | sort | tail -1 | grep -o "[[0-9]].[[0-9]]*")
|
||||
@ -16,20 +16,22 @@ cd "$VERSION_SHORT" || exit 1
|
||||
VERSION=$(grep -oP '[0-9]+\.[0-9]+\.[0-9]+' Dockerfile | head -1)
|
||||
DOCKER_REPO=factoriotools/factorio
|
||||
|
||||
if [[ $TRAVIS_PULL_REQUEST == true ]]; then
|
||||
if [[ ${TRAVIS_PULL_REQUEST:-} == true ]]; then
|
||||
TAGS="$DOCKER_REPO:$TRAVIS_PULL_REQUEST_SLUG"
|
||||
else
|
||||
# we are either on master or on a tag build
|
||||
if [[ $TRAVIS_BRANCH == master ]] || [[ $TRAVIS_BRANCH == "$VERSION" ]]; then
|
||||
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
||||
# we are on an incremental build of a tag
|
||||
elif [[ $VERSION == "${TRAVIS_BRANCH%-*}" ]]; then
|
||||
TAGS="$DOCKER_REPO:$TRAVIS_BRANCH -t $DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
||||
# we build a other branch than master
|
||||
elif [[ -n $TRAVIS_BRANCH ]]; then
|
||||
TAGS="$DOCKER_REPO:$TRAVIS_BRANCH"
|
||||
# we are not in CI and tag version and version short
|
||||
elif [[ $CI == "" ]]; then
|
||||
if [[ -n ${CI:-} ]]; then
|
||||
# we are either on master or on a tag build
|
||||
if [[ $TRAVIS_BRANCH == master ]] || [[ $TRAVIS_BRANCH == "$VERSION" ]]; then
|
||||
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
||||
# we are on an incremental build of a tag
|
||||
elif [[ $VERSION == "${TRAVIS_BRANCH%-*}" ]]; then
|
||||
TAGS="$DOCKER_REPO:$TRAVIS_BRANCH -t $DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
||||
# we build a other branch than master
|
||||
elif [[ -n $TRAVIS_BRANCH ]]; then
|
||||
TAGS="$DOCKER_REPO:$TRAVIS_BRANCH"
|
||||
fi
|
||||
else
|
||||
# we are not in CI and tag version and version short
|
||||
TAGS="$DOCKER_REPO:$VERSION -t $DOCKER_REPO:$VERSION_SHORT"
|
||||
fi
|
||||
|
||||
@ -45,29 +47,33 @@ fi
|
||||
docker build . -t ${TAGS[@]}
|
||||
docker images
|
||||
|
||||
if [[ ${TRAVIS_BRANCH:-} ]]; then
|
||||
TRAVIS_BRANCH_VERSION=${TRAVIS_BRANCH%-*}
|
||||
fi
|
||||
|
||||
# only push when:
|
||||
# latest changes where made in the folder corosponding to the version we build, we are on master and don#t build a PR.
|
||||
if [[ $(dirname "$(git diff --name-only HEAD^)") =~ $VERSION_SHORT ]] && [[ $TRAVIS_BRANCH == master ]] && [[ $TRAVIS_PULL_REQUEST_BRANCH == "" ]] ||
|
||||
# we build a tag and we are not on master
|
||||
[[ $VERSION == "${TRAVIS_BRANCH%-*}" ]] && [[ $TRAVIS_PULL_REQUEST_BRANCH == "" ]] ||
|
||||
[[ $VERSION == "${TRAVIS_BRANCH_VERSION:-}" ]] && [[ $TRAVIS_PULL_REQUEST_BRANCH == "" ]] ||
|
||||
# we are not in CI
|
||||
[[ $CI == "" ]]; then
|
||||
[[ -z ${CI:-} ]]; then
|
||||
|
||||
if [[ $CI == true ]]; then
|
||||
if [[ ${CI:-} == true ]]; then
|
||||
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||
fi
|
||||
|
||||
# push a tag on a branch other than master
|
||||
if [[ -n $TRAVIS_BRANCH ]] && [[ $VERSION != "${TRAVIS_BRANCH%-*}" ]] && [[ $TRAVIS_BRANCH != "master" ]]; then
|
||||
if [[ -n ${TRAVIS_BRANCH:-} ]] && [[ $VERSION != "${TRAVIS_BRANCH_VERSION:-}" ]] && [[ ${TRAVIS_BRANCH:-} != "master" ]]; then
|
||||
docker push "$DOCKER_REPO:$TRAVIS_BRANCH"
|
||||
fi
|
||||
|
||||
# push an incremental tag
|
||||
if [[ $VERSION == "${TRAVIS_BRANCH%-*}" ]]; then
|
||||
if [[ $VERSION == "${TRAVIS_BRANCH_VERSION:-}" ]]; then
|
||||
docker push "$DOCKER_REPO:$TRAVIS_BRANCH"
|
||||
fi
|
||||
|
||||
if [[ -n $TRAVIS_TAG ]] || [[ $CI == "" ]]; then
|
||||
if [[ -n ${TRAVIS_TAG:-} ]] || [[ -z ${CI:-} ]]; then
|
||||
docker push "$DOCKER_REPO:$VERSION"
|
||||
docker push "$DOCKER_REPO:$VERSION_SHORT"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user