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 echo "---> INFO: Verifying $release_file schema."
29 lftools schema verify "$release_file" "$RELEASE_SCHEMA"
30 # Verify allowed versions
31 # Allowed versions are "v#.#.#" or "#.#.#" aka SemVer
32 allowed_version_regex="^((v?)([0-9]+)\.([0-9]+)\.([0-9]+))$"
33 if [[ ! $VERSION =~ $allowed_version_regex ]]; then
34 echo "The version $VERSION is not a semantic valid version"
35 echo "Allowed versions are \"v#.#.#\" or \"#.#.#\" aka SemVer"
36 echo "See https://semver.org/ for more details on SemVer"
42 if git tag -v "$VERSION"; then
43 echo "---> OK: Repo already tagged $VERSION Continuting to release"
46 echo "---> INFO: Repo has not yet been tagged $VERSION"
47 git tag -am "${PROJECT//\//-} $VERSION" "$VERSION"
48 sigul --batch -c "$SIGUL_CONFIG" sign-git-tag "$SIGUL_KEY" "$VERSION" < "$SIGUL_PASSWORD"
49 echo "Showing latest signature for $PROJECT:"
50 gpg --import "$SIGNING_PUBKEY"
51 echo "git tag -v $VERSION"
53 ########## Merge Part ##############
54 if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
55 echo "--> INFO: Running merge"
56 gerrit_ssh=$(echo "$GERRIT_URL" | awk -F"/" '{print $3}')
57 git remote set-url origin ssh://"$RELEASE_USERNAME"@"$gerrit_ssh":29418/"$PROJECT"
58 git config user.name "$RELEASE_USERNAME"
59 git config user.email "$RELEASE_EMAIL"
60 echo -e "Host $gerrit_ssh\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
61 chmod 600 ~/.ssh/config
62 git push origin "$VERSION"
68 for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
69 # extract the domain name from URL
70 NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
71 echo "---> INFO: NEXUS_URL: $NEXUS_URL"
72 # extract the staging repo from URL
73 STAGING_REPO=${staging_url#*repositories/}
74 echo "Running Nexus Verify"
75 lftools nexus release -v --server https://"$NEXUS_URL" "$STAGING_REPO"
77 echo "lftools nexus release --server https://$NEXUS_URL $STAGING_REPO"
80 #Run the loop twice, to catch errors on either nexus repo
81 if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
82 for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
83 NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
84 STAGING_REPO=${staging_url#*repositories/}
85 echo "Promoting $STAGING_REPO on $NEXUS_URL."
86 lftools nexus release --server https://"$NEXUS_URL" "$STAGING_REPO"
92 container_release_file(){
93 echo "---> Processing container release"
95 lfn_umbrella="$(echo "$GERRIT_HOST" | awk -F"." '{print $2}')"
98 for namequoted in $(cat $release_file | yq '.containers[].name'); do
99 versionquoted=$(cat $release_file | yq ".containers[] |select(.name=="$namequoted") |.version")
101 #Remove extra yaml quotes
102 name="${namequoted#\"}"
104 version="${versionquoted#\"}"
105 version="${version%\"}"
109 echo "---> INFO: Merge will release $name $version as $VERSION"
110 #Pull from public, to see if we have already tagged this.
111 if docker pull "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"; then
112 echo "---> OK: $VERSION is already released for image $name, Continuing..."
114 echo "---> OK: $VERSION not found in releases, release will be prepared. Continuing..."
115 docker pull "$DOCKER_REGISTRY":10001/"$lfn_umbrella"/"$name":"$version"
116 container_image_id="$(docker images | grep $name | grep $version | awk '{print $3}')"
117 echo "---> INFO: Merge will run the following commands:"
118 echo "docker tag $container_image_id $DOCKER_REGISTRY:10002/$lfn_umbrella/$name:$VERSION"
119 echo "docker push $DOCKER_REGISTRY:10002/$lfn_umbrella/$name:$VERSION"
120 if [[ "$JOB_NAME" =~ "merge" ]]; then
121 docker tag "$container_image_id" "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"
122 docker push "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"
124 echo "#########################"
128 ref="$(niet ".ref" "$release_file")"
129 echo "---> INFO: Merge will tag ref: $ref"
134 maven_release_file(){
135 echo "---> INFO: wget -P $PATCH_DIR ${LOGS_URL}/staging-repo.txt.gz"
136 wget -P "$PATCH_DIR" "${LOGS_URL}/"staging-repo.txt.gz
138 echo "---> INFO: wget ${LOGS_URL}/patches/{${PROJECT//\//-}.bundle,taglist.log.gz}"
139 wget "${LOGS_URL}"/patches/{"${PROJECT//\//-}".bundle,taglist.log.gz}
140 gunzip taglist.log.gz
141 cat "$PATCH_DIR"/taglist.log
143 git checkout "$(awk '{print $NF}' "$PATCH_DIR/taglist.log")"
144 git fetch "$PATCH_DIR/${PROJECT//\//-}.bundle"
145 git merge --ff-only FETCH_HEAD
150 echo "########### Start Script release-job.sh ###################################"
151 echo "---> INFO: Setting all VARS"
153 LOGS_SERVER="${LOGS_SERVER:-None}"
154 MAVEN_CENTRAL_URL="${MAVEN_CENTRAL_URL:-None}"
155 if [ "${LOGS_SERVER}" == 'None' ]; then
156 echo "FAILED: log server not found"
160 if $USE_RELEASE_FILE ; then
162 release_files=$(git diff-tree --no-commit-id -r "$GERRIT_PATCHSET_REVISION" --name-only -- "releases/" ".releases/")
163 if (( $(grep -c . <<<"$release_files") > 1 )); then
164 echo "---> INFO: RELEASE FILES ARE AS FOLLOWS: $release_files"
165 echo "---> ERROR: Committing multiple release files in the same commit OR rename/amend of existing files is not supported."
168 release_file="$release_files"
169 echo "---> INFO: RELEASE FILE: $release_files"
173 echo "This job is built with parameters, no release file needed. Continuing..."
178 NEXUS_PATH="${SILO}/${JENKINS_HOSTNAME}/"
180 VERSION="${VERSION:-None}"
181 if [[ $VERSION == "None" ]]; then
182 VERSION="$(niet ".version" "$release_file")"
185 LOG_DIR="${LOG_DIR:-None}"
186 if [[ $LOG_DIR == "None" ]]; then
187 LOG_DIR="$(niet ".log_dir" "$release_file")"
190 DISTRIBUTION_TYPE="${DISTRIBUTION_TYPE:-None}"
191 if [[ $DISTRIBUTION_TYPE == "None" ]]; then
192 DISTRIBUTION_TYPE="$(niet ".distribution_type" "$release_file")"
196 LOGS_URL="${LOGS_SERVER}/${NEXUS_PATH}${LOG_DIR}"
197 LOGS_URL=${LOGS_URL%/} # strip any trailing '/'
198 PATCH_DIR="$(mktemp -d)"
201 echo "RELEASE_FILE: $release_file"
202 echo "LOGS_SERVER: $LOGS_SERVER"
203 echo "NEXUS_PATH: $NEXUS_PATH"
204 echo "JENKINS_HOSTNAME: $JENKINS_HOSTNAME"
206 echo "PROJECT: $PROJECT"
207 echo "PROJECT-DASHED: ${PROJECT//\//-}"
208 echo "VERSION: $VERSION"
209 echo "LOG DIR: $LOG_DIR"
210 echo "LOGS URL: $LOGS_URL"
211 echo "DISTRIBUTION_TYPE: $DISTRIBUTION_TYPE"
212 #Check if this is a container or maven release: release-container-schema.yaml vs release-schema.yaml
214 #Logic to determine what we are releasing.
215 ##########################################
216 if [[ "$DISTRIBUTION_TYPE" == "maven" ]]; then
217 wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-schema.yaml
218 RELEASE_SCHEMA="release-schema.yaml"
219 if $USE_RELEASE_FILE ; then
223 elif [[ "$DISTRIBUTION_TYPE" == "container" ]]; then
224 wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-container-schema.yaml
225 RELEASE_SCHEMA="release-container-schema.yaml"
227 container_release_file
229 echo "---> ERROR: distribution_type: $DISTRIBUTION_TYPE not supported"
230 echo "Must be maven or container"
233 ##########################################
235 echo "########### End Script release-job.sh ###################################"