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