#!/usr/bin/env bash set -eux # This script gets IMGAGE_NAME and TAG as ENV vars, and also gets GITHUB_TOKEN and github_username as secret ENV vars. INFRA_GITHUB_REPOSITORY=${INFRA_GITHUB_REPOSITORY:-"ncrvoyix-swt-retail/edge-infra"} INFRA_BRANCH="${INFRA_BRANCH:-master}" dir=$(basename "$INFRA_GITHUB_REPOSITORY") RELEASE_GITHUB_EMAIL="${RELEASE_GITHUB_EMAIL:-ea230385@corp.ncr.com}" RELEASE_GITHUB_USER=$(echo "$RELEASE_GITHUB_EMAIL" | cut -d'@' -f1) echo "cloning $INFRA_GITHUB_REPOSITORY" dir=$(basename "$INFRA_GITHUB_REPOSITORY") rm -rf "../$dir" git clone -b "$INFRA_BRANCH" "https://$RELEASE_GITHUB_USER:$RELEASE_GITHUB_TOKEN@github.com/$INFRA_GITHUB_REPOSITORY.git" "../$dir" cd "../$dir" || exit edgeadmin cfg update-manifests \ --component "$IMAGE_NAME" \ --image "$IMAGE_NAME=$TAG" \ --manifests "$INFRA_MANIFESTS_DIR" if [ "$DRY_RUN" == 'true' ]; then git diff exit 0 fi echo "configuring git committer information" git config --global user.email "$RELEASE_GITHUB_EMAIL" git config --global user.name "$RELEASE_GITHUB_USER" echo "committing updated manifests" commit_sha=$(git rev-parse HEAD) url=$(git config --get remote.origin.url | awk -F '@' '{print $2}') url=${url%.*} commit_message="[generated] updating images for $IMAGE_NAME commit: https://$url/commits/$commit_sha" git commit -am "$commit_message" echo "$commit_message" while [ -n "$(git fetch)" ]; do echo "Working tree is not clean. Pulling latest changes from $INFRA_BRANCH before push." git pull done git push