From 1f8b986f79515c81dde6edb48f22cb273a125eb5 Mon Sep 17 00:00:00 2001 From: Johannes Visintini Date: Tue, 10 Dec 2024 12:03:19 +0100 Subject: [PATCH 1/2] improve release script for macOS and Linux compatibility --- ..._user_exit_or_continue.sh => functions.sh} | 13 +++++++++++- scripts/release.sh | 21 +++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) rename scripts/{prompt_user_exit_or_continue.sh => functions.sh} (75%) diff --git a/scripts/prompt_user_exit_or_continue.sh b/scripts/functions.sh similarity index 75% rename from scripts/prompt_user_exit_or_continue.sh rename to scripts/functions.sh index fa1ab7b43..3d30401ca 100644 --- a/scripts/prompt_user_exit_or_continue.sh +++ b/scripts/functions.sh @@ -20,6 +20,17 @@ prompt_user() { done } + +run_sed() { +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + sed --in-place=.bak "$1" "$2" +elif [[ "$OSTYPE" == "darwin"* ]]; then + sed -i .bak "$1" "$2" +else + printf "\nOS could not be detected. Please open report manually!\n" +fi +} + # Example usage #prompt_user "Do you want to continue?" @@ -29,4 +40,4 @@ prompt_user() { #SCRIPT_DIR="$(dirname "$0")" # ## import user prompt - #source "$SCRIPT_DIR/prompt_user_exit_or_continue.sh" \ No newline at end of file + #source "$SCRIPT_DIR/functions.sh" diff --git a/scripts/release.sh b/scripts/release.sh index ea08317ad..96fa259fb 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,3 +1,4 @@ +#!/bin/bash # based on docs here: https://heigit.atlassian.net/wiki/spaces/OQT/pages/3474149/Releases # requires local installation of `gh`, the github CLI: https://cli.github.com @@ -9,14 +10,14 @@ export NEW_VERSION=1.8.1 # exit immediately if a command exits with a non-zero status -set -ex +set -e # get the directory of the current script SCRIPT_DIR="$(dirname "$0")" # import user prompt -source "$SCRIPT_DIR/prompt_user_exit_or_continue.sh" +source "$SCRIPT_DIR/functions.sh" prompt_user "👉 did you adjust the values for old and new versions in the release script?" @@ -26,7 +27,7 @@ prompt_user "👉 do you run this script in an active python env? if not run 'po # change to main directory -cd .. +cd $SCRIPT_DIR/.. # get latest version of main and create new branch @@ -56,14 +57,14 @@ export NEW="__version__ = \"$NEW_VERSION\"" # might not work like this on linux -sed -i .bak "s/$OLD/$NEW/g" ohsome_quality_api/__init__.py +run_sed "s/$OLD/$NEW/g" ohsome_quality_api/__init__.py rm -rf ohsome_quality_api/__init__.py.bak echo "✅ updated __init__.py to $NEW_VERSION" # insert new sub-headline for new release prompt_user "👉 update CHANGELOG.md?" -sed -i .bak "s/## Current Main/## Current Main \n\n## Release $NEW_VERSION/g" CHANGELOG.md +run_sed "s/## Current Main/## Current Main\n\n## Release $NEW_VERSION/g" CHANGELOG.md rm -rf CHANGELOG.md.bak echo "✅ updated CHANGELOG.md" @@ -108,4 +109,12 @@ echo "✅ created new github release and tag for version: $NEW_VERSION" -echo "⚠️ Please start the Jenkins tag build here: https://jenkins.heigit.org/job/OQAPI/view/tags/job/$NEW_VERSION/" +JENKINS_URL="https://jenkins.heigit.org/job/OQAPI/view/tags/job/${NEW_VERSION}/" +echo "⚠️ Please start the Jenkins tag build here: ${JENKINS_URL}" +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + xdg-open "$JENKINS_URL" +elif [[ "$OSTYPE" == "darwin"* ]]; then + open "$JENKINS_URL" +else + printf "\nOS could not be detected. Please open report manually!\n" +fi From 6c996de282cc261e55ca8197df061255dbe758ba Mon Sep 17 00:00:00 2001 From: Johannes Visintini Date: Tue, 10 Dec 2024 12:12:52 +0100 Subject: [PATCH 2/2] scripts: add function for opening (i.e. URLs) --- scripts/functions.sh | 24 +++++++++++++++++------- scripts/release.sh | 8 +------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 3d30401ca..9d548dd7f 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -22,13 +22,23 @@ prompt_user() { run_sed() { -if [[ "$OSTYPE" == "linux-gnu"* ]]; then - sed --in-place=.bak "$1" "$2" -elif [[ "$OSTYPE" == "darwin"* ]]; then - sed -i .bak "$1" "$2" -else - printf "\nOS could not be detected. Please open report manually!\n" -fi + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + sed --in-place=.bak "$1" "$2" + elif [[ "$OSTYPE" == "darwin"* ]]; then + sed -i .bak "$1" "$2" + else + printf "\nOS could not be detected. Please open report manually!\n" + fi +} + +run_open() { + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + xdg-open "$1" + elif [[ "$OSTYPE" == "darwin"* ]]; then + open "$1" + else + printf "\nOS could not be detected. Please open URL manually!\n" + fi } # Example usage diff --git a/scripts/release.sh b/scripts/release.sh index 96fa259fb..1a4b7f028 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -111,10 +111,4 @@ echo "✅ created new github release and tag for version: $NEW_VERSION" JENKINS_URL="https://jenkins.heigit.org/job/OQAPI/view/tags/job/${NEW_VERSION}/" echo "⚠️ Please start the Jenkins tag build here: ${JENKINS_URL}" -if [[ "$OSTYPE" == "linux-gnu"* ]]; then - xdg-open "$JENKINS_URL" -elif [[ "$OSTYPE" == "darwin"* ]]; then - open "$JENKINS_URL" -else - printf "\nOS could not be detected. Please open report manually!\n" -fi +run_open "$JENKINS_URL"