summaryrefslogtreecommitdiffstats
path: root/autorelease/scripts/generate-jjbs/gen-code-jjbs.sh
blob: 9432cee549b6388f919aeb409e65fb63669594d9 (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
#
# Copyright 2016-2017 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# autorelease root dir
ROOT=`git rev-parse --show-toplevel`/autorelease

BUILD_DIR=$ROOT/build
JJB_DIR=$BUILD_DIR/ci-management/jjb

cd $BUILD_DIR

source $ROOT/scripts/generate-jjbs/workarounds.sh


find . -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | sort | while read repo; do
    project=${repo}
 
    toxs=`find $repo -type d -exec test -e "{}/tox.ini" ';' -prune -printf "%P/tox.ini\n" | sort`

    in_sun_branch=`git show sun:autorelease/all-projects.txt | grep -x ${repo}`

    mkdir -p $JJB_DIR/$repo

    if [ ! -z "$toxs" ]; then
	rm -f $JJB_DIR/$repo/${repo}-python.yaml

	project=${repo}-java
	echo $repo/${repo}-python.yaml
	
	cat > $JJB_DIR/$repo/${repo}-python.yaml <<EOF
---
- project:
    name: ${repo}-python
    project: '${repo}'
    stream:
      - 'master':
          branch: 'master'
EOF
	if [ $in_sun_branch ]; then
	    cat >> $JJB_DIR/$repo/${repo}-python.yaml <<EOF
      - 'sun':
          branch: 'sun'
EOF
	fi
	cat >> $JJB_DIR/$repo/${repo}-python.yaml <<EOF
    mvn-settings: '${repo}-settings'
    build-node: 'centos7-redis-2c-1g'
    subproject:
EOF
	for tox in $toxs; do
	    toxpath=${tox%/tox.ini}

	    if [ "$toxpath" == "" ]; then
		subproject="root"
		pathparam="."
		pattern="**"
	    else
		subproject=${toxpath////-} # replace slash with dash
		pathparam=$toxpath
		pattern="$toxpath/**"

		# do special subproject names
		for SUB in "${SUBPROJECT_MAP[@]}"; do
		    if [ "${SUB%:*}" = "$repo/$toxpath" ]; then
			subproject=${SUB#*:}
		    fi
		done
	    fi

	    cat >> $JJB_DIR/$repo/${repo}-python.yaml <<EOF
      - '${subproject}':
          path: '${pathparam}'
          pattern: '${pattern}'
EOF
	done
	cat >> $JJB_DIR/$repo/${repo}-python.yaml <<EOF
    jobs:
      - '{project}-{stream}-{subproject}-verify-python'
EOF
    fi




    has_subprojects=0
    for r in "${SPLIT_REPOS[@]}"; do
	if [ "$repo" = "$r" ]; then
	    has_subprojects=1
	fi
    done

    if [ $has_subprojects -eq 1 ]; then
	poms=`find $repo -mindepth 1 -type d -exec test -e "{}/pom.xml" ';' -prune -printf "%P/pom.xml\n" | sort`
    else
	poms=`find $repo -type d -exec test -e "{}/pom.xml" ';' -prune -printf "%P/pom.xml\n" | sort`
	if [ "$poms" != "/pom.xml" ]; then
	    has_subprojects=1
	fi
    fi
    
    
    if [ ! -z "$poms" ]; then
	rm -f $JJB_DIR/$repo/${repo}.yaml
	rm -f $JJB_DIR/$repo/${repo}-java.yaml
	echo $repo/${project}.yaml
    fi

    if [ $has_subprojects -eq 0 ]; then
	# root pom.xml found
	cat > $JJB_DIR/$repo/${project}.yaml <<EOF
---
- project:
    name: ${project}
    jobs:
      - '{project}-{stream}-verify-java'
      - '{project}-{stream}-merge-java'

    project: '${repo}'
    stream:
      - 'master':
          branch: 'master'
EOF
	if [ $in_sun_branch ]; then
	    cat >> $JJB_DIR/$repo/${project}.yaml <<EOF
      - 'sun':
          branch: 'sun'
EOF
	fi
	cat >> $JJB_DIR/$repo/${project}.yaml <<EOF
    mvn-settings: '${repo}-settings'
EOF
    elif [ ! -z "$poms" ]; then
	cat > $JJB_DIR/$repo/${project}.yaml <<EOF
---
- project:
    name: ${project}
    project: '${repo}'
    stream:
      - 'master':
          branch: 'master'
EOF
	if [ $in_sun_branch ]; then
	    cat >> $JJB_DIR/$repo/${project}.yaml <<EOF
      - 'sun':
          branch: 'sun'
EOF
	fi
	cat >> $JJB_DIR/$repo/${project}.yaml <<EOF
    mvn-settings: '${repo}-settings'
    subproject:
EOF

	for pom in $poms; do
	    pompath=${pom%/pom.xml}
	    subproject=${pompath////-} # replace slash with dash
	    cat >> $JJB_DIR/$repo/${project}.yaml <<EOF
      - '${subproject}':
          pom: '${pom}'
          pattern: '${pompath}/**'
EOF
	done

	if [ -e $BUILD_DIR/$repo/pom.xml ]; then
	    cat >> $JJB_DIR/$repo/${project}.yaml <<EOF
      - 'root':
          pom: 'pom.xml'
          pattern: '*'
EOF
	fi

	cat >> $JJB_DIR/$repo/${project}.yaml <<EOF
    jobs:
      - '{project}-{stream}-{subproject}-verify-java'
      - '{project}-{stream}-{subproject}-merge-java'
EOF
    fi
done