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"
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"
25 pip install --user lftools[nexus] jsonschema niet
27 echo "########### Start Script release-job.sh ###################################"
29 LOGS_SERVER="${LOGS_SERVER:-None}"
30 MAVEN_CENTRAL_URL="${MAVEN_CENTRAL_URL:-None}"
32 if [ "${LOGS_SERVER}" == 'None' ]; then
33 echo "FAILED: log server not found"
37 NEXUS_URL="${NEXUSPROXY:-$NEXUS_URL}"
39 # Fetch the release-schema.yaml
40 wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-schema.yaml
42 release_files=$(git diff-tree --no-commit-id -r $GERRIT_PATCHSET_REVISION --name-only -- "releases/")
43 echo "RELEASE FILES ARE AS FOLLOWS: $release_files"
45 if (( $(grep -c . <<<"$release_files") > 1 )); then
46 echo "multiple release files in the same commit do not make sense"
49 release_file="$release_files"
50 echo "RELEASE FILE IS AS FOLLOWS: $release_file"
53 echo "--> Verifying $release_file schema."
54 lftools schema verify $release_file release-schema.yaml
56 VERSION="$(niet ".version" "$release_file")"
57 PROJECT="$(niet ".project" "$release_file")"
58 LOG_DIR="$(niet ".log_dir" "$release_file")"
60 NEXUS_PATH="${SILO}/${JENKINS_HOSTNAME}/"
61 LOGS_URL="${LOGS_SERVER}/${NEXUS_PATH}${LOG_DIR}"
62 PATCH_DIR="$(mktemp -d)"
64 wget --quiet -P "$PATCH_DIR" "${LOGS_URL}"staging-repo.txt.gz
67 for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
68 # extract the domain name from URL
69 NEXUS_URL=$(echo $staging_url | sed -e 's|^[^/]*//||' -e 's|/.*$||')
70 # extract the staging repo from URL
71 STAGING_REPO=${staging_url#*repositories/}
73 echo "lftools nexus release --server https://$NEXUS_URL $STAGING_REPO"
74 if [[ "$JOB_NAME" =~ "merge" ]]; then
75 echo "Promoting $STAGING_REPO on $NEXUS_URL."
76 lftools nexus release --server https://"$NEXUS_URL" "$STAGING_REPO"
84 echo "RELEASE_FILE: $release_file"
85 echo "LOGS_SERVER: $LOGS_SERVER"
86 echo "NEXUS_URL: $NEXUS_URL"
87 echo "NEXUS_PATH: $NEXUS_PATH"
88 echo "NEXUSPROXY: $NEXUSPROXY"
89 echo "JENKINS_HOSTNAME: $JENKINS_HOSTNAME"
91 echo "PROJECT: $PROJECT"
92 echo "VERSION: $VERSION"
93 echo "PROJECT: $PROJECT"
94 echo "LOG DIR: $LOG_DIR"
97 wget --quiet "${LOGS_URL}"/patches/{"${PROJECT}".bundle,taglist.log.gz}
99 cat "$PATCH_DIR"/taglist.log
102 # Verify allowed versions
103 # Allowed versions are "v#.#.#" or "#.#.#" aka SemVer
104 allowed_version_regex="^((v?)([0-9]+)\.([0-9]+)\.([0-9]+))$"
105 if [[ ! $VERSION =~ $allowed_version_regex ]]; then
106 echo "The version $VERSION is not a semantic valid version"
107 echo "Allowed versions are "v#.#.#" or "#.#.#" aka SemVer"
108 echo "See https://semver.org/ for more details on SemVer"
112 git checkout "$(awk '{print $NF}' "$PATCH_DIR/taglist.log")"
113 git fetch "$PATCH_DIR/$PROJECT.bundle"
114 git merge --ff-only FETCH_HEAD
115 git tag -am "$PROJECT $VERSION" "$VERSION"
116 sigul --batch -c "$SIGUL_CONFIG" sign-git-tag "$SIGUL_KEY" "$VERSION" < "$SIGUL_PASSWORD"
118 echo "Showing latest signature for $PROJECT:"
119 gpg --import "$SIGNING_PUBKEY"
120 echo "git tag -v "$VERSION""
121 git tag -v "$VERSION"
123 ########## Merge Part ##############
124 if [[ "$JOB_NAME" =~ "merge" ]]; then
126 gerrit_ssh=$(echo "$GERRIT_URL" | awk -F"/" '{print $3}')
127 git remote set-url origin ssh://"$RELEASE_USERNAME"@"$gerrit_ssh":29418/$PROJECT
128 git config user.name "$RELEASE_USERNAME"
129 git config user.email "$RELEASE_EMAIL"
130 echo -e "Host $gerrit_ssh\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
131 chmod 600 ~/.ssh/config
132 git push origin "$VERSION"
137 # This function: if merge push to nexus. If verify output the proposed push command.
140 echo "########### End Script release-job.sh ###################################"