-for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
- # extract the domain name from URL
- NEXUS_URL=$(echo $staging_url | sed -e 's|^[^/]*//||' -e 's|/.*$||')
- # extract the staging repo from URL
- STAGING_REPO=${staging_url#*repositories/}
- echo "Merge will run"
- echo "lftools nexus release --server https://$NEXUS_URL $STAGING_REPO"
- if [[ "$JOB_NAME" =~ "merge" ]]; then
- echo "Promoting $STAGING_REPO on $NEXUS_URL."
- lftools nexus release --server https://"$NEXUS_URL" "$STAGING_REPO"
- fi
-done
-}
-
-
-#INFO
-echo "INFO:"
-echo "RELEASE_FILE: $release_file"
-echo "LOGS_SERVER: $LOGS_SERVER"
-echo "NEXUS_URL: $NEXUS_URL"
-echo "NEXUS_PATH: $NEXUS_PATH"
-echo "NEXUSPROXY: $NEXUSPROXY"
-echo "JENKINS_HOSTNAME: $JENKINS_HOSTNAME"
-echo "SILO: $SILO"
-echo "PROJECT: $PROJECT"
-echo "PROJECT-DASHED: ${PROJECT//\//-}"
-
-echo "VERSION: $VERSION"
-echo "LOG DIR: $LOG_DIR"
-
-pushd "$PATCH_DIR"
- echo "wget "${LOGS_URL}"/patches/{"${PROJECT//\//-}".bundle,taglist.log.gz}"
- wget "${LOGS_URL}"/patches/{"${PROJECT//\//-}".bundle,taglist.log.gz}
- gunzip taglist.log.gz
- cat "$PATCH_DIR"/taglist.log
-popd
-
-# Verify allowed versions
-# Allowed versions are "v#.#.#" or "#.#.#" aka SemVer
-allowed_version_regex="^((v?)([0-9]+)\.([0-9]+)\.([0-9]+))$"
-if [[ ! $VERSION =~ $allowed_version_regex ]]; then
- echo "The version $VERSION is not a semantic valid version"
- echo "Allowed versions are "v#.#.#" or "#.#.#" aka SemVer"
- echo "See https://semver.org/ for more details on SemVer"
- exit 1
-fi
-
-if git tag -v "$VERSION"; then
- echo "Repo already tagged $VERSION"
- echo "This job has already run exit 0"
- exit 0
-fi
-
-git checkout "$(awk '{print $NF}' "$PATCH_DIR/taglist.log")"
-git fetch "$PATCH_DIR/${PROJECT//\//-}.bundle"
-git merge --ff-only FETCH_HEAD
-git tag -am "${PROJECT//\//-} $VERSION" "$VERSION"
-sigul --batch -c "$SIGUL_CONFIG" sign-git-tag "$SIGUL_KEY" "$VERSION" < "$SIGUL_PASSWORD"
-
-echo "Showing latest signature for $PROJECT:"
-gpg --import "$SIGNING_PUBKEY"
-echo "git tag -v "$VERSION""
-git tag -v "$VERSION"
-
-########## Merge Part ##############
-if [[ "$JOB_NAME" =~ "merge" ]]; then
- echo "Running merge"
- gerrit_ssh=$(echo "$GERRIT_URL" | awk -F"/" '{print $3}')
- git remote set-url origin ssh://"$RELEASE_USERNAME"@"$gerrit_ssh":29418/"$PROJECT"
- git config user.name "$RELEASE_USERNAME"
- git config user.email "$RELEASE_EMAIL"
- echo -e "Host $gerrit_ssh\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- chmod 600 ~/.ssh/config
- git push origin "$VERSION"
-
-
-fi
-
-# This function: if merge push to nexus. If verify output the proposed push command.
-nexus_release
-#
-#echo "########### End Script release-job.sh ###################################"
+ echo "INFO: Processing nexus release"
+ for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
+ # extract the domain name from URL
+ NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
+ echo "INFO: NEXUS_URL: $NEXUS_URL"
+ # extract the staging repo from URL
+ STAGING_REPO=${staging_url#*repositories/}
+ echo "INFO: Running Nexus Verify"
+ lftools nexus release -v --server https://"$NEXUS_URL" "$STAGING_REPO"
+ echo "INFO: Merge will run:"
+ echo "lftools nexus release --server https://$NEXUS_URL $STAGING_REPO"
+ done
+
+ #Run the loop twice, to catch errors on either nexus repo
+ if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
+ for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
+ NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
+ STAGING_REPO=${staging_url#*repositories/}
+ echo "INFO: Promoting $STAGING_REPO on $NEXUS_URL."
+ lftools nexus release --server https://"$NEXUS_URL" "$STAGING_REPO"
+ done
+ fi
+}
+
+packagecloud_promote(){
+ echo "INFO: Preparing to promote $1..."
+ promote_url="https://packagecloud.io$(curl --netrc-file ~/packagecloud_api \
+ --silent https://packagecloud.io/api/v1/repos/"$2"/staging/search?q="$1" \
+ | yq -r .[].promote_url)"
+ echo "INFO: Promoting $1 from staging to release"
+ curl --netrc-file ~/packagecloud_api -X POST -F \
+ destination="$2/release" "$promote_url" \
+ | echo "INFO: Promoted package location: \
+ https://packagecloud.io$(yq -r .package_html_url)"
+ git checkout "$REF"
+ tag-git-repo
+}
+
+packagecloud_verify(){
+ echo "INFO: Verifying $1 exists in staging..."
+ if [[ $1 == $(curl --netrc-file ~/packagecloud_api --silent \
+ https://packagecloud.io/api/v1/repos/"$2"/staging/search?q="$1" \
+ | yq -r .[].filename) ]]; then
+ echo "INFO: $1 exists in staging!"
+ echo "INFO: Existing package location: https://packagecloud.io$(curl \
+ --netrc-file ~/packagecloud_api --silent \
+ https://packagecloud.io/api/v1/repos/"$2"/staging/search?q="$1" \
+ | yq -r .[].package_html_url)"
+ else
+ echo "ERROR: $1 does not exist in staging"
+ exit 1
+ fi
+}
+
+# calls pip to download binary and source distributions from the specified index,
+# which requires a recent-in-2019 version. Uploads the files it received.
+pypi_release_file(){
+ echo "INFO: Processing pypi release"
+ tgtdir=dist
+ mkdir $tgtdir
+ pip_pfx="pip download -d $tgtdir --no-deps --python-version $PYTHON_VERSION -i $PYPI_INDEX"
+ module="$PYPI_PROJECT==$VERSION"
+ pip_bin="$pip_pfx $module"
+ echo "INFO: downloading binary: $pip_bin"
+ if ! $pip_bin ; then
+ echo "WARN: failed to download binary distribution"
+ fi
+ pip_src="$pip_pfx --no-binary=:all: $module"
+ echo "INFO: downloading source: $pip_src"
+ if ! $pip_src ; then
+ echo "WARN: failed to download source distribution"
+ fi
+ echo "INFO: Checking files in $tgtdir"
+ # shellcheck disable=SC2012
+ filecount=$(ls $tgtdir | wc -l)
+ if [[ $filecount = 0 ]] ; then
+ echo "ERROR: no files downloaded"
+ exit 1
+ else
+ # shellcheck disable=SC2046
+ echo "INFO: downloaded $filecount distributions: " $(ls $tgtdir)
+ fi
+
+ if [[ ! "$JOB_NAME" =~ "merge" ]] ; then
+ echo "INFO: not a merge job, not uploading files"
+ return
+ fi
+
+ cmd="twine upload -r $REPOSITORY $tgtdir/*"
+ if $DRY_RUN; then
+ echo "INFO: dry-run is set, echoing command only"
+ echo "$cmd"
+ else
+ echo "INFO: uploading $filecount distributions to repo $REPOSITORY"
+ $cmd
+ fi
+ tag-git-repo
+}
+
+############################## End Function Declarations ################################
+
+# Set common environment variables
+set_variables_common
+
+# Determine the type of release:
+# - artifact, release-artifact-schema.yaml
+# - container, release-container-schema.yaml
+# - maven, release-schema.yaml
+# - packagecloud, release-packagecloud-schema.yaml
+# - pypi, release-pypi-schema.yaml
+
+case $DISTRIBUTION_TYPE in
+
+ artifact)
+ if $USE_RELEASE_FILE ; then
+ release_schema="release-artifact-schema.yaml"
+ echo "INFO: Fetching schema $release_schema"
+ wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${release_schema}
+ verify_schema
+ fi
+ set_variables_artifact
+ verify_version
+ artifact_release_file
+ ;;
+
+ container)
+ if $USE_RELEASE_FILE ; then
+ release_schema="release-container-schema.yaml"
+ echo "INFO: Fetching schema $release_schema"
+ wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${release_schema}
+ verify_schema
+ fi
+ set_variables_container
+ verify_version
+ container_release_file
+ ;;
+
+ maven)
+ if $USE_RELEASE_FILE ; then
+ release_schema="release-schema.yaml"
+ echo "INFO: Fetching schema $release_schema"
+ wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/$release_schema
+ verify_schema
+ fi
+ set_variables_maven
+ verify_version
+ verify_version_match_release
+ maven_release_file
+ ;;
+
+ packagecloud)
+ if $USE_RELEASE_FILE ; then
+ release_schema="release-packagecloud-schema.yaml"
+ packagecloud_account=$(cat "$ACCOUNT_NAME_FILE")
+ echo "INFO: Fetching schema $release_schema"
+ wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${release_schema}
+ verify_schema
+ fi
+ set_variables_packagecloud
+ verify_packagecloud_match_release
+ for name in $(yq -r '.packages[].name' "$release_file"); do
+ package=$name
+ packagecloud_verify "$package" "$packagecloud_account"
+ if [[ "$JOB_NAME" =~ "merge" ]] && ! $DRY_RUN; then
+ packagecloud_promote "$package" "$packagecloud_account"
+ fi
+ done
+ ;;
+
+ pypi)
+ if $USE_RELEASE_FILE ; then
+ release_schema="release-pypi-schema.yaml"
+ echo "INFO: Fetching schema $release_schema"
+ wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${release_schema}
+ verify_schema
+ fi
+ set_variables_pypi
+ verify_version
+ verify_pypi_match_release
+ pypi_release_file
+ ;;
+
+ *)
+ echo "ERROR: distribution_type: $DISTRIBUTION_TYPE not supported"
+ exit 1
+ ;;
+esac
+
+echo "---> release-job.sh ends"