setup ci in github actions

Signed-off-by: Ashish Amarnath <ashisham@vmware.com>
This commit is contained in:
Ashish Amarnath
2020-05-27 16:34:12 -07:00
parent 5b52fd3efd
commit 941b804a06
3 changed files with 53 additions and 13 deletions

View File

@@ -20,8 +20,8 @@
set +x
if [[ -z "$TRAVIS" ]]; then
echo "This script is intended to be run only on Travis." >&2
if [[ -z "$CI" ]]; then
echo "This script is intended to be run only on Github Actions." >&2
exit 1
fi
@@ -47,37 +47,43 @@ function highest_release() {
done
}
triggeredBy=$(echo $GITHUB_REF | cut -d / -f 2)
if [[ "$triggeredBy" == "heads" ]]; then
BRANCH=$(echo $GITHUB_REF | cut -d / -f 3)
TAG=
elif [[ "$triggeredBy" == "tags" ]]; then
BRANCH=
TAG=$(echo $GITHUB_REF | cut -d / -f 3)
fi
if [[ "$BRANCH" == "master" ]]; then
VERSION="$BRANCH"
elif [[ ! -z "$TRAVIS_TAG" ]]; then
# Tags aren't fetched by Travis on checkout, and we don't need them for master
elif [[ ! -z "$TAG" ]]; then
# Explicitly checkout tags when building from a git tag.
# This is not needed when building from master
git fetch --tags
# Calculate the latest release if there's a tag.
highest_release
VERSION="$TRAVIS_TAG"
VERSION="$TAG"
else
# If we're not on master and we're not building a tag, exit early.
echo "We're not on master and we're not building a tag, exit early."
exit 0
fi
# Assume we're not tagging `latest` by default, and never on master.
TAG_LATEST=false
if [[ "$BRANCH" == "master" ]]; then
echo "Building master, not tagging latest."
elif [[ "$TRAVIS_TAG" == "$HIGHEST" ]]; then
elif [[ "$TAG" == "$HIGHEST" ]]; then
TAG_LATEST=true
fi
# Debugging info
echo "Highest tag found: $HIGHEST"
echo "BRANCH: $BRANCH"
echo "TRAVIS_TAG: $TRAVIS_TAG"
echo "TAG: $TAG"
echo "TAG_LATEST: $TAG_LATEST"
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
unset GIT_HTTP_USER_AGENT
echo "Building and pushing container images."
VERSION="$VERSION" TAG_LATEST="$TAG_LATEST" make all-containers all-push all-manifests