From 4c201eb7f68db22f638ed04d4d51bd8371d58782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Fri, 16 Aug 2024 08:51:16 +0200 Subject: [PATCH 01/10] Added README. --- gradlew_gpg | 36 ++++++++++++++++++++++++++++ gradlew_release | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 gradlew_gpg create mode 100644 gradlew_release diff --git a/gradlew_gpg b/gradlew_gpg new file mode 100644 index 0000000..0632c4b --- /dev/null +++ b/gradlew_gpg @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PARENT_DIR="$(dirname "$SCRIPT_DIR")" + +if [ -z "$GPG_KEY_FINGERPRINT" ]; then +GPG_KEY_FINGERPRINT=$1 +shift + +if [ "${#GPG_KEY_FINGERPRINT}" -ne 40 ] || ! [[ $GPG_KEY_FINGERPRINT =~ ^[0-9A-Fa-f]{1,}$ ]]; then + echo "First arg must be the 40 character key fingerprint." + exit 1 +fi +fi + + +if [ -z "${GPG_SIGNING_PASSPHRASE}" ]; then + echo -n "Enter passphrase: " + unset GPG_SIGNING_PASSPHRASE + while IFS= read -r -s -n1 pass; do + if [[ -z $pass ]]; then + echo + break + else + echo -n '*' + GPG_SIGNING_PASSPHRASE+=$pass + fi + done + export GPG_SIGNING_PASSPHRASE +fi + +GPG_SIGNING_KEY=$(echo ${GPG_SIGNING_PASSPHRASE} |gpg --pinentry-mode=loopback --passphrase-fd 0 -a --export-secret-keys $GPG_KEY_FINGERPRINT) +export GPG_SIGNING_KEY + + +exec ${PARENT_DIR}/gradlew "$@" \ No newline at end of file diff --git a/gradlew_release b/gradlew_release new file mode 100644 index 0000000..ccaef0b --- /dev/null +++ b/gradlew_release @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PARENT_DIR="$(dirname "$SCRIPT_DIR")" + +RELEASE_STRATEGY="patch" + +if [ ! -z "$1" ]; then + RELEASE_STRATEGY="$1" + shift +fi + +function printHelp(){ + >&2 echo "Usage: $(basename "$0") [patch|minor|major]" +} + +function currentVersion() { + echo $(${SCRIPT_DIR}/gradlew properties -q | awk '/^version:/ {print $2}') +} + +increment_version() { + local delimiter=. + local array=($(echo "$1" | tr $delimiter '\n')) + array[$2]=$((array[$2]+1)) + + for (( j=$(($2+1)); j<${#array[@]}; j++ )); + do + array[$j]=0 + done + + echo $(local IFS=$delimiter ; echo "${array[*]}") +} + +shopt -s extglob +case "$RELEASE_STRATEGY" in + "--help" | "-?" ) + printHelp + ;; + "patch" ) + # Nothing to do + ;; + "minor" ) + CURRENT_VERSION=$(currentVersion) + RELEASE_VERSION=$(increment_version ${CURRENT_VERSION} 1) + ;; + "major" ) + CURRENT_VERSION=$(currentVersion) + RELEASE_VERSION=$(increment_version ${CURRENT_VERSION} 0) + ;; + +([0-9])?(.+([0-9]))?(.+([0-9])) ) + RELEASE_VERSION="$RELEASE_STRATEGY-SNAPSHOT" + ;; + *) + printHelp + ;; +esac + +echo "Executing ${RELEASE_STRATEGY} release" + +if [ ! -z "${RELEASE_VERSION}" ]; then + ${PARENT_DIR}/gradlew --info -Prelease.useAutomaticVersion=true -Prelease.newVersion=${RELEASE_VERSION} :updateVersion :commitNewVersion +fi + +exec ${PARENT_DIR}/gradlew --info -Prelease.useAutomaticVersion=true release "$@" \ No newline at end of file From f6ecf04b76b4ce9ca72269d20825f3d43a26920b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Fri, 16 Aug 2024 09:10:01 +0200 Subject: [PATCH 02/10] Added update-git-repo-commons script. --- update-git-repo-commons.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 update-git-repo-commons.sh diff --git a/update-git-repo-commons.sh b/update-git-repo-commons.sh new file mode 100644 index 0000000..6f4c5a6 --- /dev/null +++ b/update-git-repo-commons.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PARENT_DIR="$(dirname "$SCRIPT_DIR")" + +pushd $(pwd) +cd ${PARENT_DIR} + +git subtree -P .bin pull --squash git-repo-commons gradle/bin +git subtree -P .github pull --squash git-repo-commons gradle/github + +popd \ No newline at end of file From 628f1d1378994a10a5b967dfdafaf45e2931baff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Fri, 16 Aug 2024 09:11:29 +0200 Subject: [PATCH 03/10] Changed file to trigger workflow. --- update-git-repo-commons.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/update-git-repo-commons.sh b/update-git-repo-commons.sh index 6f4c5a6..ebccd3b 100644 --- a/update-git-repo-commons.sh +++ b/update-git-repo-commons.sh @@ -3,6 +3,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PARENT_DIR="$(dirname "$SCRIPT_DIR")" + pushd $(pwd) cd ${PARENT_DIR} From 2f9d4a17b4a51ff8ff96290f68fb73b53d1b3a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Sun, 18 Aug 2024 11:53:20 +0200 Subject: [PATCH 04/10] Locating gradlew improved. --- README.md | 38 ++++++++++++++ gradlew_gpg | 55 +++++++++++---------- gradlew_release | 6 ++- gradlew_utils | 31 ++++++++++++ update-git-repo-commons.sh => project-facet | 0 5 files changed, 102 insertions(+), 28 deletions(-) create mode 100644 README.md create mode 100644 gradlew_utils rename update-git-repo-commons.sh => project-facet (100%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac6e552 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Script Documentation + +## [gradlew_gpg](gradlew_gpg) + +Exports a gpg key and executes the `gradlew` in the parent directory. +Any arguments passed to `gradlew_gpg` will be passed to the `gradlew` in the parent directory. + +### Use the key fingerpring + +You can pass the signing key fingerprint as the first argument + +```shell +./gradlew_gpg 1CEFE097A0DC0F8C2F92688 publish +``` + +### Fingerprint as environment variable + +Set the singing key fingerprint as an environment variable. This environment var is then used to look up the key. + +```shell +export GPG_KEY_FINGERPRINT=1CEFE097A0DC0F8C2F92688 + +./gradlew_gpg publish +``` + + +When the script executes it will ask you for the passphrase + +```shell +$ ./gradlew_gpg publish +Enter passphrase: ************** + +> Configure project : +Signing publications +<-------------> 3% EXECUTING [7s] +> :initializeSonatypeStagingRepository +``` + diff --git a/gradlew_gpg b/gradlew_gpg index 0632c4b..0978afe 100644 --- a/gradlew_gpg +++ b/gradlew_gpg @@ -3,34 +3,37 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PARENT_DIR="$(dirname "$SCRIPT_DIR")" -if [ -z "$GPG_KEY_FINGERPRINT" ]; then -GPG_KEY_FINGERPRINT=$1 -shift - -if [ "${#GPG_KEY_FINGERPRINT}" -ne 40 ] || ! [[ $GPG_KEY_FINGERPRINT =~ ^[0-9A-Fa-f]{1,}$ ]]; then - echo "First arg must be the 40 character key fingerprint." - exit 1 -fi -fi +if [ -z "GPG_SIGNING_KEY" ]; then + if [ -z "$GPG_KEY_FINGERPRINT" ]; then + GPG_KEY_FINGERPRINT=$1 + shift -if [ -z "${GPG_SIGNING_PASSPHRASE}" ]; then - echo -n "Enter passphrase: " - unset GPG_SIGNING_PASSPHRASE - while IFS= read -r -s -n1 pass; do - if [[ -z $pass ]]; then - echo - break - else - echo -n '*' - GPG_SIGNING_PASSPHRASE+=$pass + if [ "${#GPG_KEY_FINGERPRINT}" -ne 40 ] || ! [[ $GPG_KEY_FINGERPRINT =~ ^[0-9A-Fa-f]{1,}$ ]]; then + echo "First arg must be the 40 character key fingerprint, but was '${GPG_KEY_FINGERPRINT}'" + exit 1 fi - done - export GPG_SIGNING_PASSPHRASE + fi + + if [ -z "GPG_SIGNING_PASSPHRASE" ]; then + echo -n "Enter passphrase: " + unset GPG_SIGNING_PASSPHRASE + while IFS= read -r -s -n1 pass; do + if [[ -z $pass ]]; then + echo + break + else + echo -n '*' + GPG_SIGNING_PASSPHRASE+=$pass + fi + done + export GPG_SIGNING_PASSPHRASE + + + GPG_SIGNING_KEY=$(echo ${GPG_SIGNING_PASSPHRASE} |gpg --pinentry-mode=loopback --passphrase-fd 0 -a --export-secret-keys $GPG_KEY_FINGERPRINT) + export GPG_SIGNING_KEY + fi fi -GPG_SIGNING_KEY=$(echo ${GPG_SIGNING_PASSPHRASE} |gpg --pinentry-mode=loopback --passphrase-fd 0 -a --export-secret-keys $GPG_KEY_FINGERPRINT) -export GPG_SIGNING_KEY - - -exec ${PARENT_DIR}/gradlew "$@" \ No newline at end of file +source "${SCRIPT_DIR}/gradlew_utils" +gradlewExec "$@" \ No newline at end of file diff --git a/gradlew_release b/gradlew_release index ccaef0b..111e9e8 100644 --- a/gradlew_release +++ b/gradlew_release @@ -57,8 +57,10 @@ esac echo "Executing ${RELEASE_STRATEGY} release" +source "${SCRIPT_DIR}/gradlew_utils" + if [ ! -z "${RELEASE_VERSION}" ]; then - ${PARENT_DIR}/gradlew --info -Prelease.useAutomaticVersion=true -Prelease.newVersion=${RELEASE_VERSION} :updateVersion :commitNewVersion + gradlewExec --info -Prelease.useAutomaticVersion=true -Prelease.newVersion=${RELEASE_VERSION} :updateVersion :commitNewVersion fi -exec ${PARENT_DIR}/gradlew --info -Prelease.useAutomaticVersion=true release "$@" \ No newline at end of file +gradlewExec --info -Prelease.useAutomaticVersion=true release "$@" \ No newline at end of file diff --git a/gradlew_utils b/gradlew_utils new file mode 100644 index 0000000..fc0f877 --- /dev/null +++ b/gradlew_utils @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +function findGradlewPath() { + local parent_dir="$(dirname "$SCRIPT_DIR")" + local gradlew_path="$(git rev-parse --show-toplevel)/gradlew" + + if [ -f "${gradlew_path}" ]; then + echo "${gradlew_path}" + return + fi + + echo "" +} + +function gradlewExec(){ + local gradlew="$(findGradlewPath)" + + if ! [ -f "${gradlew}" ]; then + >&2 echo "Gradle Wrapper not found!" + exit 1 + fi + + if [ -x "${gradlew}" ]; then + exec "${gradlew}" $@ + fi + + >&2 echo "Gradle Wrapper is not executable: ${gradlew}" + exit 1 +} diff --git a/update-git-repo-commons.sh b/project-facet similarity index 100% rename from update-git-repo-commons.sh rename to project-facet From 93da72e5f77fc580e61ac611225805901859e6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Sun, 18 Aug 2024 12:32:51 +0200 Subject: [PATCH 05/10] Reuse bash code. --- git_utils | 28 ++++++++++++++++++++++++++++ project-facet | 24 +++++++++++++++++------- 2 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 git_utils diff --git a/git_utils b/git_utils new file mode 100644 index 0000000..1ca6fb0 --- /dev/null +++ b/git_utils @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +function onGitRootDir() { + pushd "$(pwd)" > /dev/null + cd "$(git rev-parse --show-toplevel)" + local command=$1 + shift + $command $* + popd > /dev/null +} + + +function updateSubtree(){ + local repo=$1 + local projectFacet=$2 + local subtree=$3 + local existingSubtrees=$(git log | grep git-subtree-dir | tr -d ' ' | cut -d ":" -f2 | sort | uniq | xargs -I {} bash -c 'if [ -d $(git rev-parse --show-toplevel)/{} ] ; then echo {}; fi') + local subtreeBranchQualifier="${subtree#\.}" + + if [[ ${existingSubtrees} =~ ${subtree} ]]; then + git subtree -P "${subtree}" pull --squash "${repo}/${projectFacet}/${subtreeBranchQualifier}" + else + local subtreeBranchQualifier="${subtree#\.}" + git subtree -P "${subtree}" add --squash "${repo}/${projectFacet}/${subtreeBranchQualifier}" + fi +} \ No newline at end of file diff --git a/project-facet b/project-facet index ebccd3b..00eebcb 100644 --- a/project-facet +++ b/project-facet @@ -1,13 +1,23 @@ #!/usr/bin/env bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -PARENT_DIR="$(dirname "$SCRIPT_DIR")" +source "{SCRIPT_DIR}/git_utils" +function main(){ + local cmd="$1" + case "${cmd}" in + update) + onGitRootDir updateSubtrees + ;; + *) + echo "Usage: $0 update" + ;; + esac +} -pushd $(pwd) -cd ${PARENT_DIR} +function updateSubtrees() { + updateSubtree git-repo-commons gradle .bin + updateSubtree git-repo-commons gradle .github +} -git subtree -P .bin pull --squash git-repo-commons gradle/bin -git subtree -P .github pull --squash git-repo-commons gradle/github - -popd \ No newline at end of file +main "$@"; exit \ No newline at end of file From f0f0531995655f7e1ebf4018f9f6c8a3e07f24f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Sun, 18 Aug 2024 12:35:28 +0200 Subject: [PATCH 06/10] Reuse bash code. --- git_utils | 2 +- project-facet | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/git_utils b/git_utils index 1ca6fb0..f009434 100644 --- a/git_utils +++ b/git_utils @@ -20,7 +20,7 @@ function updateSubtree(){ local subtreeBranchQualifier="${subtree#\.}" if [[ ${existingSubtrees} =~ ${subtree} ]]; then - git subtree -P "${subtree}" pull --squash "${repo}/${projectFacet}/${subtreeBranchQualifier}" + git subtree -P "${subtree}" pull --squash "${repo}" "${projectFacet}/${subtreeBranchQualifier}" else local subtreeBranchQualifier="${subtree#\.}" git subtree -P "${subtree}" add --squash "${repo}/${projectFacet}/${subtreeBranchQualifier}" diff --git a/project-facet b/project-facet index 00eebcb..c5cf913 100644 --- a/project-facet +++ b/project-facet @@ -1,7 +1,7 @@ #!/usr/bin/env bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -source "{SCRIPT_DIR}/git_utils" +source "${SCRIPT_DIR}/git_utils" function main(){ local cmd="$1" From f7557987047570e7c3eb571b1f92d68a25d3bbb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Sun, 18 Aug 2024 13:55:31 +0200 Subject: [PATCH 07/10] Set execution flag for scripts. --- gradlew_gpg | 0 gradlew_release | 0 gradlew_utils | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew_gpg mode change 100644 => 100755 gradlew_release mode change 100644 => 100755 gradlew_utils diff --git a/gradlew_gpg b/gradlew_gpg old mode 100644 new mode 100755 diff --git a/gradlew_release b/gradlew_release old mode 100644 new mode 100755 diff --git a/gradlew_utils b/gradlew_utils old mode 100644 new mode 100755 From 33673833f4ab1235f68871c02eaf8da8862810a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Sun, 18 Aug 2024 14:28:28 +0200 Subject: [PATCH 08/10] Do no substitute the process using exec. --- gradlew_utils | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gradlew_utils b/gradlew_utils index fc0f877..6bfb942 100755 --- a/gradlew_utils +++ b/gradlew_utils @@ -23,7 +23,8 @@ function gradlewExec(){ fi if [ -x "${gradlew}" ]; then - exec "${gradlew}" $@ + "${gradlew}" $@ + retrun fi >&2 echo "Gradle Wrapper is not executable: ${gradlew}" From d4511c4cb98079987808a48fa7efbc0a02149102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Sun, 18 Aug 2024 14:58:07 +0200 Subject: [PATCH 09/10] Typo. --- gradlew_utils | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradlew_utils b/gradlew_utils index 6bfb942..15408d9 100755 --- a/gradlew_utils +++ b/gradlew_utils @@ -24,7 +24,7 @@ function gradlewExec(){ if [ -x "${gradlew}" ]; then "${gradlew}" $@ - retrun + return fi >&2 echo "Gradle Wrapper is not executable: ${gradlew}" From 67bd61eca6af0235ec86e340e8daac9667b1ed0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Sun, 18 Aug 2024 17:22:56 +0200 Subject: [PATCH 10/10] Do not use subtree squash. --- git_utils | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git_utils b/git_utils index f009434..9f4d7ed 100644 --- a/git_utils +++ b/git_utils @@ -20,9 +20,9 @@ function updateSubtree(){ local subtreeBranchQualifier="${subtree#\.}" if [[ ${existingSubtrees} =~ ${subtree} ]]; then - git subtree -P "${subtree}" pull --squash "${repo}" "${projectFacet}/${subtreeBranchQualifier}" + git subtree -P "${subtree}" pull "${repo}" "${projectFacet}/${subtreeBranchQualifier}" else local subtreeBranchQualifier="${subtree#\.}" - git subtree -P "${subtree}" add --squash "${repo}/${projectFacet}/${subtreeBranchQualifier}" + git subtree -P "${subtree}" add "${repo}/${projectFacet}/${subtreeBranchQualifier}" fi } \ No newline at end of file