+pip install --user lftools[nexus] jsonschema niet yq
+
+#Functions.
+verify_schema(){
+ echo "---> INFO: Verifying $release_file schema."
+ lftools schema verify "$release_file" "$RELEASE_SCHEMA"
+ # Verify allowed versions
+ # Allowed versions are "v#.#.#" or "#.#.#" aka SemVer
+ allowed_version_regex="^((v?)([0-9]+)\.([0-9]+)\.([0-9]+))$"
+ if [[ ! $VERSION =~ $allowed_version_regex ]]; then
+ echo "The version $VERSION is not a semantic valid version"
+ echo "Allowed versions are \"v#.#.#\" or \"#.#.#\" aka SemVer"
+ echo "See https://semver.org/ for more details on SemVer"
+ exit 1
+ fi
+}
+
+tag(){
+ if git tag -v "$VERSION"; then
+ echo "---> OK: Repo already tagged $VERSION Continuting to release"
+ else
+
+ echo "---> INFO: Repo has not yet been tagged $VERSION"
+ git tag -am "${PROJECT//\//-} $VERSION" "$VERSION"
+ sigul --batch -c "$SIGUL_CONFIG" sign-git-tag "$SIGUL_KEY" "$VERSION" < "$SIGUL_PASSWORD"
+ echo "Showing latest signature for $PROJECT:"
+ gpg --import "$SIGNING_PUBKEY"
+ echo "git tag -v $VERSION"
+ git tag -v "$VERSION"
+ ########## Merge Part ##############
+ if [[ "$JOB_NAME" =~ "merge" ]]; then
+ echo "--> INFO: Running merge"
+ gerrit_ssh=$(echo "$GERRIT_URL" | awk -F"/" '{print $3}')
+ git remote set-url origin ssh://"$RELEASE_USERNAME"@"$gerrit_ssh":29418/"$PROJECT"
+ git config user.name "$RELEASE_USERNAME"
+ git config user.email "$RELEASE_EMAIL"
+ echo -e "Host $gerrit_ssh\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
+ chmod 600 ~/.ssh/config
+ git push origin "$VERSION"
+ fi
+ fi
+}
+
+nexus_release(){
+ for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
+ # extract the domain name from URL
+ NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
+ echo "---> INFO: NEXUS_URL: $NEXUS_URL"
+ # extract the staging repo from URL
+ STAGING_REPO=${staging_url#*repositories/}
+ echo "Running Nexus Verify"
+ lftools nexus release -v --server https://"$NEXUS_URL" "$STAGING_REPO"
+ echo "Merge will run"
+ echo "lftools nexus release --server https://$NEXUS_URL $STAGING_REPO"
+ done
+ #Run the loop twice, to catch errors on either nexus repo
+
+ if [[ "$JOB_NAME" =~ "merge" ]]; then
+ for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
+ NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
+ STAGING_REPO=${staging_url#*repositories/}
+ echo "Promoting $STAGING_REPO on $NEXUS_URL."
+ lftools nexus release --server https://"$NEXUS_URL" "$STAGING_REPO"
+ done
+ fi
+}
+