Skip to content

Commit

Permalink
ci: automate PR for sdk version bump (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
efgpinto authored Oct 17, 2022
1 parent 847696c commit 2add3cf
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 17 deletions.
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: 2.1

orbs:
build-tools: circleci/[email protected]
github-cli: circleci/[email protected]

commands:
checkout-and-merge-to-main:
Expand Down Expand Up @@ -216,6 +217,31 @@ jobs:
make -C docs validate-links
- save_deps_cache

create-pr-sdk-versions-update:
docker:
- image: circleci/openjdk:11
steps:
- github-cli/setup
- checkout
- restore_deps_cache
- setup_sbt
- set-sdk-version
- run:
name: Create PR to update all sdk versions (samples, sbt and maven)
command: |
chmod +x ./updateSdkVersions.sh
bash ./updateSdkVersions.sh all
BRANCH=bump-sdk-versions-$SDK_VERSION
git checkout -b $BRANCH
git config user.name "Kalix Bot"
git config user.email "[email protected]"
git commit . -m "Bump SDK versions to $SDK_VERSION"
git remote add origin-rw https://[email protected]/lightbend/kalix-jvm-sdk
git push --set-upstream origin-rw $BRANCH
gh pr create -B main -t "Auto PR - Bump SDK versions to $SDK_VERSION" -b "This PR should update all existing samples (pom.xml and plugins.sbt) and the maven-java poms. Please review, and merge if okay. [$CIRCLE_SHA1]($CIRCLE_BUILD_URL)" || echo "No changes"; exit 0
tests:
docker:
- image: cimg/openjdk:11.0
Expand Down Expand Up @@ -1424,6 +1450,16 @@ workflows:
- publish-maven
- publish-tck

- create-pr-sdk-versions-update:
filters: # version tags only
tags:
only: /^v.*/
branches:
ignore: /.*/
requires:
# we only create the versions bump PR after publish-docs is successful, which means release was successful
- publish-docs

Nightly:
triggers:
- schedule:
Expand Down
8 changes: 4 additions & 4 deletions docs/release-issue-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ You can see the proxy version on prod [on grafana](https://lightbendcloud.grafan

### Update to the latest version

- [ ] Update the sdk version in samples and maven plugin
- [ ] Update the `kalix-sdk.version` in the `samples/*/pom.xml` files to the released version.
- [ ] Update the `kalix-sdk.version` default value in the `samples/scala-*/project/plugins.sbt` files to the release version
- [ ] version in `maven-java/**/pom.xml`
- [ ] Review and merge PR created by bot (should appear [here](https://github.com/lightbend/kalix-jvm-sdk/pulls?q=is%3Apr+is%3Aopen+auto+pr+)). While reviewing confirm the release version is updated for:
- `kalix-sdk.version` in the `samples/*/pom.xml` files
- `kalix-sdk.version` default value in the `samples/scala-*/project/plugins.sbt` files
- version in `maven-java/**/pom.xml`

### Check docs update

Expand Down
18 changes: 5 additions & 13 deletions updatePomVersions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ if [ -z ${SDK_VERSION+x} ]; then
SDK_VERSION=$(sbt "print sdkJava/version" | tail -1)
fi


if [ $1 ]; then
PROJ=$1
else
PROJ=("samples/*java-*" "samples/*spring-*")
fi

sbt 'publishM2; publishLocal'
(
cd maven-java
Expand All @@ -33,9 +26,8 @@ sbt 'publishM2; publishLocal'
git checkout */pom.xml
)

for i in ${PROJ[@]}
do
echo "Updating pom for: $i"
sed -i .versionsBackup "s/<kalix-sdk.version>\(.*\)<\/kalix-sdk.version>/<kalix-sdk.version>$SDK_VERSION<\/kalix-sdk.version>/" $i/pom.xml
rm $i/pom.xml.versionsBackup
done
if [ $1 ]; then
SDK_VERSION=$SDK_VERSION sh ./updateSdkVersions.sh java $1
else
SDK_VERSION=$SDK_VERSION sh ./updateSdkVersions.sh all
fi
57 changes: 57 additions & 0 deletions updateSdkVersions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# this script is meant to be used after a new SDK version is out
# to facilitate the update of all the places where we usually depend on the latest version

# provide the new sdk version you want the project to be updated to
if [[ -z "$SDK_VERSION" ]]; then
echo "Must provide SDK_VERSION in environment" 1>&2
exit 1
fi

updateJavaSamples() {
echo ">>> Updating pom versions to $SDK_VERSION"
PROJS=$(find $1 -type f -name "pom.xml")
for i in ${PROJS[@]}
do
echo "Updating pom for: $i"
sed -i .bak "s/<kalix-sdk.version>\(.*\)<\/kalix-sdk.version>/<kalix-sdk.version>$SDK_VERSION<\/kalix-sdk.version>/" $i
rm $i.bak
done
}

updateScalaSamples() {
echo ">>> Updating sbt plugins to $SDK_VERSION"
PROJS=$(find $1 -type f -name "*plugins.sbt")
for i in ${PROJS[@]}
do
echo "Updating plugins sbt for: $i"
sed -i .bak "s/System.getProperty(\"kalix-sdk.version\", \".*\"))/System.getProperty(\"kalix-sdk.version\", \"$SDK_VERSION\"))/" $i
rm $i.bak
done
}

updateMavenPlugin() {
echo ">>> Updating maven plugin to $SDK_VERSION"
cd maven-java && mvn versions:set -DnewVersion="$SDK_VERSION"
}

DEFAULT_SAMPLES="./samples"
option="${1}"
sample="${2:-$DEFAULT_SAMPLES}"
case ${option} in
java) updateJavaSamples $sample
;;
scala) updateScalaSamples $sample
;;
plugin) updateMavenPlugin
;;
all)
updateJavaSamples $sample; updateScalaSamples $sample; updateMavenPlugin
;;
*)
echo "`basename ${0}`:usage: java|scala|plugin|all [project-folder]"
echo "e.g.: `basename ${0}` java ./samples/java-customer-registry-kafka-quickstart/"
exit 1 # Command to come out of the program with status 1
;;
esac

0 comments on commit 2add3cf

Please sign in to comment.