@@ -4,30 +4,47 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
4
4
5
5
template_file=template.rb
6
6
if [[ ! -f " $template_file " ]]; then
7
- echo " Formula template is missing: $template_file "
8
- exit 1
7
+ echo " Formula template is missing: $template_file "
8
+ exit 1
9
9
fi
10
10
11
+ repo_root=" $( git rev-parse --show-toplevel) "
12
+ repo_name=" $( basename " $repo_root " ) "
13
+
11
14
# Mock GitHub Actions env
12
- GITHUB_REPOSITORY=anttiharju/vmatch
15
+ GITHUB_REPOSITORY=" anttiharju/$repo_name "
16
+ TAG=" $( git tag --sort=-creatordate | head -n1) "
13
17
14
- # Mock what would normally be provided by release job so we can run this locally
15
- TAG=" $( basename " $( gh api " repos/$GITHUB_REPOSITORY /releases/latest" --jq .tarball_url) " ) "
18
+ # Check if we need to download binaries by comparing cached tag with latest release tag
19
+ tag_cache_file=" $repo_root /tag"
20
+ cached_tag=" "
21
+ [[ -f " $tag_cache_file " ]] && cached_tag=" $( cat " $tag_cache_file " ) "
16
22
17
- # Cache logic for faster iteration
23
+ # Cache logic for faster template iteration
18
24
cache_file=values.cache
19
25
quick_mode=false
20
26
[[ " $* " =~ " --quick " ]] && quick_mode=true
21
27
22
28
set -a
23
29
if [[ " $quick_mode " == true ]] && [[ -f " $cache_file " ]]; then
24
- echo " Using cached values from $cache_file "
25
- cat " $cache_file "
30
+ echo " Using cached values from $cache_file "
31
+ cat " $cache_file "
26
32
else
27
- echo " Generating fresh values"
28
- gh release download " $TAG " --pattern ' vmatch-*64.tar.gz'
29
- mv vmatch-* 64.tar.gz ../../
30
- source values.bash | tee " $cache_file "
33
+ echo " Generating fresh values"
34
+
35
+ # Only download binaries if the tag has changed or cache doesn't exist
36
+ if [[ " $cached_tag " != " $TAG " ]]; then
37
+ echo " New release detected: $TAG (was: ${cached_tag:- none} )"
38
+ gh release download " $TAG " --pattern " $repo_name -*64.tar.gz"
39
+ find . -name " $repo_name -*64.tar.gz" -exec mv {} " $repo_root /" \;
40
+
41
+ # Cache the latest tag
42
+ echo " $TAG " > " $tag_cache_file "
43
+ else
44
+ echo " Using cached binaries for tag: $TAG "
45
+ fi
46
+
47
+ source values.bash | tee " $cache_file "
31
48
fi
32
49
33
50
# Cache file is gitignored and we cannot guarantee its existence
@@ -36,15 +53,15 @@ source "$cache_file"
36
53
set +a
37
54
38
55
# Template
39
- envsubst < " $template_file " > vmatch.rb
56
+ envsubst < " $template_file " > " . $repo_name .rb "
40
57
41
58
local_tap=false
42
59
[[ " $* " =~ " --local-tap " ]] && local_tap=true
43
60
if [[ " $local_tap " == true ]]; then
44
- dir=../../ Formula
45
- mkdir -p " $dir "
46
- cp vmatch.rb " $dir "
61
+ dir=" $repo_root / Formula"
62
+ mkdir -p " $dir "
63
+ cp " . $repo_name .rb " " $dir "
47
64
fi
48
65
49
66
# Easier visual diffing
50
- cp " $template_file " vmatch. template.rb
67
+ cp " $template_file " " . $repo_name . template.rb"
0 commit comments