xref: /Lucene/dev-tools/test-patch/test-patch.sh (revision 12372530a8366ab35834b8a93c39775ab87564ed)
1#!/usr/bin/env bash
2# Licensed to the Apache Software Foundation (ASF) under one or more
3# contributor license agreements.  See the NOTICE file distributed with
4# this work for additional information regarding copyright ownership.
5# The ASF licenses this file to You under the Apache License, Version 2.0
6# (the "License"); you may not use this file except in compliance with
7# the License.  You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
18# Invoke Yetus locally to validate a patch against Lucene/Solr, and
19# (optionally) post a validation report comment on the passed-in JIRA issue
20# from which the patch was downloaded.
21#
22# NB 1: The Lucene/Solr Yetus personality currently performs the equivalent
23# of "ant precommit" and "ant test" in modified modules; instead of using
24# this script to test your changes, please consider invoking those targets
25# directly.
26#
27# NB 2: The Jenkins job "PreCommit-Admin" automatically detects new patches
28# posted to LUCENE and SOLR JIRA issues that are in the "Patch Available"
29# state, and then queues the appropriate "PreCommit-LUCENE-Build" or
30# "PreCommit-SOLR-Build" job pointing to the JIRA hosting the new patch.
31# Those jobs perform the same checks as this script, and like this script,
32# will post a comment on the JIRA issue.  As a result, manual invocation
33# (e.g. via this script) should ordinarily not be necessary.
34#
35# Environment variable ${YETUS_HOME} must point to the separately installed
36# Yetus home directory, e.g. the "rel/0.7.0" tag checked out from a local
37# Yetus Git repository.
38#
39# Environment variable ${PROJECT_DIR} must point to a local Lucene/Solr git
40# workspace dir.
41#
42# The sole cmdline param can be a JIRA issue, a local patch file,
43# or a URL to a patch file.
44#
45# If the cmdline param is a JIRA issue, the patch to download and validate
46# will be the most recently uploaded patch on the issue.  See the patch
47# naming schema that Yetus recognizes:
48# https://yetus.apache.org/documentation/in-progress/precommit-patchnames/
49#
50# If the cmdline param is a JIRA issue and you provide JIRA user/password via
51# environment variables ${JIRA_USER} and ${JIRA_PASSWORD}, a patch validation
52# report will be posted as a comment on the JIRA issue.
53
54help () {
55  echo "Usage 1: [ JIRA_USER=xxx JIRA_PASSWORD=yyy ] PROJECT_DIR=/path/to/lucene-solr YETUS_HOME=/path/to/yetus $0 SOLR-12345"
56  echo "Usage 2: [ JIRA_USER=xxx JIRA_PASSWORD=yyy ] PROJECT_DIR=/path/to/lucene-solr YETUS_HOME=/path/to/yetus $0 LUCENE-12345"
57  echo "Usage 3: PROJECT_DIR=/path/to/lucene-solr YETUS_HOME=/path/to/yetus $0 ../local.patch"
58  echo "Usage 4: PROJECT_DIR=/path/to/lucene-solr YETUS_HOME=/path/to/yetus $0 http://example.com/remote.patch"
59}
60
61if [[ -z "${PROJECT_DIR}" || -z "${YETUS_HOME}" || -z "${1}" || "${1}" =~ ^-(-?h(elp)?|\?)$ ]] ; then
62  help
63  exit 1
64fi
65
66PATCH_REF=${1}
67TEST_PATCH_BIN="${YETUS_HOME}/precommit/test-patch.sh"
68SCRIPT_DIR="$( cd "$( dirname "${0}" )" && pwd )"
69declare -a YETUS_ARGS
70
71if [[ ${PATCH_REF} =~ ^(LUCENE|SOLR)- ]]; then
72  JIRA_PROJECT=${BASH_REMATCH[0]}
73  YETUS_ARGS+=("--project=${JIRA_PROJECT}")
74
75  if [[ -n "${JIRA_USER}" ]] && [[ -n "${JIRA_PASSWORD}" ]] ; then
76    YETUS_ARGS+=("--jira-user=${JIRA_USER}")
77    YETUS_ARGS+=("--jira-password=${JIRA_PASSWORD}")
78    YETUS_ARGS+=("--bugcomments=jira")
79  fi
80fi
81
82YETUS_ARGS+=("--basedir=${PROJECT_DIR}")
83YETUS_ARGS+=("--personality=${SCRIPT_DIR}/lucene-solr-yetus-personality.sh")
84YETUS_ARGS+=("--skip-dirs=dev-tools")
85YETUS_ARGS+=("--resetrepo")
86YETUS_ARGS+=("--run-tests")
87YETUS_ARGS+=("--debug")
88YETUS_ARGS+=("--robot")
89YETUS_ARGS+=("${PATCH_REF}")
90
91/bin/bash ${TEST_PATCH_BIN} "${YETUS_ARGS[@]}"
92