-
Notifications
You must be signed in to change notification settings - Fork 8
/
head_pkg_builder.sh
105 lines (95 loc) · 4.12 KB
/
head_pkg_builder.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#/usr/bin/env bash
# -bname build name
# -wspace build workspace dir
# -lcommit builds last commit
#read command line args
while getopts b:w:l: option
do
case "${option}"
in
b) BNAME=${OPTARG};;
w) WSPACE=${OPTARG};;
l) LCOMMIT=${OPTARG};;
esac
done
echo Build Name: $BNAME
echo Workspace: $WSPACE
echo Last Commit: $LCOMMIT
#change working directory to the dir for this build
echo Changing working directory to /var/lib/jenkins/workspace
cd /var/lib/jenkins/workspace
# check for the existence of an existing commit file for this
# project
SCRIPTFILE='/var/lib/jenkins/workspace/lastcommit/'$BNAME'.txt'
echo Searching for script file $SCRIPTFILE...
if [ -e $SCRIPTFILE ]
then
PREVRSA=$(<$SCRIPTFILE) &&
echo Found previous SHA $PREVRSA
# Backup existing Package.xml
cd $WSPACE/src
echo changing directoy to $WSPACE
cp package.xml{,.bak} &&
echo Backing up package.xml to package.xml.bak &&
read -d '' NEWPKGXML <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<Package>
</Package>
EOF
echo ===PKGXML===
echo $NEWPKGXML
echo Creating new package.xml
echo $NEWPKGXML > $WSPACE/src/package.xml
for CFILE in `git diff-tree --no-commit-id --name-only -r $LCOMMIT $PREVRSA`
do
echo Analyzing file `basename $CFILE`
case "$CFILE"
in
*.cls*) TYPENAME="ApexClass";;
*.page*) TYPENAME="ApexPage";;
*.component*) TYPENAME="ApexComponent";;
*.trigger*) TYPENAME="ApexTrigger";;
*.app*) TYPENAME="CustomApplication";;
*.labels*) TYPENAME="CustomLabels";;
*.object*) TYPENAME="CustomObject";;
*.tab*) TYPENAME="CustomTab";;
*.resource*) TYPENAME="StaticResource";;
*.workflow*) TYPENAME="Workflow";;
*.remoteSite*) TYPENAME="RemoteSiteSettings";;
*.pagelayout*) TYPENAME="Layout";;
*) TYPENAME="UNKNOWN TYPE";;
esac
if [[ "$TYPENAME" != "UNKNOWN TYPE" ]]
then
ENTITY=$(basename "$CFILE")
ENTITY="${ENTITY%.*}"
echo ENTITY NAME: $ENTITY
if grep -Fq "$TYPENAME" $WSPACE/src/package.xml
then
echo Generating new member for $ENTITY
xmlstarlet ed -L -s "/Package/types[name='$TYPENAME']" -t elem -n members -v "$ENTITY" $WSPACE/src/package.xml
else
echo Generating new $TYPENAME type
xmlstarlet ed -L -s /Package -t elem -n types -v "" $WSPACE/src/package.xml
xmlstarlet ed -L -s '/Package/types[not(*)]' -t elem -n name -v "$TYPENAME" $WSPACE/src/package.xml
echo Generating new member for $ENTITY
xmlstarlet ed -L -s "/Package/types[name='$TYPENAME']" -t elem -n members -v "$ENTITY" $WSPACE/src/package.xml
fi
else
echo ERROR: UNKNOWN FILE TYPE $CFILE
fi
echo ====UPDATED PACKAGE.XML====
cat $WSPACE/src/package.xml
done
echo Saving last RSA Commit
echo $LCOMMIT > /var/lib/jenkins/workspace/lastcommit/$BNAME.txt
echo Cleaning up Package.xml
xmlstarlet ed -L -s /Package -t elem -n version -v "27.0" $WSPACE/src/package.xml
xmlstarlet ed -L -i /Package -t attr -n xmlns -v "http://soap.sforce.com/2006/04/metadata" $WSPACE/src/package.xml
echo ====FINAL PACKAGE.XML=====
cat $WSPACE/src/package.xml
else
echo No RSA found, default Package.xml will be used
echo Creating new list commit file
echo $LCOMMIT > /var/lib/jenkins/workspace/lastcommit/$BNAME.txt
fi