Skip to content

Commit 32a8aa0

Browse files
committed
refactor: move commands to subdir 'lib/cmd'
This also comes with an update to the Glue scripts, which I couldn't really avoid
1 parent a151090 commit 32a8aa0

23 files changed

+206
-148
lines changed

.glue/actions/auto/result-pacman-package.sh

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,56 @@ main() {
1313
ensure.file glue.toml
1414
ensure.file glue-auto.toml
1515

16-
# TODO: use function
17-
mkdir -p .glue/generated/tool-makepkg
16+
toml.get_key project glue.toml
17+
local myProject="$REPLY"
1818

19-
# TODO: get these values somewhere else
20-
toml.get_key name glue.toml
21-
local myPkg="$REPLY"
22-
local myName="Edwin Kofler"
23-
local myEmail="[email protected]"
2419
toml.get_key desc glue.toml
2520
local myDesc="$REPLY"
2621

22+
toml.get_key name glue.toml
23+
local myName="$REPLY"
24+
25+
toml.get_key email glue.toml
26+
local myEmail="$REPLY"
27+
2728
toml.get_key version glue-auto.toml
28-
local myVer="$REPLY"
29-
myVer="${myVer/-/_}"
29+
local myVer="$REPLY"; myVer="${myVer/-/_}"
3030

31+
ensure.nonZero 'myProject' "$myProject"
32+
ensure.nonZero 'myDesc' "$myDesc"
33+
ensure.nonZero 'myName' "$myName"
34+
ensure.nonZero 'myEmail' "$myEmail"
3135
ensure.nonZero 'myVer' "$myVer"
32-
# glue useConfig(tool-makepkg)
33-
util.get_config "tool-makepkg/dev/PKGBUILD"
36+
37+
# glue useConfig(result-pacman-package)
38+
util.get_config "result-pacman-package/dev/PKGBUILD"
3439
pkgbuildFile="$REPLY"
3540

3641
generated.in 'result-pacman-package'
3742
(
38-
mkdir -p .glue/generated/tool-makepkg/dev
39-
cd .glue/generated/tool-makepkg/dev || error.cd_failed
43+
cd "$GENERATED_DIR" || error.cd_failed
44+
mkdir dev
45+
cd dev || error.cd_failed
4046

41-
cp "$pkgbuildFile" .
47+
tar --create --directory "$GLUE_WD" --file "$myProject-$myVer.tar.gz" --exclude './.git' \
48+
--exclude "$myProject-$myVer.tar.gz" --transform "s/^\./$myProject-$myVer/" ./
4249

43-
# TODO: bash templating
50+
cp "$pkgbuildFile" .
4451
sed -i -e "s/# Maintainer:.*/# Maintainer: $myName <$myEmail>/g" PKGBUILD
45-
sed -i -e "s/pkgname=.*\$/pkgname='$myPkg'/g" PKGBUILD
52+
sed -i -e "s/pkgname=.*\$/pkgname='$myProject'/g" PKGBUILD
4653
sed -i -e "s/pkgver=.*\$/pkgver='$myVer'/g" PKGBUILD
4754
sed -i -e "s/pkgdesc=.*\$/pkgdesc='$myDesc'/g" PKGBUILD
48-
sed -i -e "s/url=.*\$/url='https:\/\/github.com\/eankeen\/$myPkg'/g" PKGBUILD
49-
sed -i -e "s/source=.*\$/source=\(\$pkgname-\$pkgver.tar.gz::http:\/\/localhost:9334\/v\$pkgver.tar.gz\)/g" PKGBUILD
50-
51-
# TODO: assumption on working directory
52-
tar --create --directory "$GLUE_WD" --file "$myPkg-$myVer.tar.gz" ../"$myPkg"
53-
rm -rf "$myPkg-$myVer"
54-
# tar xf "$myPkg-$myVer.tar.gz"
55-
# mv "$myPkg" "$myPkg-$myVer"
56-
# rm -rf "$myPkg-$myVer/.git"
57-
58-
local sum="$(sha256sum "$myPkg-$myVer.tar.gz")"
55+
sed -i -e "s/url=.*\$/url='https:\/\/github.com\/eankeen\/$myProject'/g" PKGBUILD
56+
sed -i -e "s/source=.*\$/source=\(\$pkgname-\$pkgver.tar.gz::\)/g" PKGBUILD
57+
local sum="$(sha256sum "$myProject-$myVer.tar.gz")"
5958
sum="${sum%% *}"
6059
sed -i -e "s/sha256sums=.*\$/sha256sums=\('$sum'\)/g" PKGBUILD
6160

61+
namcap PKGBUILD
6262
makepkg -Cfsrc
63+
namcap ./*.zst
6364
) || exit
6465
generated.out
65-
66-
# TODO: think about more fine grained linting control in the whole SDLC
67-
# namcap PKGBUILD
68-
# namcap ./*.zst
69-
7066
}
7167

7268
main "$@"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
eval "$GLUE_BOOTSTRAP"
3+
bootstrap || exit
4+
5+
unset main
6+
main() {
7+
local newVersion="$1"
8+
ensure.nonZero 'newVersion' "$newVersion"
9+
10+
# TODO: show which files changed
11+
find . -ignore_readdir_race -regex '\./pkg/.*\.\(sh\|bash\)' -print0 2>/dev/null \
12+
| xargs -r0 \
13+
sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1$newVersion\2|g"
14+
log.info "util-Bash-version-bump: Bump done"
15+
}
16+
17+
main "$@"
18+
unset main
19+
20+
unbootstrap

.glue/actions/auto/util-get-version.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bash
2-
eval "$GLUE_BOOTSTRAP"
3-
bootstrap || exit
42

3+
unset main
54
main() {
65
# If the working tree is dirty and there are unstaged changes
76
# for both tracked and untracked files
@@ -24,4 +23,4 @@ main() {
2423
}
2524

2625
main "$@"
27-
unbootstrap
26+
unset main
Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,70 @@
11
#!/usr/bin/env bash
2-
# eval "$GLUE_BOOTSTRAP"
3-
# bootstrap || exit
2+
eval "$GLUE_BOOTSTRAP"
3+
bootstrap || exit
44

55
# @file util-release-post.sh
66
# @brief Steps to perform after specialized version bumping
7+
# - Ensure a dirty Git working tree
8+
# - Add bumped files to commit with version number
9+
# - Make GitHub release
710

811
unset main
912
main() {
1013
local -r dryStatus="$1"
1114
local newVersion="$2"
1215

13-
ensure.nonZero 'newVersion' "$newVersion"
14-
1516
ensure.cmd 'git'
1617
ensure.cmd 'gh'
1718

19+
ensure.nonZero 'newVersion' "$newVersion"
20+
21+
isDry() {
22+
# must be set to 'notDry' to not be dry.
23+
# Defaults to 'not dry'
24+
[ "$dryStatus" != "notDry" ]
25+
}
26+
27+
if isDry; then
28+
log.info "Running release process in dry mode"
29+
fi
30+
1831
# Ensure working tree is dirty
1932
if [ -z "$(git status --porcelain)" ]; then
20-
die 'Working tree is not dirty. Cannot make a release if versions have not been bumped in their respective files'
33+
if isDry; then
34+
local cmd="log.warn"
35+
else
36+
local cmd="die"
37+
fi
38+
39+
"$cmd" 'Working tree is not dirty. Cannot make a release if versions have not been bumped in their respective files'
2140
fi
2241

2342
# Local Release
24-
git add -A
25-
git commit -m "chore(release): v$newVersion"
26-
git tag -a "v$newVersion" -m "Release $newVersion" HEAD
27-
git push --follow-tags origin HEAD
28-
29-
local -a args=()
30-
if [ -f CHANGELOG.md ]; then
31-
args+=("-F" "CHANGELOG.md")
32-
elif [ -f changelog.md ]; then
33-
args+=("-F" "changelog.md")
43+
if isDry; then
44+
log.info "Skipping Git taging and artifact release"
3445
else
35-
# '-F' is required for non-interactivity
36-
args+=("-F" "")
37-
log.warn 'CHANGELOG.md file not found. Creating empty notes file for release'
38-
fi
46+
git add -A
47+
git commit -m "chore(release): v$newVersion"
48+
git tag -a "v$newVersion" -m "Release $newVersion" HEAD
49+
git push --follow-tags origin HEAD
3950

40-
# Remote Release
41-
gh release create "v$newVersion" --target main --title "v$newVersion" "${args[@]}"
51+
local -a args=()
52+
if [ -f CHANGELOG.md ]; then
53+
args+=("-F" "CHANGELOG.md")
54+
elif [ -f changelog.md ]; then
55+
args+=("-F" "changelog.md")
56+
else
57+
# '-F' is required for non-interactivity
58+
args+=("-F" "")
59+
log.warn 'CHANGELOG.md file not found. Creating empty notes file for release'
60+
fi
61+
62+
# Remote Release
63+
gh release create "v$newVersion" --target main --title "v$newVersion" "${args[@]}"
64+
fi
4265
}
4366

4467
main "$@"
68+
unset main
4569

46-
# unbootstrap
70+
unbootstrap

.glue/actions/auto/util-release-pre.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bash
2+
eval "$GLUE_BOOTSTRAP"
3+
bootstrap || exit
24

35
# @file util-release-pre.sh
46
# @brief Steps to perform before specialized version bumping
5-
# @description Before the release is made, this ensures there
6-
# are no changes in the working directory, and from the version
7-
# in 'glue-auto.toml', increments the version. This does not handle
8-
# anything language specific, so this is usually called along with
9-
# 'util-release-post.sh', and any other files that need version bumping
10-
# is performed in the interum
7+
# @description This does the following
8+
# - Ensures a clean Git working tree
9+
# - Ensures a shared history (no force pushing)
10+
# - Update version in 'glue-auto.toml'
1111

1212
unset main
1313
main() {
@@ -17,12 +17,12 @@ main() {
1717
local -r dryStatus="$1"
1818
isDry() {
1919
# must be set to 'notDry' to not be dry.
20-
# Defaults to 'not try'
20+
# Defaults to 'not dry'
2121
[ "$dryStatus" != "notDry" ]
2222
}
2323

2424
if isDry; then
25-
log.info "Running release process in dry mode"
25+
log.info "Running pre-release process in dry mode"
2626
fi
2727

2828
# Ensure working tree not dirty
@@ -55,10 +55,8 @@ main() {
5555
# glue useAction(util-get-version.sh)
5656
util.get_action "util-get-version.sh"
5757
source "$REPLY"
58-
newVersion="$REPLY-DRY"
58+
newVersion="$REPLY"
5959
else
60-
# Prompt for new version
61-
6260
# Get current version
6361
toml.get_key version glue-auto.toml
6462
local currentVersion="$REPLY"
@@ -72,7 +70,7 @@ main() {
7270

7371
# Ensure new version is valid (does not already exist)
7472
if [ -n "$(git tag -l "v$newVersion")" ]; then
75-
# TODO: ensure there are no tag sthat exists that are greater than it
73+
# TODO: ensure there are no tags that exists that are greater than it
7674
die 'Version already exists in a Git tag'
7775
fi
7876
fi
@@ -81,3 +79,6 @@ main() {
8179
}
8280

8381
main "$@"
82+
unset main
83+
84+
unbootstrap

.glue/commands/auto/Bash.build.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
eval "$GLUE_BOOTSTRAP"
33
bootstrap || exit
44

5-
# glue useAction(util-release-pre.sh)
6-
util.get_action 'util-release-pre.sh'
7-
source "$REPLY" 'dry'
8-
newVersion="$REPLY"
5+
# glue useAction(util-get-version.sh)
6+
util.get_action 'util-get-version.sh'
7+
source "$REPLY"
8+
declare newVersion="$REPLY"
99

10-
sed -ie "s|\(version[ \t]*=[ \t]*\"\).*\(\"\)|\1${newVersion}\2|g" glue-auto.toml
10+
# glue useAction(util-Bash-version-bump.sh)
11+
util.get_action 'util-Bash-version-bump.sh'
12+
source "$REPLY" "$newVersion"
1113

1214
unbootstrap

.glue/commands/auto/Bash.release.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
eval "$GLUE_BOOTSTRAP"
33
bootstrap || exit
44

5+
#
56
# glue useAction(util-release-pre.sh)
67
util.get_action 'util-release-pre.sh'
78
source "$REPLY" 'notDry'
89
newVersion="$REPLY"
910

10-
# TODO: generalize
11-
sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1${newVersion}\2|g" glue.sh || :
11+
# Bash version bump
12+
(
13+
find . -ignore_readdir_race -regex '\./pkg/.*\.\(sh\|bash\)' -print0 \
14+
| xargs -r0 \
15+
sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1${newVersion}\2|g" || :
16+
) || exit
1217

1318
# glue useAction(util-release-post.sh)
1419
util.get_action 'util-release-post.sh'

.glue/commands/auto/Bash.releaseDry.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ util.get_action 'util-release-pre.sh'
77
source "$REPLY" 'dry'
88
newVersion="$REPLY"
99

10-
# TODO: generalize
11-
sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1${newVersion}\2|g" glue.sh || :
10+
# Bash version bump
11+
(
12+
find . -ignore_readdir_race -regex '\./pkg/.*\.\(sh\|bash\)' -print0 \
13+
| xargs -r0 \
14+
sed -i -e "s|\(PROGRAM_VERSION=\"\).*\(\"\)|\1${newVersion}\2|g" || :
15+
) || exit
1216

1317
# glue useAction(util-release-post.sh)
1418
util.get_action 'util-release-post.sh'

.glue/commands/auto/Bash.run.sh

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,24 @@
22
eval "$GLUE_BOOTSTRAP"
33
bootstrap || exit
44

5-
dirty=
6-
if [ -n "$(git status --porcelain)" ]; then
7-
dirty=yes
5+
declare cmdName="$1"
6+
ensure.nonZero 'cmdName' "$cmdName"
7+
shift
8+
9+
if [ -d pkg ]; then
10+
cd pkg || error.cd_failed
811
fi
912

10-
if version="$(git describe --match 'v*' --abbrev=0 2>/dev/null)"; then
11-
version="${version/#v/}"
13+
declare execPath="$PWD/bin/$cmdName"
14+
if [ -f "$execPath" ]; then
15+
if [ -x "$execPath" ]; then
16+
"$execPath" "$@"
17+
else
18+
error.not_executable "$execPath"
19+
fi
1220
else
13-
version="0.0.0"
21+
echo "Executable file '$execPath' not found"
1422
fi
1523

16-
id="$(git rev-parse --short HEAD)"
17-
version+="+$id${dirty:+-DIRTY}"
18-
19-
sed -i -e "s|\(version=\"\).*\(\"\)|\1${version}\2|g" glue.toml
20-
21-
# TODO: exec project
22-
23-
# if [ -f Taskfile.yml ]; then
24-
# if command -v go-task &>/dev/null; then
25-
# go-task run "$@"
26-
# elif command -v task &>/dev/null; then
27-
# if ! task help | grep -q Taskwarrior; then
28-
# task run "$@"
29-
# else
30-
# ensure.cmd 'go-task'
31-
# fi
32-
# else
33-
# ensure.cmd 'go-task'
34-
# fi
35-
# elif [ -f Justfile ]; then
36-
# ensure.cmd 'just'
37-
38-
# just run "$@"
39-
# fi
4024

4125
unbootstrap

0 commit comments

Comments
 (0)