From: Aric Gardner Date: Fri, 23 Aug 2019 00:02:05 +0000 (-0700) Subject: Allow Build with Params releases X-Git-Tag: v0.42.0~6^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=9b6adc3de515a9388baad51acc33feb74a12d64a;p=releng%2Fglobal-jjb.git Allow Build with Params releases Add support for "Build with Parameters" for projects that do not want to use a release file for maven builds. Restructure shell/release-job.sh into functions. Change-Id: Iada9c9a50710c24fbfe87b2ea0def10f3dd04bd7 Authored-By: Aric Gardner Signed-off-by: Jessica Wagantall --- diff --git a/docs/jjb/lf-macros.rst b/docs/jjb/lf-macros.rst index 32aa2be3..cfc92298 100644 --- a/docs/jjb/lf-macros.rst +++ b/docs/jjb/lf-macros.rst @@ -327,6 +327,12 @@ lf-infra-tox-parameters Provides parameters needed by python-tox. Should be used by any jobs that need to run `tox `. + +lf-build-with-parameters-maven-release +-------------------------------------- + +Provides parameters needed for maven release jobs 'build with parameters'. + Properties ========== diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index ca7d478d..baf50195 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -475,6 +475,26 @@ Tox environments to run build against. Example: docs,py2,py3 +- parameter: + name: lf-build-with-parameters-maven-release + parameters: + - string: + name: VERSION + default: "" + description: "This is the tag, Example: 1.0.0" + - string: + name: LOG_DIR + default: "" + description: "Log dir, example: project-maven-stage-master/17/" + - string: + name: DISTRIBUTION_TYPE + default: "" + description: "Set to maven for build with parametes" + - bool: + name: RELEASE_FILE + default: "{use-release-file}" + description: "Set to False for job built with parameters" + ############## # PROPERTIES # ############## diff --git a/jjb/lf-release-jobs.yaml b/jjb/lf-release-jobs.yaml index 657c7014..29deacaf 100644 --- a/jjb/lf-release-jobs.yaml +++ b/jjb/lf-release-jobs.yaml @@ -30,6 +30,8 @@ project: "{project}" branch: "$GERRIT_BRANCH" stream: "$GERRIT_BRANCH" + - lf-build-with-parameters-maven-release: + use-release-file: "{use-release-file}" publishers: - lf-infra-publish @@ -50,6 +52,7 @@ disable-job: false git-url: "$GIT_URL/$PROJECT" gerrit-skip-vote: false + use-release-file: true gerrit_verify_triggers: - patchset-created-event: @@ -139,6 +142,7 @@ build-timeout: 15 disable-job: false git-url: "$GIT_URL/$PROJECT" + use-release-file: true gerrit_merge_triggers: - change-merged-event diff --git a/releasenotes/notes/release-job-with-params-84e851b4e0c4cdbe.yaml b/releasenotes/notes/release-job-with-params-84e851b4e0c4cdbe.yaml new file mode 100644 index 00000000..d6c96aa3 --- /dev/null +++ b/releasenotes/notes/release-job-with-params-84e851b4e0c4cdbe.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Add support for "Build with Parameters" for projects + that do not want to use a release file for maven builds. +fixes: + - | + Restructure shell/release-job.sh into functions. diff --git a/shell/release-job.sh b/shell/release-job.sh index 7c572cd7..31721d11 100644 --- a/shell/release-job.sh +++ b/shell/release-job.sh @@ -9,9 +9,9 @@ # http://www.eclipse.org/legal/epl-v10.html ############################################################################## echo "---> release-job.sh" - set -eu -o pipefail +#Python bits. Remove when centos 7.7 builder is avaliable. if [ -d "/opt/pyenv" ]; then echo "---> Setting up pyenv" export PYENV_ROOT="/opt/pyenv" @@ -21,129 +21,171 @@ PYTHONPATH=$(pwd) export PYTHONPATH pyenv local 3.6.4 export PYENV_VERSION="3.6.4" +pip install --user lftools[nexus] jsonschema niet yq + +#Functions. +verify_schema(){ + echo "---> INFO: Verifying $release_file schema." + lftools schema verify "$release_file" "$RELEASE_SCHEMA" + # 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 +} + +tag(){ + if git tag -v "$VERSION"; then + echo "---> OK: Repo already tagged $VERSION Continuting to release" + else + + echo "---> INFO: Repo has not yet been tagged $VERSION" + 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 "--> INFO: 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 + fi +} + +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 "Running Nexus Verify" + lftools nexus release -v --server https://"$NEXUS_URL" "$STAGING_REPO" + 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 +} -pip install --user lftools[nexus] jsonschema niet +container_release_file(){ + echo "---> Processing container release" + # Container-release code is addressed in a new feature patchset. +} + +maven_release_file(){ + echo "---> INFO: wget -P $PATCH_DIR ${LOGS_URL}/staging-repo.txt.gz" + wget -P "$PATCH_DIR" "${LOGS_URL}/"staging-repo.txt.gz + pushd "$PATCH_DIR" + echo "---> INFO: 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 + git checkout "$(awk '{print $NF}' "$PATCH_DIR/taglist.log")" + git fetch "$PATCH_DIR/${PROJECT//\//-}.bundle" + git merge --ff-only FETCH_HEAD + nexus_release + tag +} echo "########### Start Script release-job.sh ###################################" +echo "---> INFO: Setting all VARS" LOGS_SERVER="${LOGS_SERVER:-None}" MAVEN_CENTRAL_URL="${MAVEN_CENTRAL_URL:-None}" - if [ "${LOGS_SERVER}" == 'None' ]; then echo "FAILED: log server not found" exit 1 fi -NEXUSPROXY="${NEXUSPROXY:-None}" -NEXUS_URL="${NEXUSPROXY:-$NEXUS_URL}" - -# Fetch the release-schema.yaml -wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-schema.yaml +RELEASE_FILE="${RELEASE_FILE:-True}" +if [[ "$RELEASE_FILE" == "True" ]]; then -release_files=$(git diff-tree --no-commit-id -r "$GERRIT_PATCHSET_REVISION" --name-only -- "releases/") -echo "RELEASE FILES ARE AS FOLLOWS: $release_files" + release_files=$(git diff-tree --no-commit-id -r "$GERRIT_PATCHSET_REVISION" --name-only -- "releases/" ".releases/") + if (( $(grep -c . <<<"$release_files") > 1 )); then + echo "---> INFO: RELEASE FILES ARE AS FOLLOWS: $release_files" + echo "---> ERROR: Committing multiple release files in the same commit OR rename/amend of existing files is not supported." + exit 1 + else + release_file="$release_files" + echo "---> INFO: RELEASE FILE: $release_files" + fi -if (( $(grep -c . <<<"$release_files") > 1 )); then - echo "multiple release files in the same commit do not make sense" - exit 1 else - release_file="$release_files" - echo "RELEASE FILE IS AS FOLLOWS: $release_file" + echo "This is job is built with parameters, no release file needed" + release_file="None" fi -echo "--> Verifying $release_file schema." -lftools schema verify "$release_file" release-schema.yaml -VERSION="$(niet ".version" "$release_file")" -LOG_DIR="$(niet ".log_dir" "$release_file")" NEXUS_PATH="${SILO}/${JENKINS_HOSTNAME}/" -LOGS_URL="${LOGS_SERVER}/${NEXUS_PATH}${LOG_DIR}" -PATCH_DIR="$(mktemp -d)" -LOGS_URL=${LOGS_URL%/} # strip any trailing '/' -echo "wget -P $PATCH_DIR ${LOGS_URL}/staging-repo.txt.gz" -wget -P "$PATCH_DIR" "${LOGS_URL}/"staging-repo.txt.gz +VERSION="${VERSION:-None}" +if [[ $VERSION == "None" ]]; then + VERSION="$(niet ".version" "$release_file")" +fi -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|/.*$||') - # 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 -} +LOG_DIR="${LOG_DIR:-None}" +if [[ $LOG_DIR == "None" ]]; then + LOG_DIR="$(niet ".log_dir" "$release_file")" +fi +DISTRIBUTION_TYPE="${DISTRIBUTION_TYPE:-None}" +if [[ $DISTRIBUTION_TYPE == "None" ]]; then + DISTRIBUTION_TYPE="$(niet ".distribution_type" "$release_file")" +fi +#### +LOGS_URL="${LOGS_SERVER}/${NEXUS_PATH}${LOG_DIR}" +LOGS_URL=${LOGS_URL%/} # strip any trailing '/' +PATCH_DIR="$(mktemp -d)" #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" +echo "LOGS URL: $LOGS_URL" +echo "DISTRIBUTION_TYPE: $DISTRIBUTION_TYPE" +#Check if this is a container or maven release: release-container-schema.yaml vs release-schema.yaml + +#Logic to determine what we are releasing. +########################################## +if [[ "$DISTRIBUTION_TYPE" == "maven" ]]; then + wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-schema.yaml + RELEASE_SCHEMA="release-schema.yaml" + if [[ "$RELEASE_FILE" == "True" ]]; then + verify_schema + fi + maven_release_file +elif [[ "$DISTRIBUTION_TYPE" == "container" ]]; then + # Container-release code is addressed in a new feature patchset. + container_release_file +else + echo "---> ERROR: distribution_type: $DISTRIBUTION_TYPE not supported" + echo "Must be maven or container" 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" - +echo "########### End Script release-job.sh ###################################" -fi - -# This function: if merge push to nexus. If verify output the proposed push command. -nexus_release -# -#echo "########### End Script release-job.sh ###################################"