Skip to content

Commit

Permalink
fix(build-pr): Fix the build-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
definite committed Apr 15, 2016
1 parent fc85002 commit 34b4a19
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 117 deletions.
226 changes: 109 additions & 117 deletions zanata-build-pr
@@ -1,133 +1,125 @@
#!/bin/bash
PROG_NAME=zanata-build-pr

function print_usage(){
cat <<END
NAME
$PROG_NAME - Build pull request
zanata-client-build-pr - Build zanata-client pull request
SYNOPSIS
$PROG_NAME <repo> -p <GitHubPullRequestNumber>
zanata-client-build-pr -p <GitHubPullRequestNumber>
OPTIONS
repo
Repository to build
E.g. zanata-client
-p GitHubPullRequestNumber
GitHub Pull Request Number
E.g. -p 45
-r Branch name
Branch name
E.g. master
DESCRIPTION
zanata-build-br checkouts the corresponding branch in
given branch, then run:
mvn -e clean install
zanata-client-build-br is esentially
zanata-build-pr zanata-client -p <GitHubPullRequestNumber>
ENVIRONMENT
ZANATA_CHECKOUT_PARENT_DIR
Parent Directory for zanata checkout.
Default: ${HOME}/zanata
EXIT STATUS
${EXIT_CODE_OK} if sucessfully.
${EXIT_CODE_INVALID_ARGUMENTS} invalid or missing arguments
${EXIT_CODE_ERROR} no such pull request or other error.
END
}

function get_branch_from_pr(){
local urlPrefix=$1
local repo=$2
local pr=$3
local url=${urlPrefix}${repo}/pull/$pr

local tmpFile=$(mktemp --tmpdir zanata.XXXXXX)
curl -s -S $url > $tmpFile
sed -n -e '/data-channel.*branch/ s/\s*data-channel.*:branch:\(.*\)"/\1/ p' $tmpFile | head -n 1
rm -f $tmpFile
}

### Variable definition
export EXIT_CODE_OK=0
export EXIT_CODE_INVALID_ARGUMENTS=3
export EXIT_CODE_ERROR=5
export ZANATA_GIT_URL_PREFIX=https://github.com/zanata/

### Get arguments
BRANCH=
case $0 in
*zanata-client* )
REPO=zanata-client
;;
* )
REPO=$1
shift
;;
esac

if [[ -z "$REPO" ]];then
echo "Please specify repo" > /dev/stderr
print_usage > /dev/stderr
exit ${EXIT_CODE_INVALID_ARGUMENTS}
fi

if [[ $# -ne 2 ]];then
print_usage > /dev/stderr
exit ${EXIT_CODE_INVALID_ARGUMENTS}
fi

while getopts "p:" opt;do
#!/bin/bash -e
### NAME
### zanata-build-pr - Build pull request
### zanata-client-build-pr - Build zanata-client pull request
###
### SYNOPSIS
### zanata-build-pr -h
### zanata-build-pr [Options] -b <Branch> <repo>
### zanata-build-pr [Options] -p <GitHubPullRequestNumber> <Module>
### zanata-build-pr-<Module> -h
### zanata-build-pr-<Module> [Options] -b <Branch>
### zanata-build-pr-<Module> [Options] -p <GitHubPullRequestNumber>
###
### DESCRIPTION
### This program produce artifact list from m2 repo/
###
### OPTIONS
### <repo>
### Repository to build
### E.g. zanata-client
###
### -c:
### Clean the branch after build
###
### -b Branch name:
### Branch name
### E.g. master
###
### -p <GitHubPullRequestNumber>:
### GitHub Pull Request Number
### E.g. -p 45
###
###
### DESCRIPTION
### zanata-build-br checkouts the corresponding branch in
### given branch, then run:
###
### mvn -e clean install $ZANATA_MVN_BUILD_OPTIONS
###
### zanata-client-build-br is esentially
###
### zanata-build-pr zanata-client -p <GitHubPullRequestNumber>
###
ScriptDir=$(dirname $(readlink -q -f $0))
FunctionScriptFile=${ScriptDir}/zanata-functions
source "$FunctionScriptFile"
trap exit_print_error EXIT
### ENVIRONMENT
### WORK_ROOT
### The base directory for repository checkout
### As maven release plugin generally require a clean git working tree
### This script will clean it for you.
### Thus it is better not use normal development directory.
###
### ZANATA_MVN_BUILD_OPTIONS
### Default: -DstaticAnalysis
: ${ZANATA_MVN_BUILD_OPTIONS:=-DstaticAnalysis}

##=== parsing Start ===
print_status -t parsing -s "Start"

CleanBranch=0
PullRequestId=0
Branch=

while getopts "hcb:p:" opt;do
case $opt in
p )
PULL_REQUEST=$OPTARG
h )
zanata_script_help $0
exit ${EXIT_OK}
;;
c )
CleanBranch=1
;;
b )
Branch=$OPTARG
;;
r )
BRANCH=$OPTARG
p )
PullRequestId=$OPTARG
;;
* )
echo "Invalid option $opt" > /dev/stderr
print_usage > /dev/stderr
exit ${EXIT_CODE_INVALID_ARGUMENTS}
failed ${EXIT_FATAL_INVALID_OPTIONS} "$opt"
;;
esac
done

shift $((OPTIND-1))

### Create the repo if it is not there
if [[ ! -d "${ZANATA_CHECKOUT_PARENT_DIR}" ]];then
mkdir -p "${ZANATA_CHECKOUT_PARENT_DIR}"
## Get Module
moduleResult=$(get_module_from_command $1)
echo "moduleResult=$moduleResult"
Module=$(sed -e 's/ .*//'<<<"$moduleResult")
if [[ $moduleResult == *1 ]];then
shift
fi
print_status " Module=$Module"

cd ${ZANATA_CHECKOUT_PARENT_DIR}
##=== prepare Start ===
print_status -t prepare -s "Start"


if [[ ! -d "$REPO" ]];then
git clone ${ZANATA_GIT_URL_PREFIX}${REPO}.git
## Ensure repo
if [ ! -d ${WORK_ROOT} ];then
mkdir -p ${WORK_ROOT}
fi

### Get Branch
if [ -z "$BRANCH" ];then
BRANCH=$(get_branch_from_pr ${ZANATA_GIT_URL_PREFIX} ${REPO} ${PULL_REQUEST})
ensure_repo ${Module}
cd ${WORK_ROOT}/${Module}

##=== build Start ===
print_status -t build -s "Start"

if [ -n "$Branch" ];then
git fetch origin
elif [ -n "$PullRequestId" ];then
Branch=pr${PullRequestId}merge
git fetch origin "pull/$PullRequestId/merge:$Branch"
else
failed $EXIT_FATAL_INVALID_OPTIONS "Neither -b <Branch> nor -p <PullRequest> specified"
fi
git checkout $Branch
mvn -e clean install ${ZANATA_MVN_BUILD_OPTIONS}

echo "BRANCH is $BRANCH"

### Checkout the pull request
cd ${REPO}

git fetch origin pull/${PULL_REQUEST}/head:${BRANCH}
git checkout ${BRANCH}
if [ $CleanBranch -eq 1 ];then
git branch -D $Branch
fi

### Build
mvn clean install
File renamed without changes.

0 comments on commit 34b4a19

Please sign in to comment.