Skip to content

Commit

Permalink
ci: scripts for release
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Apr 24, 2020
1 parent 2214d9d commit a7ebe81
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 81 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
126 changes: 126 additions & 0 deletions scripts/changelog.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -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)
}
75 changes: 0 additions & 75 deletions scripts/extract-changelog-for-version.sh

This file was deleted.

6 changes: 1 addition & 5 deletions scripts/quickstarts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
113 changes: 113 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -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
#
# '''
# }
# }
# }
# }
#}

0 comments on commit a7ebe81

Please sign in to comment.