Skip to content

Commit

Permalink
Merge commit 'ba7f7cb412fb1ad18fc587dab7235d0a8a0d57af' as '.bin'
Browse files Browse the repository at this point in the history
  • Loading branch information
renelink committed Aug 18, 2024
2 parents dbd8c20 + ba7f7cb commit 19a51c6
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .bin/README.md
Original file line number Diff line number Diff line change
@@ -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
```

28 changes: 28 additions & 0 deletions .bin/git_utils
Original file line number Diff line number Diff line change
@@ -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
}
39 changes: 39 additions & 0 deletions .bin/gradlew_gpg
Original file line number Diff line number Diff line change
@@ -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 "$@"
66 changes: 66 additions & 0 deletions .bin/gradlew_release
Original file line number Diff line number Diff line change
@@ -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 "$@"
31 changes: 31 additions & 0 deletions .bin/gradlew_utils
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 23 additions & 0 deletions .bin/project-facet
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 19a51c6

Please sign in to comment.