Skip to content

Commit 7504473

Browse files
feat: generate habitat artifact version from git tag
1 parent d0ce25d commit 7504473

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

habitat/plan.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pkg_origin="codeforphilly"
22
pkg_name="chime"
3-
pkg_version="0.1.0"
43
pkg_maintainer="Code for Philly <[email protected]>"
54
pkg_license=('MIT')
65
pkg_deps=(
@@ -17,6 +16,39 @@ pkg_bin_dirs=(
1716
)
1817
pkg_svc_user="root"
1918

19+
pkg_version() {
20+
if [ -n "${pkg_last_tag}" ]; then
21+
if [ ${pkg_last_tag_distance} -eq 0 ]; then
22+
echo "${pkg_last_version}"
23+
else
24+
echo "${pkg_last_version}-git+${pkg_last_tag_distance}.${pkg_commit}"
25+
fi
26+
else
27+
echo "${pkg_last_version}-git.${pkg_commit}"
28+
fi
29+
}
30+
31+
do_before() {
32+
do_default_before
33+
34+
# configure git repository
35+
export GIT_DIR="${PLAN_CONTEXT}/../.git"
36+
37+
# load version information from git
38+
pkg_commit="$(git rev-parse --short HEAD)"
39+
pkg_last_tag="$(git describe --tags --abbrev=0 ${pkg_commit} || true 2>/dev/null)"
40+
41+
if [ -n "${pkg_last_tag}" ]; then
42+
pkg_last_version=${pkg_last_tag#v}
43+
pkg_last_tag_distance="$(git rev-list ${pkg_last_tag}..${pkg_commit} --count)"
44+
else
45+
pkg_last_version="0.0.0"
46+
fi
47+
48+
# initialize pkg_version
49+
update_pkg_version
50+
}
51+
2052
do_prepare() {
2153
python -m venv "${pkg_prefix}"
2254
source "${pkg_prefix}/bin/activate"

0 commit comments

Comments
 (0)