Skip to content

Commit 271cf42

Browse files
committed
feat(justfile): pick latest git release via version="latest-git-tag"
1 parent 74b7337 commit 271cf42

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

justfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
version := ''
22
image := 'ghcr.io/linkerd/dev'
3-
_tag := if version != '' { "--tag=" + image + ':' + version } else { "" }
3+
4+
# Auto-detect latest git version if version is 'latest-git-tag'
5+
_version := if version == 'latest-git-tag' {
6+
shell('which git > /dev/null || (echo >&2 "$1error$2: git not available" && exit 1) && git --git-dir="$3/.git" --work-tree="$3" tag -l --sort=-version:refname "v*" | head -n 1', style('error'), NORMAL, justfile_directory())
7+
} else {
8+
version
9+
}
10+
11+
_tag := if _version != '' { "--tag=" + image + ':' + _version } else { "" }
412

513
k3s-image := 'docker.io/rancher/k3s'
614

@@ -26,7 +34,7 @@ build: && _list-if-load
2634
for tgt in {{ targets }} ; do
2735
just output='{{ output }}' \
2836
image='{{ image }}' \
29-
version='{{ version }}' \
37+
version='{{ _version }}' \
3038
_target "$tgt"
3139
done
3240

@@ -36,22 +44,22 @@ _list-if-load:
3644
if [ '{{ load }}' = 'true' ] ; then
3745
just image='{{ image }}' \
3846
targets='{{ targets }}' \
39-
version='{{ version }}' \
47+
version='{{ _version }}' \
4048
list
4149
fi
4250

4351
list:
4452
#!/usr/bin/env bash
4553
set -euo pipefail
46-
if [ -z '{{ version }}' ]; then
54+
if [ -z '{{ _version }}' ]; then
4755
echo "Usage: just version=<version> list" >&2
4856
exit 64
4957
fi
5058
for tgt in {{ targets }} ; do
5159
if [ "$tgt" == "devcontainer" ]; then
52-
docker image ls {{ image }}:{{ version }} | sed 1d
60+
docker image ls {{ image }}:{{ _version }} | sed 1d
5361
else
54-
docker image ls {{ image }}:{{ version }}-$tgt | sed 1d
62+
docker image ls {{ image }}:{{ _version }}-$tgt | sed 1d
5563
fi
5664
done
5765

@@ -100,8 +108,9 @@ _target target='':
100108
@just \
101109
output='{{ output }}' \
102110
image='{{ image }}' \
111+
version='{{ _version }}' \
103112
_build --target='{{ target }}' \
104-
{{ if version == '' { '' } else { '--tag=' + image + ':' + version + if target == 'devcontainer' { '' } else { '-' + target } } }}
113+
{{ if _version == '' { '' } else { '--tag=' + image + ':' + _version + if target == 'devcontainer' { '' } else { '-' + target } } }}
105114

106115
# Build the devcontainer image
107116
_build *args='':

0 commit comments

Comments
 (0)