Merge "Do not clone submodules in rtdv3"
authorJessica Wagantall <jwagantall@linuxfoundation.org>
Wed, 5 Feb 2020 21:30:24 +0000 (21:30 +0000)
committerGerrit Code Review <gerrit@linuxfoundation.org>
Wed, 5 Feb 2020 21:30:24 +0000 (21:30 +0000)
releasenotes/notes/cleanup-gerrit-push-change-f77402b88764c6ff.yaml [new file with mode: 0644]
shell/gerrit-push-patch.sh
shell/git-validate-jira-urls.sh [deleted file]
shell/jjb-check-unicode.sh [deleted file]
shell/jjb-cleanup.sh [deleted file]
shell/jjb-install.sh [deleted file]
shell/job-cost.sh
shell/pip-install.sh [deleted file]

diff --git a/releasenotes/notes/cleanup-gerrit-push-change-f77402b88764c6ff.yaml b/releasenotes/notes/cleanup-gerrit-push-change-f77402b88764c6ff.yaml
new file mode 100644 (file)
index 0000000..c2ad64b
--- /dev/null
@@ -0,0 +1,7 @@
+---
+fixes:
+  - |
+    Removed broken code that removed leading/trailing white-space from
+    variables. Use lf-activate-venv() to install openstack. Enabled 'set -euf
+    pipefail' and updated code to handle errors. Updated out of date
+    comments. Some minor cleanup of code for clarity.
index 8bddfa9..b33f0f5 100644 (file)
 echo "---> gerrit-push-patch.sh"
 # Push a change to Gerrit if files modified in repository.
 #
-# The script requires to install the minimum version 1.25 of git-review using
-# virtualenv and pip install which supports `--reviewers` option.
+# Need to use git-review >= 1.28 to be compatible with Gerrit 3
 #
 # The script allows a job to push a patch to Gerrit in an automated fashion.
 # This is meant for tasks that creates the same patch regularly and needs the
 # ability to detect if an unreviewed patch already exists. In which case it
 # will update the existing patch.
 #
-# Note: This patch assumes the $WORKSPACE contains the project repo with
-#       the files changed already "git add" and waiting for a "git commit" call.
+# Note: This script expects $WORKSPACE to point to a project git repo that
+# may contain staged commits. This script will exit with OK status if no
+# staged commits are present, otherwise the staged commits will be commited and
+# a gerrit review will be created.
 #
-# This script requires the following JJB variables to be passed in:
+# This script expects the following environment variables to be set in the
+# JJB configuration
 #
 #   $PROJECT              : Gerrit project-name
 #   $GERRIT_COMMIT_MESSAGE: Commit message to assign to commit
@@ -31,52 +33,44 @@ echo "---> gerrit-push-patch.sh"
 #   $GERRIT_USER          : Gerrit user
 #   $REVIEWERS_EMAIL      : Reviewers email
 
-# TODO: remove the workaround when v1.26 is available on all images
-# Workaround for git-review bug in v1.24
-# https://storyboard.openstack.org/#!/story/2001081
-set +u  # Allow unbound variables for virtualenv
-virtualenv --quiet "/tmp/v/git-review"
-# shellcheck source=/tmp/v/git-review/bin/activate disable=SC1091
-source "/tmp/v/git-review/bin/activate"
-pip install --quiet --upgrade "pip==9.0.3" setuptools
-pip install --quiet --upgrade git-review
-set -u
-# End git-review workaround
-# Remove any leading or trailing quotes surrounding the strings
-# which can cause parse errors when passed as CLI options to commands
-# shellcheck disable=SC2001
-PROJECT="$(echo "$PROJECT" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
-# shellcheck disable=SC2001
-GERRIT_COMMIT_MESSAGE="$(echo "$GERRIT_COMMIT_MESSAGE" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
-# shellcheck disable=SC2001
-GERRIT_HOST="$(echo "$GERRIT_HOST" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
-# shellcheck disable=SC2001
-GERRIT_TOPIC="$(echo "$GERRIT_TOPIC" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
-# shellcheck disable=SC2001
-GERRIT_USER="$(echo "$GERRIT_USER" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
-# shellcheck disable=SC2001
-REVIEWERS_EMAIL="$(echo "$REVIEWERS_EMAIL" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
-job=$JOB_NAME/$BUILD_NUMBER
+set -eufo pipefail
+
+# No reason to continue if there are no staged commits
+staged_commits=$(git diff --cached --name-only)
+if [[ -z $staged_commits ]]; then
+    echo "INFO: Nothing to commit"
+    exit 0
+fi
+
+echo -e "INFO: Staged for commit:\n$staged_commits\n"
 
-CHANGE_ID=$(ssh -p 29418 "$GERRIT_USER@$GERRIT_HOST" gerrit query \
-               limit:1 owner:self is:open project:"$PROJECT" \
-               message: "$GERRIT_COMMIT_MESSAGE" \
-               topic: "$GERRIT_TOPIC" | \
-               grep 'Change-Id:' | \
-               awk '{ print $2 }')
+# shellcheck disable=SC1090
+source ~/lf-env.sh
 
-if [ -z "$CHANGE_ID" ]; then
-   git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Job: ${job}"
+lf-activate-venv "git-review>=1.28"
+
+# Query for a pre-existing gerrit review
+query_result=$(ssh -p 29418 "$GERRIT_USER@$GERRIT_HOST" gerrit query \
+               limit:1 owner:self is:open project:"$PROJECT"         \
+               message: "$GERRIT_COMMIT_MESSAGE"                     \
+               topic: "$GERRIT_TOPIC")
+
+# Extract the change_id from the query_result
+job=$JOB_NAME/$BUILD_NUMBER
+# If available, add change_id to commit message
+if change_id=$(echo "$query_result" | grep 'Change-Id:' | awk '{print $2}'); then
+    echo "NOTE: Found gerrit review: $change_id"
+    message="Job: $job\nChange-Id: $change_id"
 else
-   git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Job: ${job}\nChange-Id: $CHANGE_ID"
+    echo "NOTE: No gerrit review found"
+    message="Job: $job"
 fi
+git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "$message"
 
 git status
 git remote add gerrit "ssh://$GERRIT_USER@$GERRIT_HOST:29418/$PROJECT.git"
 
-# if the reviewers email is empty then use a default
-REVIEWERS_EMAIL=${REVIEWERS_EMAIL:-"$GERRIT_USER@$GERRIT_HOST"}
+# If the reviewers email is unset/empty then use a default
+reviewers_email=${REVIEWERS_EMAIL:-"$GERRIT_USER@$GERRIT_HOST"}
 
-# Don't fail the build if this command fails because it's possible that there
-# is no changes since last update.
-git review --yes -t "$GERRIT_TOPIC" --reviewers "$REVIEWERS_EMAIL" || true
+git review --yes -t "$GERRIT_TOPIC" --reviewers "$reviewers_email"
diff --git a/shell/git-validate-jira-urls.sh b/shell/git-validate-jira-urls.sh
deleted file mode 100644 (file)
index 4a10772..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: EPL-1.0
-##############################################################################
-# Copyright (c) 2017 The Linux Foundation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-##############################################################################
-echo "---> git-validate-jira-urls.sh"
-# This script will make sure that there are no JIRA URLs in the commit
-# message. JIRA URLs will break the its-jira plugin
-
-# Ensure we fail the job if any steps fail.
-# Do not treat undefined variables as errors as in this case we are allowed
-# to have JIRA_URL undefined
-set -e -o pipefail
-set +u
-
-if [ -n "${JIRA_URL}" ];
-then
-  BASE_URL=$(echo "$JIRA_URL" | awk -F'/' '{print $3}')
-  JIRA_LINK=$(git rev-list --format=%B --max-count=1 HEAD | grep -io "http[s]*://$BASE_URL/" || true)
-  if [[ -n "$JIRA_LINK" ]]
-  then
-    echo 'Remove JIRA URLs from commit message'
-    echo 'Add jira references as: Issue: <JIRAKEY>-<ISSUE#>, instead of URLs'
-    exit 1
-  fi
-fi
diff --git a/shell/jjb-check-unicode.sh b/shell/jjb-check-unicode.sh
deleted file mode 100644 (file)
index 284d6db..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: EPL-1.0
-##############################################################################
-# Copyright (c) 2015 The Linux Foundation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-##############################################################################
-echo "---> jjb-check-unicode.sh"
-
-if LC_ALL=C grep -I -r '[^[:print:][:space:]]' jjb/; then
-    echo "Found files containing non-ascii characters."
-    exit 1
-fi
-
-echo "All files are ASCII only"
diff --git a/shell/jjb-cleanup.sh b/shell/jjb-cleanup.sh
deleted file mode 100644 (file)
index ffdfe1f..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: EPL-1.0
-##############################################################################
-# Copyright (c) 2017 The Linux Foundation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-##############################################################################
-echo "---> jjb-cleanup.sh"
-# Cleans up the temporary directory created for the virtualenv but only if it
-# exists under /tmp. This is to ensure we never attempt to blow away '/'
-# through mis-set bash variables.
-
-# Ensure we fail the job if any steps fail.
-# DO NOT set -u as virtualenv's activate script has unbound variables
-set -e +u -o pipefail
-
-# shellcheck source="$WORKSPACE/.jjb.properties" disable=SC1091
-source "$WORKSPACE/.jjb.properties"
-if [[ -n "$JJB_VENV" && "$JJB_VENV" =~ /tmp/.* ]]; then
-    rm -rf "$JJB_VENV" && echo "$JJB_VENV removed"
-    unset JJB_VENV
-fi
-rm -f "$WORKSPACE/.jjb.properties"
-deactivate
diff --git a/shell/jjb-install.sh b/shell/jjb-install.sh
deleted file mode 100644 (file)
index d0c0e4a..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash -l
-# SPDX-License-Identifier: EPL-1.0
-##############################################################################
-# Copyright (c) 2017 The Linux Foundation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-##############################################################################
-echo "---> jjb-install.sh"
-
-# Ensure we fail the job if any steps fail.
-# DO NOT set -u as virtualenv's activate script has unbound variables
-set -e -o pipefail
-
-# Create a virtualenv in a temporary directoy and write it down to used
-# or cleaned up later; cleanup is done in the script jjb-cleanup.sh.
-JJB_VENV="$(mktemp -d)"
-export JJB_VENV
-virtualenv "$JJB_VENV"
-echo "JJB_VENV=$JJB_VENV" > "$WORKSPACE/.jjb.properties"
-# shellcheck source=$VENV_DIR/bin/activate disable=SC1091
-source "$JJB_VENV/bin/activate"
-python -m pip install --quiet --upgrade "jenkins-job-builder==$JJB_VERSION"
-
-# installs are silent, show version details in log
-python --version
-pip --version
-pip freeze
index 34ab5e7..769b972 100644 (file)
@@ -59,7 +59,7 @@ url="https://pricing.vexxhost.net/v1/pricing/$instance_type/cost?seconds=$uptime
 json_block=$(curl -s "$url")
 
 # check if JSON returned and can be parsed
-if jq <<< "$json_block"; then
+if jq <<< "$json_block" > /dev/null 2>&1; then
     cost=$(jq .cost <<< "$json_block")
     resource=$(jq .resource <<< "$json_block" | tr -d '"')
 else
diff --git a/shell/pip-install.sh b/shell/pip-install.sh
deleted file mode 100644 (file)
index 9770d66..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: EPL-1.0
-##############################################################################
-# Copyright (c) 2017 The Linux Foundation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-##############################################################################
-# pip install packages into a virtualenv using the first listed package as venv name
-#
-# PIP_PACKAGES is a space separated list of pypi packages to install. The first
-#              listed package is used as the virtualenv directory name.
-echo "---> pip-install.sh"
-
-# Ensure we fail the job if any steps fail.
-# DO NOT set -u as virtualenv's activate script has unbound variables
-set -e -o pipefail
-
-# Install git-review using virtualenv to the latest version that supports
-# --reviewers option, available through pip install. Existing minion image has a
-# version that does not have it.
-virtualenv "/tmp/v/${PIP_PACKAGES%% *}"
-# shellcheck source=/tmp/v/venv/bin/activate disable=SC1091
-source "/tmp/v/${PIP_PACKAGES%% *}/bin/activate"
-pip install --quiet --upgrade "pip==9.0.3" setuptools
-pip install --quiet --upgrade pipdeptree
-
-# PIP_PACKAGES needs to be passed through as a space separated list of packages
-# shellcheck disable=SC2086
-pip install --upgrade $PIP_PACKAGES
-
-echo "----> Pip Dependency Tree"
-pipdeptree