From 6f2909977113cea7658bdbfa8ab54f29d57a26f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Sun, 18 Aug 2024 12:45:42 +0200 Subject: [PATCH] Squashed '.bin/' content from commit 953c3aa git-subtree-dir: .bin git-subtree-split: 953c3aa974e1483032424936cc02ad3df34671cd --- README.md | 38 ++++++++++++++++++++++++++++ git_utils | 28 +++++++++++++++++++++ gradlew_gpg | 39 +++++++++++++++++++++++++++++ gradlew_release | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ gradlew_utils | 31 +++++++++++++++++++++++ project-facet | 23 +++++++++++++++++ 6 files changed, 225 insertions(+) create mode 100644 README.md create mode 100644 git_utils create mode 100644 gradlew_gpg create mode 100644 gradlew_release create mode 100644 gradlew_utils create mode 100644 project-facet 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/git_utils b/git_utils new file mode 100644 index 0000000..f009434 --- /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/gradlew_gpg b/gradlew_gpg new file mode 100644 index 0000000..0978afe --- /dev/null +++ b/gradlew_gpg @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PARENT_DIR="$(dirname "$SCRIPT_DIR")" + +if [ -z "GPG_SIGNING_KEY" ]; then + + 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, but was '${GPG_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 + + + 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 + +source "${SCRIPT_DIR}/gradlew_utils" +gradlewExec "$@" \ No newline at end of file diff --git a/gradlew_release b/gradlew_release new file mode 100644 index 0000000..111e9e8 --- /dev/null +++ b/gradlew_release @@ -0,0 +1,66 @@ +#!/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" + +source "${SCRIPT_DIR}/gradlew_utils" + +if [ ! -z "${RELEASE_VERSION}" ]; then + gradlewExec --info -Prelease.useAutomaticVersion=true -Prelease.newVersion=${RELEASE_VERSION} :updateVersion :commitNewVersion +fi + +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/project-facet b/project-facet new file mode 100644 index 0000000..c5cf913 --- /dev/null +++ b/project-facet @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/git_utils" + +function main(){ + local cmd="$1" + case "${cmd}" in + update) + onGitRootDir updateSubtrees + ;; + *) + echo "Usage: $0 update" + ;; + esac +} + +function updateSubtrees() { + updateSubtree git-repo-commons gradle .bin + updateSubtree git-repo-commons gradle .github +} + +main "$@"; exit \ No newline at end of file