-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestPR.sh
executable file
·57 lines (46 loc) · 1.71 KB
/
testPR.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
#
# Test a PR by automatically updating .gitlab-ci.yml
# then adding, committing, and pushing
#
# Usage:
# ./testPR.sh <PR NUMBER> <REFBRANCH> <PRID> <SKIP CI> <MAKE NTUPLES> <IS SLC7>
#
# PRID is optional, it will get updated in the CI job if it doesn't exist
set -x # help debugging by printing commands, watch out if you use secrets!
PULLNUM="$1"
REFBRANCH="$2"
PRID="$3"
SKIPCI="$4" # if 1 skip all CI, 0 run
MAKENTUPLES="$5" # if 1 run cmsRun, make ntuples, plot, if 0 skip that (i.e. compile only)
ISSLC7="$6"
NEWBRANCH="test${PULLNUM}"
git checkout master
# If local branch already exists, delete it and do it again
git branch -D "${NEWBRANCH}"
git checkout -b "${NEWBRANCH}" master
REPLACESTR="#@TESTVARS@"
IMAGE="gitlab-registry.cern.ch/ci-tools/ci-worker:slc6"
if [[ $ISSLC7 == 1 ]]; then
IMAGE="gitlab-registry.cern.ch/ci-tools/ci-worker:cc7"
fi
CONTENTS=" PRNUM: \"${PULLNUM}\"\n"
CONTENTS="$CONTENTS REFBRANCH: \"${REFBRANCH}\"\n"
CONTENTS="$CONTENTS REMOTEBRANCH: \"pull/${PULLNUM}/head\"\n"
CONTENTS="$CONTENTS LOCALBRANCH: \"${NEWBRANCH}\"\n"
CONTENTS="$CONTENTS PRID: \"${PRID}\"\n"
CONTENTS="$CONTENTS MAKENTUPLES: \"${MAKENTUPLES}\"\n"
CONTENTS="$CONTENTS IMAGE: \"${IMAGE}\"\n"
CONTENTS="$CONTENTS$REPLACESTR\n" # add REPLACESTR back on for any future replacements
# Only work with gnu sed, be careful on mac
sed -i -e "s|${REPLACESTR}|${CONTENTS}|g" .gitlab-ci.yml
git add ".gitlab-ci.yml"
COMMITMSG="Test PR ${PULLNUM}"
if [[ $SKIPCI == 1 ]]; then
COMMITMSG="$COMMITMSG [ci skip]" # gitlab feature
fi
git commit -m "${COMMITMSG}"
git push -f origin "${NEWBRANCH}" # use force push to overwrite existing branch
echo "Pushed to origin/${NEWBRANCH}"
git checkout master
set +x