From a7ebe81361a5d6a13a1d548dd8fb9c5aca6edb82 Mon Sep 17 00:00:00 2001 From: manusa Date: Fri, 6 Mar 2020 16:11:23 +0100 Subject: [PATCH] ci: scripts for release Signed-off-by: Marc Nuri --- CHANGELOG.md | 2 +- scripts/changelog.sh | 126 +++++++++++++++++++++++ scripts/common.sh | 20 ++++ scripts/extract-changelog-for-version.sh | 75 -------------- scripts/quickstarts.sh | 6 +- scripts/release.sh | 113 ++++++++++++++++++++ 6 files changed, 261 insertions(+), 81 deletions(-) create mode 100755 scripts/changelog.sh create mode 100755 scripts/common.sh delete mode 100755 scripts/extract-changelog-for-version.sh create mode 100755 scripts/release.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d6ce7406..6e34fbed48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ We provide a script to extract changelog portions and automatic link building to Usage: ``` -# ./scripts/extract-changelog-for-version.sh semanticVersionNumber [linkLabelStartNumber] +# ./scripts/changelog.sh semanticVersionNumber [linkLabelStartNumber] ./scripts/extract-changelog-for-version.sh 1.3.37 5 ``` ### 1.0.0-SNAPSHOT diff --git a/scripts/changelog.sh b/scripts/changelog.sh new file mode 100755 index 0000000000..67edbbae36 --- /dev/null +++ b/scripts/changelog.sh @@ -0,0 +1,126 @@ +#!/bin/bash +# +# Copyright (c) 2019 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at: +# +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# + +trap 'exit' ERR + +START_LINK=10 +BASEDIR=$(dirname "$BASH_SOURCE") + +function help() { + cat <<-END +Utility script for CHANGELOG.md + +Available functions: + - extract: Extracts the changelog for a given version + Usage: ./changelog.sh extract semVer + Example: ./changelog.sh extract 4.9.0 + - extractWithLinks: Extracts the changelog for a given version and appends links to the referenced issues + Usage: ./changelog.sh extractWithLinks semVer [startLinkNumber] + Example: ./changelog.sh extractWithLinks 4.9.0 1 + - emailTemplate: Prepares an e-mail for the release announcement + Usage: ./changelog.sh emailTemplate semVer + Example: ./changelog.sh emailTemplate 4.9.0 +END +} + +function checkInput() { + if [ "$#" -lt 1 ]; then + help + exit 1; + fi + dotCount=$(echo "$1" | tr -d -c '.' | wc -c) + if [ "$dotCount" -ne 2 ]; then + echo "Provided version has an invalid format, should be semver compliant (e.g. 1.3.37)" + exit 1; + fi +} + +function extractChangelogPortion() { + sed -e "/^### ""$1""/,/^### /!d" "$BASEDIR/../CHANGELOG.md" +} + +function removeLastLine() { + echo "$1" | sed '$d' +} + +function replaceBullets() { + echo -e "$1" | sed -e "s/^*/-/" +} + +function addLinks() { + lines="" + links="" + currentLink="$START_LINK" + if [ -n "$2" ]; then currentLink="$2" ; fi + while read -r line; do + issueNumber=$(echo "$line" | sed -En 's/.*?#([0-9]+).*/\1/p') + if [ -z "$issueNumber" ]; then + lines+="$line\n"; + else + lines+="$line [$currentLink]\n" + links+="[$currentLink] https://github.com/eclipse/jkube/issues/$issueNumber\n" + currentLink=$((currentLink + 1)); + fi + done < <(echo "$1") + echo -e "$lines\n$links"; +} + +function extract() { + checkInput "$@" + changelog=$1 + changelog=$(extractChangelogPortion "$changelog") + changelog=$(removeLastLine "$changelog") + changelog=$(replaceBullets "$changelog") + echo "$changelog" +} + +function extractWithLinks() { + changelog=$(extract "$@") + changelog=$(addLinks "$changelog" "$2") + echo "$changelog"; +} + +function emailTemplate() { + checkInput "$@" + changelog=$(extract "$@") + changelogWithLinks=$(addLinks "$changelog" 2) + numberedChangelog=$(echo -e "$changelogWithLinks" | sed '/^$/d' | sed '/^#/d' | sed -E '/^\[[0-9]+\]/d') + changelogLinks=$(echo -e "$changelogWithLinks" | sed '/^$/d' | sed '/^#/d' | sed -E '/^\[[0-9]+\]/!d') + changelogLinksCount=$(echo -e "$changelogLinks" | wc -l) + githubLinkId="["$((changelogLinksCount + 2))"]" + gitterLinkId="["$((changelogLinksCount + 3))"]" + lines="Release announcement for Eclipse JKube $1\n\n" + lines+="Hi All,\n\n" + lines+="We are pleased to announce Eclipse JKube $1 was just released. You can find the release at Maven Central [1].\n\n" + lines+="These are the features and fixes included in $1:\n" + lines+="$numberedChangelog\n\n" + lines+="Your feedback is highly appreciated, you can provide it replying to the mailing list or through the usual channels. $githubLinkId $gitterLinkId\n\n" + lines+="[1] https://repo1.maven.org/maven2/org/eclipse/jkube/kubernetes-maven-plugin/$1/\n" + lines+="$changelogLinks\n" + lines+="$githubLinkId https://github.com/eclipse/jkube\n" + lines+="$gitterLinkId https://gitter.im/eclipse/jkube\n" + echo -e "$lines" +} + +if declare -f "$1" > /dev/null ; then + "$@" +elif [ -z "$1" ]; then + echo "Please specify a function name" >&2 + help +else + echo "'$1' is not a known function name" >&2 + help + exit 1 +fi diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100755 index 0000000000..5153aff2c4 --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Copyright (c) 2019 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at: +# +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# + +PROJECT_ROOT="$BASEDIR/.." + +function getJKubeVersion() { + echo $(mvn -f "$PROJECT_ROOT/pom.xml" -q -Dexec.executable=echo -Dexec.args=\${project.version} --non-recursive exec:exec) +} diff --git a/scripts/extract-changelog-for-version.sh b/scripts/extract-changelog-for-version.sh deleted file mode 100755 index 84844331b1..0000000000 --- a/scripts/extract-changelog-for-version.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2019 Red Hat, Inc. -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at: -# -# https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# -# Contributors: -# Red Hat, Inc. - initial API and implementation -# - -trap 'exit' ERR - -START_LINK=10 -BASEDIR=$(dirname "$BASH_SOURCE") - -function checkInput() { - if [ "$#" -lt 1 ]; then - echo -e "This script extracts chagnelog version contents from CHANGELOG.md" - echo -e "Usage: ./extract-changelog-for-version.sh semVer [startLinkNumber]\n" - echo -e "Must set a valid semantic version number (e.g. 1.3.37)" - exit 1; - fi - dotCount=$(echo "$1" | tr -d -c '.' | wc -c) - if [ "$dotCount" -ne 2 ]; then - echo "Provided version has an invalid format, should be semver compliant (e.g. 1.3.37)" - exit 1; - fi -} - -function extractChangelogPortion() { - sed -e "/### ""$1""/,/###/!d" "$BASEDIR/../CHANGELOG.md" -} - -function removeLastLine() { - echo "$1" | sed '$d' -} - -function replaceBullets() { - echo -e "$1" | sed -e "s/^*/-/" -} - -function addLinks() { - lines="" - links="" - currentLink="$START_LINK" - if [ -n "$2" ]; then currentLink="$2" ; fi - while read -r line; do - issueNumber=$(echo "$line" | sed -En 's/.*?#([0-9]+).*/\1/p') - if [ -z "$issueNumber" ]; then - lines+="$line\n"; - else - lines+="$line [$currentLink]\n" - links+="[$currentLink]: https://github.com/eclipse/jkube/issues/$issueNumber\n" - currentLink=$((currentLink + 1)); - fi - done < <(echo "$1") - echo -e "$lines\n$links"; -} - -function processChangelog() { - changelog=$1 - changelog=$(extractChangelogPortion "$changelog") - changelog=$(removeLastLine "$changelog") - changelog=$(replaceBullets "$changelog") - changelog=$(addLinks "$changelog" "$2") - echo "$changelog"; -} - -checkInput "$@" -processChangelog "$@" diff --git a/scripts/quickstarts.sh b/scripts/quickstarts.sh index 72876cbabc..3ab27bfd43 100755 --- a/scripts/quickstarts.sh +++ b/scripts/quickstarts.sh @@ -16,13 +16,9 @@ trap 'exit' ERR BASEDIR=$(dirname "$BASH_SOURCE") -PROJECT_ROOT="$BASEDIR/.." +source "$BASEDIR/common.sh" QUICKSTARTS="$PROJECT_ROOT/quickstarts" -function getJKubeVersion() { - echo $(mvn -f "$PROJECT_ROOT/pom.xml" -q -Dexec.executable=echo -Dexec.args=\${project.version} --non-recursive exec:exec) -} - function version() { JKUBE_VERSION=$(getJKubeVersion) echo "Updating quickstarts pom files to JKube $JKUBE_VERSION" diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000000..c4ec12b172 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# +# Copyright (c) 2019 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at: +# +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# + +trap 'exit' ERR + +BASEDIR=$(dirname "$BASH_SOURCE") + +source "$BASEDIR/common.sh" + +function calculateReleaseVersion() { + PROJECT_VERSION=$(getJKubeVersion) + echo $PROJECT_VERSION | sed 's/-SNAPSHOT//g' +} + +function calculateNextSnapshotVersion() { + if [ -z "$1" ]; then + echo "Error calculating next snapshot version, missing current version" + fi + CURRENT_VERSION=$1 + MAJOR_VERSION=$(echo $CURRENT_VERSION | cut -d. -f1) + MINOR_VERSION=$(echo $CURRENT_VERSION | cut -d. -f2) + PATCH_VERSION=$(echo $CURRENT_VERSION | cut -d. -f3) + NEW_PATCH_VERSION=$(($PATCH_VERSION + 1)) + echo "$MAJOR_VERSION.$MINOR_VERSION.$NEW_PATCH_VERSION-SNAPSHOT" + +} + +function setReleaseVersion() { + RELEASE_VERSION=$(calculateReleaseVersion) + echo "Setting release version for project to $RELEASE_VERSION" + mvn -f "$PROJECT_ROOT/pom.xml" versions:set -DnewVersion="$RELEASE_VERSION" -DgenerateBackupPoms=false +} + +if declare -f "$1" > /dev/null ; then + "$@" +elif [ -z "$1" ]; then + echo "Please specify a function name" >&2 +else + echo "'$1' is not a known function name" >&2 + exit 1 +fi + +##!groovy +# +#pipeline { +# agent any +# tools { +# maven 'apache-maven-latest' +# jdk 'adoptopenjdk-hotspot-jdk8-latest' +# } +# stages { +# stage('Build') { +# steps { +# withCredentials([file(credentialsId: 'secret-subkeys.asc', variable: 'KEYRING')]) { +# sh 'gpg --batch --import "${KEYRING}"' +# sh 'for fpr in $(gpg --list-keys --with-colons | awk -F: \'/fpr:/ {print $10}\' | sort -u); do echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key ${fpr} trust; done' +# } +# sshagent (['github-bot-ssh']) { +# sh ''' +# +# +# # Find Project release version +# PROJECT_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) +# NEXT_RELEASE_VERSION=`echo $PROJECT_VERSION | sed 's/-SNAPSHOT//g'` +# if [ ${#NEXT_RELEASE_VERSION} -eq 3 ]; then +# NEXT_RELEASE_VERSION=`echo "$NEXT_RELEASE_VERSION.0"` +# fi +# +# echo "Releasing project with version $NEXT_RELEASE_VERSION" +# +# # Prepare project for release, modify pom to new release version +# mvn versions:set -DnewVersion=$NEXT_RELEASE_VERSION +# find . -iname *.versionsBackup -exec rm {} + +# git add . && git commit -m "[RELEASE] Modified Project pom version to $NEXT_RELEASE_VERSION" +# #git tag $NEXT_RELEASE_VERSION +# #git push origin $NEXT_RELEASE_VERSION +# #git push origin master +# +# mvn clean -B +# mvn -V -B -e -U install org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7:deploy -P release -DnexusUrl=https://oss.sonatype.org -DserverId=ossrh +# # read repo_id from *.properties file and set it +# repo_id=$(cat target/nexus-staging/staging/*.properties | grep id | awk -F'=' '{print $2}') +# mvn -B org.sonatype.plugins:nexus-staging-maven-plugin:1.6.5:rc-release -DserverId=ossrh -DnexusUrl=https://oss.sonatype.org -DstagingRepositoryId=${repo_id} -Ddescription=\"Next release is ready\" -DstagingProgressTimeoutMinutes=60 +# +# # Modify poms back to SNAPSHOT VERSIONS +# MAJOR_VERSION=`echo $NEXT_RELEASE_VERSION | cut -d. -f1` +# MINOR_VERSION=`echo $NEXT_RELEASE_VERSION | cut -d. -f2` +# PATCH_VERSION=`echo $NEXT_RELEASE_VERSION | cut -d. -f3` +# PATCH_VERSION=$(($PATCH_VERSION + 1)) +# NEXT_SNAPSHOT_VERSION=`echo "$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION-SNAPSHOT"` +# mvn versions:set -DnewVersion=$NEXT_SNAPSHOT_VERSION +# find . -iname *.versionsBackup -exec rm {} + +# #git add . && git commit -m "[RELEASE] Prepare project for next development iteration $NEXT_SNAPSHOT_VERSION" +# #git push origin master +# +# ''' +# } +# } +# } +# } +#}