Fix release job script
[releng/global-jjb.git] / shell / release-job.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
5 #
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"
12 set -eu -o pipefail
13
14 # shellcheck disable=SC1090
15 source ~/lf-env.sh
16
17 # Version controlled by JJB_VERSION
18 lf-activate-venv lftools pip idna==2.9 lftools jsonschema twine yq readline
19
20 # show installed versions
21 python -m pip --version
22 python -m pip freeze
23
24 #Functions.
25
26 set_variables_common(){
27     echo "INFO: Setting common variables"
28     if [[ -z ${LOGS_SERVER:-} ]] && [[ -z ${CDN_URL:-} ]]; then
29         echo "ERROR: LOGS_SERVER or CDN_URL not defined"
30         exit 1
31     fi
32     NEXUS_PATH="${SILO}/${JENKINS_HOSTNAME}/"
33     # Verify if using release file or parameters
34     if $USE_RELEASE_FILE ; then
35         release_files=$(git diff-tree -m --no-commit-id -r "$GIT_COMMIT" "$GIT_COMMIT^1" \
36             --name-only -- "releases/" ".releases/")
37         if (( $(grep -c . <<<"$release_files") > 1 )); then
38           echo "INFO: RELEASE FILES ARE AS FOLLOWS: $release_files"
39           echo "ERROR: Adding multiple release files in the same commit"
40           echo "ERROR: OR rename/amend/delete of existing files is not supported."
41           exit 1
42         else
43           release_file="$release_files"
44           echo "INFO: RELEASE FILE: $release_files"
45         fi
46     else
47         echo "INFO: This job is built with parameters, no release file needed."
48         release_file="None"
49     fi
50
51     if [[ -z ${LOG_DIR:-} ]]; then
52         LOG_DIR=$(yq -r ".log_dir" "$release_file")
53     fi
54     if [[ -n ${LOGS_SERVER:-} ]]; then
55         logs_url="${LOGS_SERVER}/${NEXUS_PATH}${LOG_DIR}"
56     elif [[ -n ${CDN_URL:-} ]]; then
57         logs_url="https://${CDN_URL:-}/logs/${NEXUS_PATH}${LOG_DIR}"
58     fi
59     logs_url=${logs_url%/}  # strip any trailing '/'
60
61     # Jenkins parameter drop-down defaults DISTRIBUTION_TYPE to None
62     # in the contain/maven release job; get value from release yaml.
63     # Packagecloud and PyPI jobs set the appropriate value.
64     DISTRIBUTION_TYPE="${DISTRIBUTION_TYPE:-None}"
65     if [[ $DISTRIBUTION_TYPE == "None" ]]; then
66         if ! DISTRIBUTION_TYPE=$(yq -r ".distribution_type" "$release_file"); then
67             echo "ERROR: Failed to get distribution_type from $release_file"
68             exit 1
69         fi
70     fi
71
72     PATCH_DIR=$(mktemp -d)
73
74     TAG_RELEASE="${TAG_RELEASE:-None}"
75     if [[ $TAG_RELEASE == "None" ]]; then
76         if grep -q "tag_release" $release_file ; then
77             TAG_RELEASE=$(yq -r .tag_release "$release_file")
78         else
79             TAG_RELEASE=true
80         fi
81     fi
82
83     # Displaying Release Information (Common variables)
84     printf "\t%-30s\n" RELEASE_ENVIRONMENT_INFO:
85     printf "\t%-30s %s\n" RELEASE_FILE: "$release_file"
86     printf "\t%-30s %s\n" LOGS_SERVER: "$LOGS_SERVER"
87     printf "\t%-30s %s\n" CDN_URL: "${CDN_URL:-None}"
88     printf "\t%-30s %s\n" NEXUS_PATH: "$NEXUS_PATH"
89     printf "\t%-30s %s\n" JENKINS_HOSTNAME: "$JENKINS_HOSTNAME"
90     printf "\t%-30s %s\n" SILO: "$SILO"
91     printf "\t%-30s %s\n" PROJECT: "$PROJECT"
92     printf "\t%-30s %s\n" PROJECT-DASHED: "${PROJECT//\//-}"
93     printf "\t%-30s %s\n" TAG_RELEASE: "$TAG_RELEASE"
94     printf "\t%-30s %s\n" DISTRIBUTION_TYPE: "$DISTRIBUTION_TYPE"
95     printf "\t%-30s %s\n" OVERRIDE_SEMVER_REGEX: "${OVERRIDE_SEMVER_REGEX:-None}"
96 }
97
98 set_variables_maven(){
99     echo "INFO: Setting maven variables"
100     if [[ -z ${VERSION:-} ]]; then
101         VERSION=$(yq -r ".version" "$release_file")
102     fi
103     if [[ -z ${GIT_TAG:-} ]]; then
104         if grep -q "git_tag" "$release_file" ; then
105             GIT_TAG=$(yq -r ".git_tag" "$release_file")
106         else
107             GIT_TAG="$VERSION"
108         fi
109     fi
110     if [[ -z ${LOG_DIR:-} ]]; then
111         LOG_DIR=$(yq -r ".log_dir" "$release_file")
112     fi
113
114     # Continuing displaying Release Information (Maven)
115     printf "\t%-30s\n" RELEASE_MAVEN_INFO:
116     printf "\t%-30s %s\n" VERSION: "$VERSION"
117     printf "\t%-30s %s\n" GIT_TAG: "$GIT_TAG"
118     printf "\t%-30s %s\n" LOG_DIR: "$LOG_DIR"
119     printf "\t%-30s %s\n" LOGS_URL: "$logs_url"
120 }
121
122 set_variables_container(){
123     echo "INFO: Setting container variables"
124     if [[ -z ${VERSION:-} ]]; then
125         VERSION=$(yq -r ".container_release_tag" "$release_file")
126     fi
127     if [[ -z ${GIT_TAG:-} ]]; then
128         if grep -q "git_tag" "$release_file" ; then
129             GIT_TAG=$(yq -r ".git_tag" "$release_file")
130         else
131             GIT_TAG="$VERSION"
132         fi
133    fi
134     if grep -q "container_pull_registry" "$release_file" ; then
135         CONTAINER_PULL_REGISTRY=$(yq -r ".container_pull_registry" "$release_file")
136     fi
137     if grep -q "container_push_registry" "$release_file" ; then
138         CONTAINER_PUSH_REGISTRY=$(yq -r ".container_push_registry" "$release_file")
139     fi
140     # Make sure both pull and push registries are defined
141     if [ -z ${CONTAINER_PULL_REGISTRY+x} ] || [ -z ${CONTAINER_PUSH_REGISTRY+x} ]; then
142         echo "ERROR: CONTAINER_PULL_REGISTRY and CONTAINER_PUSH_REGISTRY need to be defined"
143         exit 1
144     fi
145     ref=$(yq -r ".ref" "$release_file")
146
147     # Continuing displaying Release Information (Container)
148     printf "\t%-30s\n" RELEASE_CONTAINER_INFO:
149     printf "\t%-30s %s\n" CONTAINER_RELEASE_TAG: "$VERSION"
150     printf "\t%-30s %s\n" CONTAINER_PULL_REGISTRY: "$CONTAINER_PULL_REGISTRY"
151     printf "\t%-30s %s\n" CONTAINER_PUSH_REGISTRY: "$CONTAINER_PUSH_REGISTRY"
152     printf "\t%-30s %s\n" GIT_REF_TO_TAG: "$ref"
153     printf "\t%-30s %s\n" GIT_TAG: "$GIT_TAG"
154 }
155
156 set_variables_pypi(){
157     echo "INFO: Setting pypi variables"
158     if [[ -z ${LOG_DIR:-} ]]; then
159         LOG_DIR=$(yq -r ".log_dir" "$release_file")
160     fi
161
162     if [[ -z ${PYPI_PROJECT:-} ]]; then
163         PYPI_PROJECT=$(yq -r ".pypi_project" "$release_file")
164     fi
165     if [[ -z ${PYTHON_VERSION:-} ]]; then
166         PYTHON_VERSION=$(yq -r ".python_version" "$release_file")
167     fi
168     if [[ -z ${VERSION:-} ]]; then
169         VERSION=$(yq -r ".version" "$release_file")
170     fi
171     if [[ -z ${GIT_TAG:-} ]]; then
172         if grep -q "git_tag" "$release_file" ; then
173             GIT_TAG=$(yq -r ".git_tag" "$release_file")
174         else
175             GIT_TAG="$VERSION"
176         fi
177    fi
178
179     # Continuing displaying Release Information (pypi)
180     printf "\t%-30s\n" RELEASE_PYPI_INFO:
181     printf "\t%-30s %s\n" LOG_DIR: "$LOG_DIR"
182     printf "\t%-30s %s\n" LOGS_URL: "$logs_url"
183     printf "\t%-30s %s\n" PYPI_INDEX: "$PYPI_INDEX" # from job configuration
184     printf "\t%-30s %s\n" PYPI_PROJECT: "$PYPI_PROJECT"
185     printf "\t%-30s %s\n" PYTHON_VERSION: "$PYTHON_VERSION"
186     printf "\t%-30s %s\n" VERSION: "$VERSION"
187     printf "\t%-30s %s\n" GIT_TAG: "$GIT_TAG"
188 }
189
190 set_variables_packagecloud(){
191      echo "INFO: Setting packagecloud variables"
192      if [[ -z ${VERSION:-} ]]; then
193          VERSION=$(yq -r ".version" "$release_file")
194      fi
195      if [[ -z ${GIT_TAG:-} ]]; then
196          if grep -q "git_tag" $release_file ; then
197              GIT_TAG=$(yq -r ".git_tag" "$release_file")
198          else
199              GIT_TAG="$VERSION"
200          fi
201      fi
202      if [[ -z ${LOG_DIR:-} ]]; then
203          LOG_DIR=$(yq -r ".log_dir" "$release_file")
204      fi
205      if [[ -z ${REF:-} ]]; then
206          REF=$(yq -r ".ref" "$release_file")
207      fi
208      if [[ -z ${PACKAGE_NAME:-} ]]; then
209          PACKAGE_NAME=$(yq -r ".package_name" "$release_file")
210      fi
211
212      printf "\t%-30s %s\n" PACKAGE_NAME: "$PACKAGE_NAME"
213      printf "\t%-30s %s\n" LOG_DIR: "$LOG_DIR"
214      printf "\t%-30s %s\n" LOGS_URL: "$logs_url"
215      printf "\t%-30s %s\n" GIT_REF_TO_TAG: "$REF"
216      printf "\t%-30s %s\n" VERSION: "$VERSION"
217      printf "\t%-30s %s\n" GIT_TAG: "$GIT_TAG"
218 }
219
220 verify_schema(){
221     echo "INFO: Verifying $release_file against schema $release_schema"
222     lftools schema verify "$release_file" "$release_schema"
223 }
224
225 verify_version(){
226
227     # Override the regex for projects that do not follow https://semver.org
228     OVERRIDE_SEMVER_REGEX="${OVERRIDE_SEMVER_REGEX:-None}"
229     if [[ $OVERRIDE_SEMVER_REGEX == "None" ]]; then
230         # Use the semver regex taken from https://github.com/fsaintjacques/semver-tool
231         semver_regex="^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$"
232     else
233         semver_regex="${OVERRIDE_SEMVER_REGEX}"
234     fi
235
236     # Verify SemVer "#.#.#" (SemVer) or "v#.#.#"
237     echo "INFO: Verifying version $VERSION"
238     if [[ $VERSION =~ $semver_regex ]]; then
239         echo "INFO: The version $VERSION is valid"
240     else
241         echo "ERROR: The version $VERSION is not valid"
242         echo "ERROR: Valid versions are \"#.#.#\" (SemVer) or \"v#.#.#\""
243         echo "ERROR: Valid version will be matched against \"${semver_regex}\""
244         echo "ERROR: Refer to https://semver.org/ for more details on SemVer"
245         echo "ERROR: Refer SemVer examples from https://github.com/fsaintjacques/semver-tool/#examples"
246         exit 1
247     fi
248 }
249
250 verify_version_match_release(){
251     echo "INFO: Fetching console log from $logs_url"
252     wget -P /tmp "${logs_url}/"console.log.gz
253     echo "INFO: Searching for uploaded step and version $VERSION in job log"
254     if zgrep "Successfully uploaded" /tmp/console.log.gz | grep "$VERSION"; then
255         echo "INFO: found expected strings in job log"
256     else
257         echo "ERROR: Defined version in release file does not match staging repo artifacts version to be released"
258         echo "ERROR: Please make sure maven stage job log dir and release version are both correct"
259         exit 1
260     fi
261 }
262
263 # check prerequisites to detect mistakes in the release YAML file
264 verify_pypi_match_release(){
265     echo "INFO: Fetching console log from $logs_url"
266     wget -q -P /tmp "${logs_url}/"console.log.gz
267     echo "INFO: Searching for uploaded step, project $PYPI_PROJECT and version $VERSION in job log"
268     # pypi-upload.sh generates success message with file list
269     if zgrep -i "uploaded" /tmp/console.log.gz | grep "$PYPI_PROJECT" | grep "$VERSION" ; then
270         echo "INFO: found expected strings in job log"
271     else
272         echo "ERROR: failed to find expected strings in job log"
273         exit 1
274     fi
275 }
276
277 verify_packagecloud_match_release(){
278     echo "INFO: Fetching console log from $logs_url"
279     wget -q -P /tmp "${logs_url}/"console.log.gz
280     echo "INFO: Searching for uploaded step, package name $PACKAGE_NAME and version $VERSION in job log"
281     if  zgrep -E "Pushing.*$PACKAGE_NAME.*$VERSION.*success\!" /tmp/console.log.gz; then
282         echo "INFO: found expected strings in job log"
283     else
284         echo "ERROR: failed to find expected strings in job log"
285         exit 1
286     fi
287 }
288
289 # sigul is only available on Centos
290 # TODO: write tag-github-repo function
291 tag-git-repo(){
292     if [[ $TAG_RELEASE == false ]]; then
293        echo "INFO: Skipping code repo tag"
294        return
295     fi
296
297     if [[ -z ${GERRIT_URL:-} ]]; then
298         GIT_REPO_BASE=github
299     else
300         GIT_REPO_BASE=gerrit
301     fi
302
303     echo "INFO: tag repo with $GIT_TAG"
304     # Import public signing key
305     gpg --import "$SIGNING_PUBKEY"
306     if type=$(git cat-file -t "$GIT_TAG"); then
307         if [[ $type == "tag" ]]; then
308             echo "INFO: Repo already has signed tag $GIT_TAG, nothing to do"
309         else
310             echo "ERROR: Repo has lightweight tag $GIT_TAG, blocks push of signed tag"
311             exit 1
312         fi
313     else
314         echo "INFO: Repo has not yet been tagged $GIT_TAG"
315         git tag -am "${PROJECT//\//-} $GIT_TAG" "$GIT_TAG"
316         sigul --batch -c "$SIGUL_CONFIG" sign-git-tag "$SIGUL_KEY" "$GIT_TAG" < "$SIGUL_PASSWORD"
317         echo "INFO: Showing latest signature for $PROJECT:"
318         echo "INFO: git tag -v $GIT_TAG"
319         git tag -v "$GIT_TAG"
320
321         ########## Merge Part ##############
322         if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
323             echo "INFO: Running merge, pushing tag"
324             if [[ $GIT_REPO_BASE == "gerrit" ]]; then
325                 gerrit_ssh=$(echo "$GERRIT_URL" | awk -F"/" '{print $3}')
326                 git remote set-url origin ssh://"$RELEASE_USERNAME"@"$gerrit_ssh":29418/"$PROJECT"
327                 echo -e "Host $gerrit_ssh\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
328                 chmod 600 ~/.ssh/config
329             else
330                 git remote set-url origin "$GIT_CLONE_URL""$RELEASE_USERNAME"/"$PROJECT".git
331             fi
332             git config user.name "$RELEASE_USERNAME"
333             git config user.email "$RELEASE_EMAIL"
334             git push origin "$GIT_TAG"
335         fi
336     fi
337 }
338
339 nexus_release(){
340     echo "INFO: Processing nexus release"
341     for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
342         # extract the domain name from URL
343         NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
344         echo "INFO: NEXUS_URL: $NEXUS_URL"
345         # extract the staging repo from URL
346         STAGING_REPO=${staging_url#*repositories/}
347         echo "INFO: Running Nexus Verify"
348         lftools nexus release -v --server https://"$NEXUS_URL" "$STAGING_REPO"
349         echo "INFO: Merge will run:"
350         echo "lftools nexus release --server https://$NEXUS_URL $STAGING_REPO"
351     done
352
353     #Run the loop twice, to catch errors on either nexus repo
354     if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
355         for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
356           NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
357           STAGING_REPO=${staging_url#*repositories/}
358           echo "INFO: Promoting $STAGING_REPO on $NEXUS_URL."
359           lftools nexus release --server https://"$NEXUS_URL" "$STAGING_REPO"
360         done
361     fi
362 }
363
364 container_release_file(){
365     echo "INFO: Processing container release"
366     docker --version
367     local lfn_umbrella
368     lfn_umbrella="$(echo "$GERRIT_URL" | awk -F"." '{print $2}')"
369
370     for namequoted in $(yq '.containers[].name' $release_file); do
371         versionquoted=$(yq ".containers[] |select(.name==$namequoted) |.version" $release_file)
372
373         #Remove extra yaml quotes
374         name="${namequoted#\"}"
375         name="${name%\"}"
376         version="${versionquoted#\"}"
377         version="${version%\"}"
378
379         echo "$name"
380         echo "$version"
381         echo "INFO: Merge will release $name $version as $VERSION"
382         # Attempt to pull from releases registry to see if the image has been released.
383         if docker pull "$CONTAINER_PUSH_REGISTRY"/"$lfn_umbrella"/"$name":"$VERSION"; then
384             echo "INFO: $VERSION is already released for image $name, Continuing..."
385         else
386             echo "INFO: $VERSION not found in releases, release will be prepared. Continuing..."
387             docker pull "$CONTAINER_PULL_REGISTRY"/"$lfn_umbrella"/"$name":"$version"
388             container_image_id=$(docker images | grep "$name" | grep "$version" | awk '{print $3}')
389             echo "INFO: Merge will run the following commands:"
390             echo "docker tag $container_image_id $CONTAINER_PUSH_REGISTRY/$lfn_umbrella/$name:$VERSION"
391             echo "docker push $CONTAINER_PUSH_REGISTRY/$lfn_umbrella/$name:$VERSION"
392             if [[ "$JOB_NAME" =~ "merge" ]]; then
393                 docker tag "$container_image_id" "$CONTAINER_PUSH_REGISTRY"/"$lfn_umbrella"/"$name":"$VERSION"
394                 docker push "$CONTAINER_PUSH_REGISTRY"/"$lfn_umbrella"/"$name":"$VERSION"
395             fi
396             echo "#########################"
397         fi
398     done
399
400     echo "INFO: Merge will tag ref: $ref"
401     git checkout "$ref"
402     tag-git-repo
403 }
404
405 maven_release_file(){
406     echo "INFO: Processing maven release"
407     echo "INFO: wget -P $PATCH_DIR ${logs_url}/staging-repo.txt.gz"
408     wget -P "$PATCH_DIR" "${logs_url}/"staging-repo.txt.gz
409     pushd "$PATCH_DIR"
410         echo "INFO: wget ${logs_url}/patches/{${PROJECT//\//-}.bundle,taglist.log.gz}"
411         wget "${logs_url}"/patches/{"${PROJECT//\//-}".bundle,taglist.log.gz}
412         gunzip taglist.log.gz
413         cat "$PATCH_DIR"/taglist.log
414     popd
415     git checkout "$(awk '{print $NF}' "$PATCH_DIR/taglist.log")"
416     git fetch "$PATCH_DIR/${PROJECT//\//-}.bundle"
417     git merge --ff-only FETCH_HEAD
418     nexus_release
419     tag-git-repo
420 }
421
422 # calls pip to download binary and source distributions from the specified index,
423 # which requires a recent-in-2019 version.  Uploads the files it received.
424 pypi_release_file(){
425     echo "INFO: Processing pypi release"
426     tgtdir=dist
427     mkdir $tgtdir
428     pip_pfx="pip download -d $tgtdir --no-deps --python-version $PYTHON_VERSION -i $PYPI_INDEX"
429     module="$PYPI_PROJECT==$VERSION"
430     pip_bin="$pip_pfx $module"
431     echo "INFO: downloading binary: $pip_bin"
432     if ! $pip_bin ; then
433         echo "WARN: failed to download binary distribution"
434     fi
435     pip_src="$pip_pfx --no-binary=:all: $module"
436     echo "INFO: downloading source: $pip_src"
437     if ! $pip_src ; then
438         echo "WARN: failed to download source distribution"
439     fi
440     echo "INFO: Checking files in $tgtdir"
441     # shellcheck disable=SC2012
442     filecount=$(ls $tgtdir | wc -l)
443     if [[ $filecount = 0 ]] ; then
444         echo "ERROR: no files downloaded"
445         exit 1
446     else
447         # shellcheck disable=SC2046
448         echo "INFO: downloaded $filecount distributions: " $(ls $tgtdir)
449     fi
450
451     if [[ ! "$JOB_NAME" =~ "merge" ]] ; then
452         echo "INFO: not a merge job, not uploading files"
453         return
454     fi
455
456     cmd="twine upload -r $REPOSITORY $tgtdir/*"
457     if $DRY_RUN; then
458         echo "INFO: dry-run is set, echoing command only"
459         echo "$cmd"
460     else
461         echo "INFO: uploading $filecount distributions to repo $REPOSITORY"
462         $cmd
463     fi
464     tag-git-repo
465 }
466
467 packagecloud_verify(){
468     echo "INFO: Verifying $1 exists in staging..."
469     if [[ $1 == $(curl --netrc-file ~/packagecloud_api --silent \
470         https://packagecloud.io/api/v1/repos/"$2"/staging/search?q="$1" \
471         | yq -r .[].filename) ]]; then
472         echo "INFO: $1 exists in staging!"
473         echo "INFO: Existing package location: https://packagecloud.io$(curl \
474             --netrc-file ~/packagecloud_api --silent \
475             https://packagecloud.io/api/v1/repos/"$2"/staging/search?q="$1" \
476             | yq -r .[].package_html_url)"
477     else
478         echo "ERROR: $1 does not exist in staging"
479         exit 1
480     fi
481 }
482
483 packagecloud_promote(){
484     echo "INFO: Preparing to promote $1..."
485     promote_url="https://packagecloud.io$(curl --netrc-file ~/packagecloud_api \
486         --silent https://packagecloud.io/api/v1/repos/"$2"/staging/search?q="$1" \
487         | yq -r .[].promote_url)"
488     echo "INFO: Promoting $1 from staging to release"
489     curl --netrc-file ~/packagecloud_api -X POST -F \
490         destination="$2/release" "$promote_url" \
491         | echo "INFO: Promoted package location: \
492         https://packagecloud.io$(yq -r .package_html_url)"
493     git checkout "$REF"
494     tag-git-repo
495 }
496
497 ##############################  End Function Declarations  ################################
498
499 # Set common environment variables
500 set_variables_common
501
502 # Determine the type of release:
503 #   - container, release-container-schema.yaml
504 #   - maven, release-schema.yaml
505 #   - pypi,  release-pypi-schema.yaml
506
507 case $DISTRIBUTION_TYPE in
508
509     maven)
510         if $USE_RELEASE_FILE ; then
511             release_schema="release-schema.yaml"
512             echo "INFO: Fetching schema $release_schema"
513             wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/$release_schema
514             verify_schema
515         fi
516         set_variables_maven
517         verify_version
518         verify_version_match_release
519         maven_release_file
520         ;;
521
522     container)
523         if $USE_RELEASE_FILE ; then
524             release_schema="release-container-schema.yaml"
525             echo "INFO: Fetching schema $release_schema"
526             wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${release_schema}
527             verify_schema
528         fi
529         set_variables_container
530         verify_version
531         container_release_file
532         ;;
533
534     pypi)
535         if $USE_RELEASE_FILE ; then
536             release_schema="release-pypi-schema.yaml"
537             echo "INFO: Fetching schema $release_schema"
538             wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${release_schema}
539             verify_schema
540         fi
541         set_variables_pypi
542         verify_version
543         verify_pypi_match_release
544         pypi_release_file
545         ;;
546
547     packagecloud)
548         if $USE_RELEASE_FILE ; then
549             release_schema="release-packagecloud-schema.yaml"
550             packagecloud_account=$(cat "$ACCOUNT_NAME_FILE")
551             echo "INFO: Fetching schema $release_schema"
552             wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${release_schema}
553             verify_schema
554         fi
555         set_variables_packagecloud
556         verify_packagecloud_match_release
557         for name in $(yq -r '.packages[].name' $release_file); do
558             package=$name
559             packagecloud_verify "$package" "$packagecloud_account"
560             if [[ "$JOB_NAME" =~ "merge" ]] && ! $DRY_RUN; then
561                 packagecloud_promote "$package" "$packagecloud_account"
562             fi
563         done
564         ;;
565
566     *)
567         echo "ERROR: distribution_type: $DISTRIBUTION_TYPE not supported"
568         exit 1
569         ;;
570 esac
571
572 echo "---> release-job.sh ends"