diff --git a/.gt/remotes/tegonal-scripts/pulled.tsv b/.gt/remotes/tegonal-scripts/pulled.tsv index 7e3cc55..abf52c4 100644 --- a/.gt/remotes/tegonal-scripts/pulled.tsv +++ b/.gt/remotes/tegonal-scripts/pulled.tsv @@ -34,3 +34,4 @@ v3.2.0 src/releasing/common-constants.source.sh ../lib/tegonal-scripts/src/relea v3.2.0 src/releasing/prepare-next-dev-cycle-template.sh ../lib/tegonal-scripts/src/releasing/prepare-next-dev-cycle-template.sh 9aabb683af66bab30cba32f8486b4a3eb2fcaa243d743b1ea7177a1b17477e44249694b5fcec74298c3d1efb5989a2f86e10c78e5c810fed2b8756509c690f59 v3.2.0 src/utility/http.sh ../lib/tegonal-scripts/src/utility/http.sh 10b68f46a45f9bad34892bb3a55d72c2a8f58bf4836c9ed1eebf0999ad89c624f3e0ffd19101bacfdd7ec1bbe5f2e729d79bcff4058a2a10b249fad153cdcad6 v3.2.0 src/utility/execute-if-defined.sh ../lib/tegonal-scripts/src/utility/execute-if-defined.sh ebc507d88a3105790f3f7825db9c698234100d4eceb32f10f8acf94328123a95260841367dfa1eb04922f42a7d32fbf9143031cb1e8ee8b066386bb475895b62 +v3.2.0 src/utility/cleanups.sh ../lib/tegonal-scripts/src/utility/cleanups.sh 951b6a2384ab134cb17a4f7cb73d800e0cb397c6b7ac4ee23e9d0799c4066aa5cfa9db7587cc6afb64b812e8c230894643aa4d69137ec1390f05110691ca09ea diff --git a/lib/tegonal-scripts/src/utility/cleanups.sh b/lib/tegonal-scripts/src/utility/cleanups.sh new file mode 100644 index 0000000..394224b --- /dev/null +++ b/lib/tegonal-scripts/src/utility/cleanups.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2059 +# +# __ __ +# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/scripts +# / __/ -_) _ `/ _ \/ _ \/ _ `/ / Copyright 2022 Tegonal Genossenschaft +# \__/\__/\_, /\___/_//_/\_,_/_/ It is licensed under Apache License 2.0 +# /___/ Please report bugs and contribute back your improvements +# +# Version: v3.2.0 +####### Description ############# +# +# Functions which help in doing cleanup in e.g. scripts/cleanup-on-push-to-main.sh +# +####### Usage ################### +# +# #!/usr/bin/env bash +# set -euo pipefail +# shopt -s inherit_errexit +# +# projectDir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/.." +# +# # Assumes tegonal's scripts were fetched with gt - adjust location accordingly +# dir_of_tegonal_scripts="$projectDir/lib/tegonal-scripts/src" +# source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts" +# +# sourceOnce "$dir_of_tegonal_scripts/utility/cleanups.sh" +# +# # e.g. in scripts/cleanup-on-push-to-main.sh +# function cleanupOnPushToMain() { +# removeUnusedSignatures "$projectDir" +# logSuccess "cleanup done" +# } +# +################################### +set -euo pipefail +shopt -s inherit_errexit +unset CDPATH + +if ! [[ -v dir_of_tegonal_scripts ]]; then + dir_of_tegonal_scripts="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)/.." + source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts" +fi +sourceOnce "$dir_of_tegonal_scripts/utility/log.sh" + +function removeUnusedSignatures() { + if ! (($# == 1)); then + logError "One argument needs to be passed to removeUnusedSignatures, given \033[0;36m%s\033[0m\n" "$#" + echo >&2 '1: projectDir the path to the root directory of the project' + printStackTrace + exit 9 + fi + local projectRootDir=$1 + shift 1 || die "could not shift by 1" + + find "$projectRootDir" \ + -type f \ + -name "*.sig" \ + -not -path "$projectRootDir/.gt/signing-key.public.asc.sig" \ + -not -path "$projectRootDir/.gt/remotes/*/public-keys/*.sig" \ + -print0 | + while read -r -d $'\0' sigFile; do + if ! [[ -f ${sigFile::${#sigFile}-4} ]]; then + logInfo "remove unused signature \033[0;36m%s\033[0m as the corresponding file does no longer exist" "$sigFile" + rm "$sigFile" + fi + done +} diff --git a/scripts/cleanup-on-push-to-main.sh b/scripts/cleanup-on-push-to-main.sh index d0b692b..630562e 100755 --- a/scripts/cleanup-on-push-to-main.sh +++ b/scripts/cleanup-on-push-to-main.sh @@ -31,6 +31,7 @@ if ! [[ -v dir_of_tegonal_scripts ]]; then dir_of_tegonal_scripts="$projectDir/lib/tegonal-scripts/src" source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts" fi +sourceOnce "$dir_of_tegonal_scripts/utility/cleanups.sh" sourceOnce "$dir_of_github_commons/gt/pull-hook-functions.sh" sourceOnce "$dir_of_tegonal_scripts/utility/update-bash-docu.sh" @@ -47,6 +48,8 @@ function cleanup_putWarning() { } function cleanupOnPushToMain() { + removeUnusedSignatures "$projectDir" + find "$dir_of_github_commons/dotfiles" -type f -name ".*" -not -name '.*.sig' -print0 | while read -r -d $'\0' file; do cp "$file" "$projectDir/" || return $?