diff --git a/.glue/actions/auto/result-pacman-package.sh b/.glue/actions/auto/result-pacman-package.sh index 67b6e77..0da5b49 100755 --- a/.glue/actions/auto/result-pacman-package.sh +++ b/.glue/actions/auto/result-pacman-package.sh @@ -13,60 +13,56 @@ main() { ensure.file glue.toml ensure.file glue-auto.toml - # TODO: use function - mkdir -p .glue/generated/tool-makepkg + toml.get_key project glue.toml + local myProject="$REPLY" - # TODO: get these values somewhere else - toml.get_key name glue.toml - local myPkg="$REPLY" - local myName="Edwin Kofler" - local myEmail="edwin@kofler.dev" toml.get_key desc glue.toml local myDesc="$REPLY" + toml.get_key name glue.toml + local myName="$REPLY" + + toml.get_key email glue.toml + local myEmail="$REPLY" + toml.get_key version glue-auto.toml - local myVer="$REPLY" - myVer="${myVer/-/_}" + local myVer="$REPLY"; myVer="${myVer/-/_}" + ensure.nonZero 'myProject' "$myProject" + ensure.nonZero 'myDesc' "$myDesc" + ensure.nonZero 'myName' "$myName" + ensure.nonZero 'myEmail' "$myEmail" ensure.nonZero 'myVer' "$myVer" - # glue useConfig(tool-makepkg) - util.get_config "tool-makepkg/dev/PKGBUILD" + + # glue useConfig(result-pacman-package) + util.get_config "result-pacman-package/dev/PKGBUILD" pkgbuildFile="$REPLY" generated.in 'result-pacman-package' ( - mkdir -p .glue/generated/tool-makepkg/dev - cd .glue/generated/tool-makepkg/dev || error.cd_failed + cd "$GENERATED_DIR" || error.cd_failed + mkdir dev + cd dev || error.cd_failed - cp "$pkgbuildFile" . + tar --create --directory "$GLUE_WD" --file "$myProject-$myVer.tar.gz" --exclude './.git' \ + --exclude "$myProject-$myVer.tar.gz" --transform "s/^\./$myProject-$myVer/" ./ - # TODO: bash templating + cp "$pkgbuildFile" . sed -i -e "s/# Maintainer:.*/# Maintainer: $myName <$myEmail>/g" PKGBUILD - sed -i -e "s/pkgname=.*\$/pkgname='$myPkg'/g" PKGBUILD + sed -i -e "s/pkgname=.*\$/pkgname='$myProject'/g" PKGBUILD sed -i -e "s/pkgver=.*\$/pkgver='$myVer'/g" PKGBUILD sed -i -e "s/pkgdesc=.*\$/pkgdesc='$myDesc'/g" PKGBUILD - sed -i -e "s/url=.*\$/url='https:\/\/github.com\/eankeen\/$myPkg'/g" PKGBUILD - sed -i -e "s/source=.*\$/source=\(\$pkgname-\$pkgver.tar.gz::http:\/\/localhost:9334\/v\$pkgver.tar.gz\)/g" PKGBUILD - - # TODO: assumption on working directory - tar --create --directory "$GLUE_WD" --file "$myPkg-$myVer.tar.gz" ../"$myPkg" - rm -rf "$myPkg-$myVer" - # tar xf "$myPkg-$myVer.tar.gz" - # mv "$myPkg" "$myPkg-$myVer" - # rm -rf "$myPkg-$myVer/.git" - - local sum="$(sha256sum "$myPkg-$myVer.tar.gz")" + sed -i -e "s/url=.*\$/url='https:\/\/github.com\/eankeen\/$myProject'/g" PKGBUILD + sed -i -e "s/source=.*\$/source=\(\$pkgname-\$pkgver.tar.gz::\)/g" PKGBUILD + local sum="$(sha256sum "$myProject-$myVer.tar.gz")" sum="${sum%% *}" sed -i -e "s/sha256sums=.*\$/sha256sums=\('$sum'\)/g" PKGBUILD + namcap PKGBUILD makepkg -Cfsrc + namcap ./*.zst ) || exit generated.out - - # TODO: think about more fine grained linting control in the whole SDLC - # namcap PKGBUILD - # namcap ./*.zst - } main "$@" diff --git a/.glue/actions/auto/util-Bash-version-bump.sh b/.glue/actions/auto/util-Bash-version-bump.sh new file mode 100644 index 0000000..7025d6f --- /dev/null +++ b/.glue/actions/auto/util-Bash-version-bump.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +eval "$GLUE_BOOTSTRAP" +bootstrap || exit + +unset main +main() { + local newVersion="$1" + ensure.nonZero 'newVersion' "$newVersion" + + # TODO: show which files changed + find . -ignore_readdir_race -regex '\./pkg/.*\.\(sh\|bash\)' -print0 2>/dev/null \ + | xargs -r0 \ + sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1$newVersion\2|g" + log.info "util-Bash-version-bump: Bump done" +} + +main "$@" +unset main + +unbootstrap diff --git a/.glue/actions/auto/util-get-version.sh b/.glue/actions/auto/util-get-version.sh index 1bebfe9..953e5a6 100755 --- a/.glue/actions/auto/util-get-version.sh +++ b/.glue/actions/auto/util-get-version.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -eval "$GLUE_BOOTSTRAP" -bootstrap || exit +unset main main() { # If the working tree is dirty and there are unstaged changes # for both tracked and untracked files @@ -24,4 +23,4 @@ main() { } main "$@" -unbootstrap +unset main diff --git a/.glue/actions/auto/util-release-post.sh b/.glue/actions/auto/util-release-post.sh index ec9b3dd..be197f4 100755 --- a/.glue/actions/auto/util-release-post.sh +++ b/.glue/actions/auto/util-release-post.sh @@ -1,46 +1,70 @@ #!/usr/bin/env bash -# eval "$GLUE_BOOTSTRAP" -# bootstrap || exit +eval "$GLUE_BOOTSTRAP" +bootstrap || exit # @file util-release-post.sh # @brief Steps to perform after specialized version bumping +# - Ensure a dirty Git working tree +# - Add bumped files to commit with version number +# - Make GitHub release unset main main() { local -r dryStatus="$1" local newVersion="$2" - ensure.nonZero 'newVersion' "$newVersion" - ensure.cmd 'git' ensure.cmd 'gh' + ensure.nonZero 'newVersion' "$newVersion" + + isDry() { + # must be set to 'notDry' to not be dry. + # Defaults to 'not dry' + [ "$dryStatus" != "notDry" ] + } + + if isDry; then + log.info "Running release process in dry mode" + fi + # Ensure working tree is dirty if [ -z "$(git status --porcelain)" ]; then - die 'Working tree is not dirty. Cannot make a release if versions have not been bumped in their respective files' + if isDry; then + local cmd="log.warn" + else + local cmd="die" + fi + + "$cmd" 'Working tree is not dirty. Cannot make a release if versions have not been bumped in their respective files' fi # Local Release - git add -A - git commit -m "chore(release): v$newVersion" - git tag -a "v$newVersion" -m "Release $newVersion" HEAD - git push --follow-tags origin HEAD - - local -a args=() - if [ -f CHANGELOG.md ]; then - args+=("-F" "CHANGELOG.md") - elif [ -f changelog.md ]; then - args+=("-F" "changelog.md") + if isDry; then + log.info "Skipping Git taging and artifact release" else - # '-F' is required for non-interactivity - args+=("-F" "") - log.warn 'CHANGELOG.md file not found. Creating empty notes file for release' - fi + git add -A + git commit -m "chore(release): v$newVersion" + git tag -a "v$newVersion" -m "Release $newVersion" HEAD + git push --follow-tags origin HEAD - # Remote Release - gh release create "v$newVersion" --target main --title "v$newVersion" "${args[@]}" + local -a args=() + if [ -f CHANGELOG.md ]; then + args+=("-F" "CHANGELOG.md") + elif [ -f changelog.md ]; then + args+=("-F" "changelog.md") + else + # '-F' is required for non-interactivity + args+=("-F" "") + log.warn 'CHANGELOG.md file not found. Creating empty notes file for release' + fi + + # Remote Release + gh release create "v$newVersion" --target main --title "v$newVersion" "${args[@]}" + fi } main "$@" +unset main -# unbootstrap +unbootstrap diff --git a/.glue/actions/auto/util-release-pre.sh b/.glue/actions/auto/util-release-pre.sh index 0673c80..5d3564a 100755 --- a/.glue/actions/auto/util-release-pre.sh +++ b/.glue/actions/auto/util-release-pre.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash +eval "$GLUE_BOOTSTRAP" +bootstrap || exit # @file util-release-pre.sh # @brief Steps to perform before specialized version bumping -# @description Before the release is made, this ensures there -# are no changes in the working directory, and from the version -# in 'glue-auto.toml', increments the version. This does not handle -# anything language specific, so this is usually called along with -# 'util-release-post.sh', and any other files that need version bumping -# is performed in the interum +# @description This does the following +# - Ensures a clean Git working tree +# - Ensures a shared history (no force pushing) +# - Update version in 'glue-auto.toml' unset main main() { @@ -17,12 +17,12 @@ main() { local -r dryStatus="$1" isDry() { # must be set to 'notDry' to not be dry. - # Defaults to 'not try' + # Defaults to 'not dry' [ "$dryStatus" != "notDry" ] } if isDry; then - log.info "Running release process in dry mode" + log.info "Running pre-release process in dry mode" fi # Ensure working tree not dirty @@ -55,10 +55,8 @@ main() { # glue useAction(util-get-version.sh) util.get_action "util-get-version.sh" source "$REPLY" - newVersion="$REPLY-DRY" + newVersion="$REPLY" else - # Prompt for new version - # Get current version toml.get_key version glue-auto.toml local currentVersion="$REPLY" @@ -72,7 +70,7 @@ main() { # Ensure new version is valid (does not already exist) if [ -n "$(git tag -l "v$newVersion")" ]; then - # TODO: ensure there are no tag sthat exists that are greater than it + # TODO: ensure there are no tags that exists that are greater than it die 'Version already exists in a Git tag' fi fi @@ -81,3 +79,6 @@ main() { } main "$@" +unset main + +unbootstrap diff --git a/.glue/commands/auto/Bash.build.sh b/.glue/commands/auto/Bash.build.sh index f5d56da..3095971 100755 --- a/.glue/commands/auto/Bash.build.sh +++ b/.glue/commands/auto/Bash.build.sh @@ -2,11 +2,13 @@ eval "$GLUE_BOOTSTRAP" bootstrap || exit -# glue useAction(util-release-pre.sh) -util.get_action 'util-release-pre.sh' -source "$REPLY" 'dry' -newVersion="$REPLY" +# glue useAction(util-get-version.sh) +util.get_action 'util-get-version.sh' +source "$REPLY" +declare newVersion="$REPLY" -sed -ie "s|\(version[ \t]*=[ \t]*\"\).*\(\"\)|\1${newVersion}\2|g" glue-auto.toml +# glue useAction(util-Bash-version-bump.sh) +util.get_action 'util-Bash-version-bump.sh' +source "$REPLY" "$newVersion" unbootstrap diff --git a/.glue/commands/auto/Bash.release.sh b/.glue/commands/auto/Bash.release.sh index 55bc409..a514a0d 100755 --- a/.glue/commands/auto/Bash.release.sh +++ b/.glue/commands/auto/Bash.release.sh @@ -2,13 +2,18 @@ eval "$GLUE_BOOTSTRAP" bootstrap || exit +# # glue useAction(util-release-pre.sh) util.get_action 'util-release-pre.sh' source "$REPLY" 'notDry' newVersion="$REPLY" -# TODO: generalize -sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1${newVersion}\2|g" glue.sh || : +# Bash version bump +( + find . -ignore_readdir_race -regex '\./pkg/.*\.\(sh\|bash\)' -print0 \ + | xargs -r0 \ + sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1${newVersion}\2|g" || : +) || exit # glue useAction(util-release-post.sh) util.get_action 'util-release-post.sh' diff --git a/.glue/commands/auto/Bash.releaseDry.sh b/.glue/commands/auto/Bash.releaseDry.sh index 111fdd5..cc598ee 100755 --- a/.glue/commands/auto/Bash.releaseDry.sh +++ b/.glue/commands/auto/Bash.releaseDry.sh @@ -7,8 +7,12 @@ util.get_action 'util-release-pre.sh' source "$REPLY" 'dry' newVersion="$REPLY" -# TODO: generalize -sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1${newVersion}\2|g" glue.sh || : +# Bash version bump +( + find . -ignore_readdir_race -regex '\./pkg/.*\.\(sh\|bash\)' -print0 \ + | xargs -r0 \ + sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1${newVersion}\2|g" || : +) || exit # glue useAction(util-release-post.sh) util.get_action 'util-release-post.sh' diff --git a/.glue/commands/auto/Bash.run.sh b/.glue/commands/auto/Bash.run.sh index 6bf7506..d016b56 100755 --- a/.glue/commands/auto/Bash.run.sh +++ b/.glue/commands/auto/Bash.run.sh @@ -2,40 +2,24 @@ eval "$GLUE_BOOTSTRAP" bootstrap || exit -dirty= -if [ -n "$(git status --porcelain)" ]; then - dirty=yes +declare cmdName="$1" +ensure.nonZero 'cmdName' "$cmdName" +shift + +if [ -d pkg ]; then + cd pkg || error.cd_failed fi -if version="$(git describe --match 'v*' --abbrev=0 2>/dev/null)"; then - version="${version/#v/}" +declare execPath="$PWD/bin/$cmdName" +if [ -f "$execPath" ]; then + if [ -x "$execPath" ]; then + "$execPath" "$@" + else + error.not_executable "$execPath" + fi else - version="0.0.0" + echo "Executable file '$execPath' not found" fi -id="$(git rev-parse --short HEAD)" -version+="+$id${dirty:+-DIRTY}" - -sed -i -e "s|\(version=\"\).*\(\"\)|\1${version}\2|g" glue.toml - -# TODO: exec project - -# if [ -f Taskfile.yml ]; then -# if command -v go-task &>/dev/null; then -# go-task run "$@" -# elif command -v task &>/dev/null; then -# if ! task help | grep -q Taskwarrior; then -# task run "$@" -# else -# ensure.cmd 'go-task' -# fi -# else -# ensure.cmd 'go-task' -# fi -# elif [ -f Justfile ]; then -# ensure.cmd 'just' - -# just run "$@" -# fi unbootstrap diff --git a/.glue/common/auto/action.sh b/.glue/common/auto/action.sh index ca8da40..c9044c3 100644 --- a/.glue/common/auto/action.sh +++ b/.glue/common/auto/action.sh @@ -11,10 +11,25 @@ action.log() { local currentAction="${BASH_SOURCE[2]}" local currentActionDirname="${currentAction%/*}" - # TODO: improve output + shopt -q extglob + local extGlobExitStatus=$? + shopt -s extglob + if [ "${currentActionDirname##*/}" = auto ]; then - echo ":: :: RUNNING ACTION -> auto/${currentAction##*/}" + if [[ "${LANG,,?}" == *utf?(-)8 ]]; then + echo "■■■■ 🢂 START ACTION -> auto/${currentAction##*/}" + else + echo ":::: => START ACTION -> auto/${currentAction##*/}" + fi else - echo ":: :: RUNNING ACTION -> ${currentAction##*/}" + if [[ "${LANG,,?}" == *utf?(-)8 ]]; then + echo "■■■■ 🢂 START ACTION -> ${currentAction##*/}" + else + echo ":::: => START ACTION -> ${currentAction##*/}" + fi + fi + + (( extGlobExitStatus != 0 )) && shopt -u extglob + } diff --git a/.glue/common/auto/bootstrap.sh b/.glue/common/auto/bootstrap.sh index 7d30f8a..23840fc 100644 --- a/.glue/common/auto/bootstrap.sh +++ b/.glue/common/auto/bootstrap.sh @@ -109,11 +109,20 @@ unbootstrap() { # Print case "$dir" in - actions) - echo ":: :: END ACTION" - ;; commands) - echo ":: END COMMAND" + if [[ "${LANG,,?}" == *utf?(-)8 ]]; then + echo "■■ 🢂 END COMMAND" + else + echo ":: => END COMMAND" + fi + + ;; + actions) + if [[ "${LANG,,?}" == *utf?(-)8 ]]; then + echo "■■■■ 🢂 END ACTION" + else + echo ":::: => END ACTION" + fi ;; *) die "boostrap: Directory '$dir' not supported" diff --git a/.glue/common/auto/command.sh b/.glue/common/auto/command.sh index bc3b61b..2b4d818 100644 --- a/.glue/common/auto/command.sh +++ b/.glue/common/auto/command.sh @@ -4,13 +4,20 @@ command.log() { # Path to the currently actually executing 'action' script # This works on the assumption that 'source's are all absolute paths - local currentAction="${BASH_SOURCE[2]}" - local currentActionDirname="${currentAction%/*}" + local currentCommand="${BASH_SOURCE[2]}" + local currentCommandDirname="${currentCommand%/*}" - # TODO: improve output - if [ "${currentActionDirname##*/}" = auto ]; then - echo ":: RUNNING COMMAND -> auto/${currentAction##*/}" + if [ "${currentCommandDirname##*/}" = auto ]; then + if [[ "${LANG,,?}" == *utf?(-)8 ]]; then + echo "■■ 🢂 START COMMAND -> auto/${currentCommand##*/}" + else + echo ":: => START COMMAND -> auto/${currentCommand##*/}" + fi else - echo "::: RUNNING COMMAND -> ${currentAction##*/}" + if [[ "${LANG,,?}" == *utf?(-)8 ]]; then + echo "■■ 🢂 START COMMAND -> ${currentCommand##*/}" + else + echo ":: => START COMMAND -> ${currentCommand##*/}" + fi fi } diff --git a/.glue/common/auto/error.sh b/.glue/common/auto/error.sh index ea33008..e5adaa7 100644 --- a/.glue/common/auto/error.sh +++ b/.glue/common/auto/error.sh @@ -15,9 +15,13 @@ error.cd_failed() { } error.not_supported() { - die "Argument '$*' not supported" + die "Argument '$1' not supported" } error.empty() { die "Argument '$1' is empty" } + +error.not_executable() { + die "File '$1' is not marked as executable" +} diff --git a/.glue/configs/auto/tool-makepkg/dev/PKGBUILD b/.glue/configs/auto/result-pacman-package/dev/PKGBUILD similarity index 50% rename from .glue/configs/auto/tool-makepkg/dev/PKGBUILD rename to .glue/configs/auto/result-pacman-package/dev/PKGBUILD index 2d0b282..ec9d36f 100644 --- a/.glue/configs/auto/tool-makepkg/dev/PKGBUILD +++ b/.glue/configs/auto/result-pacman-package/dev/PKGBUILD @@ -1,4 +1,4 @@ -# Maintainer: '' <> +# Maintainer: pkgname='' pkgver='' pkgrel='1' @@ -10,28 +10,20 @@ depends=('bash') source=($pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz) sha256sums=() -build() { - # TODO: bootstrap - # TODO: assume package already built - # ~/repos/glue/glue.sh cmd build - : -} - check() { # TODO: bootstrap ~/repos/glue/glue.sh cmd test } package() { - mv "$pkgname" "$pkgname-$pkgver" cd "$pkgname-$pkgver" mkdir -p "$pkgdir/usr/bin" - find ./bin/ -ignore_readdir_race -print0 \ - | xargs -r0I '{}' -- cp -r '{}' "$pkgdir/usr/bin" + find ./pkg/bin/ -ignore_readdir_race -print0 \ + | xargs -r0I '{}' -- cp -ar '{}' "$pkgdir/usr/bin" chmod +x "$pkgdir/usr/bin" mkdir -p "$pkgdir/usr/lib/$pkgname" - find ./lib/ -ignore_readdir_race -print0 \ - | xargs -r0I '{}' -- cp -r '{}' "$pkgdir/usr/lib/$pkgname" + find ./pkg/lib/ -ignore_readdir_race -print0 \ + | xargs -r0I '{}' -- cp -ar '{}' "$pkgdir/usr/lib/$pkgname" } diff --git a/.glue/configs/auto/tool-makepkg/release/PKGBUILD b/.glue/configs/auto/result-pacman-package/release/PKGBUILD similarity index 100% rename from .glue/configs/auto/tool-makepkg/release/PKGBUILD rename to .glue/configs/auto/result-pacman-package/release/PKGBUILD diff --git a/.glue/configs/auto/tool-makepkg/toast.yml b/.glue/configs/auto/result-pacman-package/toast.yml similarity index 100% rename from .glue/configs/auto/tool-makepkg/toast.yml rename to .glue/configs/auto/result-pacman-package/toast.yml diff --git a/glue-auto.toml b/glue-auto.toml index bf3abfc..36cee1c 100644 --- a/glue-auto.toml +++ b/glue-auto.toml @@ -1 +1 @@ -version = "0.6.1+60b27e7-DIRTY-DRY" +version = "0.6.2+a151090-DIRTY" diff --git a/glue-auto.tomle b/glue-auto.tomle deleted file mode 100644 index bf3abfc..0000000 --- a/glue-auto.tomle +++ /dev/null @@ -1 +0,0 @@ -version = "0.6.1+60b27e7-DIRTY-DRY" diff --git a/glue.toml b/glue.toml index bc20b74..c311c40 100644 --- a/glue.toml +++ b/glue.toml @@ -1,3 +1,6 @@ -name = "bash-args" -desc = "A cute little Bash library for blazing fast argument parsing" using = "Bash" + +name = "Edwin Kofler" +email = "edwin@kofler.dev" +project = "bash-args" +desc = "A cute little Bash library for blazing fast argument parsing" diff --git a/pkg/bin/args.parse b/pkg/bin/args.parse index 6608c54..be1f123 100755 --- a/pkg/bin/args.parse +++ b/pkg/bin/args.parse @@ -43,4 +43,4 @@ else exit 1 fi -source "$ARGS_LIB_DIR/args.parse.sh" +source "$ARGS_LIB_DIR/cmd/args.parse.sh" diff --git a/pkg/bin/bash-args b/pkg/bin/bash-args index abeb399..17cc829 100755 --- a/pkg/bin/bash-args +++ b/pkg/bin/bash-args @@ -43,4 +43,4 @@ else exit 1 fi -source "$ARGS_LIB_DIR/bash-args.sh" +source "$ARGS_LIB_DIR/cmd/bash-args.sh" diff --git a/pkg/lib/args.parse.sh b/pkg/lib/cmd/args.parse.sh similarity index 100% rename from pkg/lib/args.parse.sh rename to pkg/lib/cmd/args.parse.sh diff --git a/pkg/lib/bash-args.sh b/pkg/lib/cmd/bash-args.sh similarity index 59% rename from pkg/lib/bash-args.sh rename to pkg/lib/cmd/bash-args.sh index ba0dcfa..f0481ad 100644 --- a/pkg/lib/bash-args.sh +++ b/pkg/lib/cmd/bash-args.sh @@ -2,17 +2,11 @@ source "$ARGS_LIB_DIR/util/util.sh" -declare -r PROGRAM_VERSION="0.5.0" +declare -r PROGRAM_VERSION="0.6.2+a151090-DIRTY" bash-args-main() { local flag="${1:-}" - # Cannot use 'args.parse' because it assumes it has been - # installed to PATH. It may not, in the case of development - # Additionally, if the consumer wishes to pre-source the - # files and use 'args.parse' as a function (as opposed to a - # 'args.parse' file source), we don't want to use 'args.parse' - # for speed reasons (double invocation) (TODO: update docs) if [ "$flag" = --version ]; then bash-args-show-version elif [ "$flag" = --help ]; then