2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> release-job.sh"
14 #Python bits. Remove when centos 7.7 builder is avaliable.
15 if [ -d "/opt/pyenv" ]; then
16 echo "---> Setting up pyenv"
17 export PYENV_ROOT="/opt/pyenv"
18 export PATH="$PYENV_ROOT/bin:$PATH"
23 export PYENV_VERSION="3.6.4"
24 pip install --user lftools[nexus] jsonschema niet yq
28 set_variables_common(){
29 echo "---> INFO: Setting all common variables"
30 LOGS_SERVER="${LOGS_SERVER:-None}"
31 if [ "${LOGS_SERVER}" == 'None' ]; then
32 echo "FAILED: log server not found"
35 NEXUS_PATH="${SILO}/${JENKINS_HOSTNAME}/"
36 # Verify if using release file or parameters
37 if $USE_RELEASE_FILE ; then
38 release_files=$(git diff-tree --no-commit-id -r "$GERRIT_PATCHSET_REVISION" --name-only -- "releases/" ".releases/")
39 if (( $(grep -c . <<<"$release_files") > 1 )); then
40 echo "---> INFO: RELEASE FILES ARE AS FOLLOWS: $release_files"
41 echo "---> ERROR: Committing multiple release files in the same commit OR rename/amend of existing files is not supported."
44 release_file="$release_files"
45 echo "---> INFO: RELEASE FILE: $release_files"
48 echo "This job is built with parameters, no release file needed. Continuing..."
52 DISTRIBUTION_TYPE="${DISTRIBUTION_TYPE:-None}"
53 if [[ $DISTRIBUTION_TYPE == "None" ]]; then
54 DISTRIBUTION_TYPE="$(niet ".distribution_type" "$release_file")"
57 PATCH_DIR="$(mktemp -d)"
59 # Displaying Release Information (Common variables)
60 echo "RELEASE ENVIRONMENT INFO:"
61 echo "RELEASE_FILE: $release_file"
62 echo "LOGS_SERVER: $LOGS_SERVER"
63 echo "NEXUS_PATH: $NEXUS_PATH"
64 echo "JENKINS_HOSTNAME: $JENKINS_HOSTNAME"
66 echo "PROJECT: $PROJECT"
67 echo "PROJECT-DASHED: ${PROJECT//\//-}"
68 echo "DISTRIBUTION_TYPE: $DISTRIBUTION_TYPE"
71 set_variables_maven(){
72 VERSION="${VERSION:-None}"
73 if [[ $VERSION == "None" ]]; then
74 VERSION="$(niet ".version" "$release_file")"
76 LOG_DIR="${LOG_DIR:-None}"
77 if [[ $LOG_DIR == "None" ]]; then
78 LOG_DIR="$(niet ".log_dir" "$release_file")"
80 LOGS_URL="${LOGS_SERVER}/${NEXUS_PATH}${LOG_DIR}"
81 LOGS_URL=${LOGS_URL%/} # strip any trailing '/'
83 # Continuing displaying Release Information (Maven)
84 echo "RELEASE MAVEN INFO:"
85 echo "VERSION: $VERSION"
86 echo "LOG DIR: $LOG_DIR"
87 echo "LOGS URL: $LOGS_URL"
90 set_variables_container(){
91 VERSION="${VERSION:-None}"
92 if [[ $VERSION == "None" ]]; then
93 VERSION="$(niet ".container_release_tag" "$release_file")"
96 ref="$(niet ".ref" "$release_file")"
98 # Continuing displaying Release Information (Container)
99 echo "RELEASE CONTAINER INFO:"
100 echo "CONTAINER_RELEASE_TAG: $VERSION"
101 echo "GERRIT_REF_TO_TAG: $ref"
105 echo "---> INFO: Verifying $release_file schema."
106 lftools schema verify "$release_file" "$RELEASE_SCHEMA"
110 # Verify allowed versions
111 # Allowed versions are "v#.#.#" or "#.#.#" aka SemVer
112 allowed_version_regex="^((v?)([0-9]+)\.([0-9]+)\.([0-9]+))$"
113 if [[ ! $VERSION =~ $allowed_version_regex ]]; then
114 echo "The version $VERSION is not a semantic valid version"
115 echo "Allowed versions are \"v#.#.#\" or \"#.#.#\" aka SemVer"
116 echo "See https://semver.org/ for more details on SemVer"
122 # Import public signing key
123 gpg --import "$SIGNING_PUBKEY"
124 if git tag -v "$VERSION"; then
125 echo "---> OK: Repo already tagged $VERSION Continuting to release"
127 echo "---> INFO: Repo has not yet been tagged $VERSION"
128 git tag -am "${PROJECT//\//-} $VERSION" "$VERSION"
129 sigul --batch -c "$SIGUL_CONFIG" sign-git-tag "$SIGUL_KEY" "$VERSION" < "$SIGUL_PASSWORD"
130 echo "Showing latest signature for $PROJECT:"
131 echo "git tag -v $VERSION"
132 git tag -v "$VERSION"
134 ########## Merge Part ##############
135 if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
136 echo "--> INFO: Running merge"
137 gerrit_ssh=$(echo "$GERRIT_URL" | awk -F"/" '{print $3}')
138 git remote set-url origin ssh://"$RELEASE_USERNAME"@"$gerrit_ssh":29418/"$PROJECT"
139 git config user.name "$RELEASE_USERNAME"
140 git config user.email "$RELEASE_EMAIL"
141 echo -e "Host $gerrit_ssh\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
142 chmod 600 ~/.ssh/config
143 git push origin "$VERSION"
149 for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
150 # extract the domain name from URL
151 NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
152 echo "---> INFO: NEXUS_URL: $NEXUS_URL"
153 # extract the staging repo from URL
154 STAGING_REPO=${staging_url#*repositories/}
155 echo "Running Nexus Verify"
156 lftools nexus release -v --server https://"$NEXUS_URL" "$STAGING_REPO"
157 echo "Merge will run"
158 echo "lftools nexus release --server https://$NEXUS_URL $STAGING_REPO"
161 #Run the loop twice, to catch errors on either nexus repo
162 if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
163 for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
164 NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
165 STAGING_REPO=${staging_url#*repositories/}
166 echo "Promoting $STAGING_REPO on $NEXUS_URL."
167 lftools nexus release --server https://"$NEXUS_URL" "$STAGING_REPO"
172 container_release_file(){
173 echo "---> Processing container release"
175 lfn_umbrella="$(echo "$GERRIT_HOST" | awk -F"." '{print $2}')"
177 for namequoted in $(cat $release_file | yq '.containers[].name'); do
178 versionquoted=$(cat $release_file | yq ".containers[] |select(.name=="$namequoted") |.version")
180 #Remove extra yaml quotes
181 name="${namequoted#\"}"
183 version="${versionquoted#\"}"
184 version="${version%\"}"
188 echo "---> INFO: Merge will release $name $version as $VERSION"
189 #Pull from public, to see if we have already tagged this.
190 if docker pull "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"; then
191 echo "---> OK: $VERSION is already released for image $name, Continuing..."
193 echo "---> OK: $VERSION not found in releases, release will be prepared. Continuing..."
194 docker pull "$DOCKER_REGISTRY":10001/"$lfn_umbrella"/"$name":"$version"
195 container_image_id="$(docker images | grep $name | grep $version | awk '{print $3}')"
196 echo "---> INFO: Merge will run the following commands:"
197 echo "docker tag $container_image_id $DOCKER_REGISTRY:10002/$lfn_umbrella/$name:$VERSION"
198 echo "docker push $DOCKER_REGISTRY:10002/$lfn_umbrella/$name:$VERSION"
199 if [[ "$JOB_NAME" =~ "merge" ]]; then
200 docker tag "$container_image_id" "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"
201 docker push "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"
203 echo "#########################"
207 echo "---> INFO: Merge will tag ref: $ref"
212 maven_release_file(){
213 echo "---> INFO: wget -P $PATCH_DIR ${LOGS_URL}/staging-repo.txt.gz"
214 wget -P "$PATCH_DIR" "${LOGS_URL}/"staging-repo.txt.gz
216 echo "---> INFO: wget ${LOGS_URL}/patches/{${PROJECT//\//-}.bundle,taglist.log.gz}"
217 wget "${LOGS_URL}"/patches/{"${PROJECT//\//-}".bundle,taglist.log.gz}
218 gunzip taglist.log.gz
219 cat "$PATCH_DIR"/taglist.log
221 git checkout "$(awk '{print $NF}' "$PATCH_DIR/taglist.log")"
222 git fetch "$PATCH_DIR/${PROJECT//\//-}.bundle"
223 git merge --ff-only FETCH_HEAD
228 echo "########### Start Script release-job.sh ###################################"
230 # Check if this is a container or maven release: release-container-schema.yaml vs release-schema.yaml
231 # Logic to determine what we are releasing.
232 ##########################################
234 # Set common environment variables
237 if [[ "$DISTRIBUTION_TYPE" == "maven" ]]; then
238 wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-schema.yaml
239 RELEASE_SCHEMA="release-schema.yaml"
240 if $USE_RELEASE_FILE ; then
246 elif [[ "$DISTRIBUTION_TYPE" == "container" ]]; then
247 wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-container-schema.yaml
248 RELEASE_SCHEMA="release-container-schema.yaml"
250 set_variables_container
252 container_release_file
254 echo "---> ERROR: distribution_type: $DISTRIBUTION_TYPE not supported"
255 echo "Must be maven or container"
258 ##########################################
260 echo "########### End Script release-job.sh ###################################"