Skip to content

Commit c996229

Browse files
committed
feat: allow using git sha versions
1 parent bc8e0d4 commit c996229

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

scripts/build_rust_package.sh

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,30 @@ build_rust_package() {
1818
return
1919
fi
2020

21-
# If binary is cached, skip compilation
22-
local cached_binary="$BUILDDIR/${package}-${version#${package}/}/${package}"
23-
if [ -f "$cached_binary" ]; then
24-
echo "Using cached binary for $package version $version"
25-
cp "$cached_binary" "$dest_path"
26-
return
27-
fi
28-
2921
# Clone the repository
3022
local build_dir="$BUILDROOT/build/$package"
3123
mkdir -p "$build_dir"
24+
set +x
25+
echo "Cloning ${git_url}"
3226
if [ -f "$BUILDDIR/.ghtoken" ]; then
33-
set +x
34-
git clone --depth 1 --branch "$version" "${git_url/#https:\/\/github.com/https:\/\/x-access-token:$( cat $BUILDDIR/.ghtoken )@github.com}" "$build_dir"
35-
set -x
36-
else
37-
git clone --depth 1 --branch "$version" "$git_url" "$build_dir"
27+
git_url="${git_url/#https:\/\/github.com/https:\/\/x-access-token:$( cat $BUILDDIR/.ghtoken )@github.com}"
28+
fi
29+
git clone --depth 1 --branch "$version" "$git_url" "$build_dir" || (
30+
echo "Could not clone branch/tag, attempting to checkout the commit by sha"
31+
git clone "$git_url" "$build_dir" && \
32+
git -C "$build_dir" checkout "$version"
33+
)
34+
set -x
35+
36+
# Get the git reference
37+
local git_describe=$( git -C "$build_dir" describe --tags --always )
38+
39+
# If binary is cached, skip compilation
40+
local cached_binary="$BUILDDIR/${package}-${git_describe#${package}/}/${package}"
41+
if [ -f "$cached_binary" ]; then
42+
echo "Using cached binary for $package version $version"
43+
cp "$cached_binary" "$dest_path"
44+
return
3845
fi
3946

4047
# Define Rust flags for reproducibility

scripts/make_git_package.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,25 @@ make_git_package() {
1010
# All remaining arguments are artifact mappings in src:dest format
1111

1212
mkdir -p "$DESTDIR/usr/bin"
13-
local cache_dir="$BUILDDIR/${package}-${version}"
13+
14+
# Clone the repository
15+
local build_dir="$BUILDROOT/build/$package"
16+
set +x
17+
echo "Cloning ${git_url}"
18+
if [ -f "$BUILDDIR/.ghtoken" ]; then
19+
git_url="${git_url/#https:\/\/github.com/https:\/\/x-access-token:$( cat $BUILDDIR/.ghtoken )@github.com}"
20+
fi
21+
git clone --depth 1 --branch "$version" "$git_url" "$build_dir" || (
22+
echo "Could not clone branch/tag, attempting to checkout the commit by sha"
23+
git clone -"$git_url" "$build_dir" &&
24+
git -C "$build_dir" checkout "$version"
25+
)
26+
set -x
27+
28+
# Get the git reference
29+
local git_describe=$( git -C "$build_dir" describe --tags --always )
30+
31+
local cache_dir="$BUILDDIR/${package}-${git_describe#${package}/}"
1432

1533
# Use cached artifacts if available
1634
if [ -n "$cache_dir" ] && [ -d "$cache_dir" ] && [ "$(ls -A "$cache_dir" 2>/dev/null)" ]; then
@@ -30,14 +48,6 @@ make_git_package() {
3048
fi
3149

3250
# Build from source
33-
local build_dir="$BUILDROOT/build/$package"
34-
if [ -f "$cache_dir/.ghtoken" ]; then
35-
set +x
36-
git clone --depth 1 --branch "$version" "${git_url/#https:\/\/github.com/https:\/\/x-access-token:$( cat $cache_dir/.ghtoken )@github.com}" "$build_dir"
37-
set -x
38-
else
39-
git clone --depth 1 --branch "$version" "$git_url" "$build_dir"
40-
fi
4151
mkosi-chroot bash -c "cd '/build/$package' && $build_cmd"
4252

4353
# Copy artifacts to image and cache

0 commit comments

Comments
 (0)