aboutsummaryrefslogtreecommitdiff
path: root/fetch_version
diff options
context:
space:
mode:
Diffstat (limited to 'fetch_version')
-rwxr-xr-xfetch_version69
1 files changed, 50 insertions, 19 deletions
diff --git a/fetch_version b/fetch_version
index db0af1b..cbbeb64 100755
--- a/fetch_version
+++ b/fetch_version
@@ -2,7 +2,7 @@
2 2
3usage() { 3usage() {
4 echo "$0 file.json" 4 echo "$0 file.json"
5 echo "$0 [-n|--name name] [-b|--branch branch] [-h|--help] (-u|--url) url" 5 echo "$0 [-n|--name name] [-b|--branch branch] [-f|--file out_file] [-h|--help] (-u|--url) url"
6 exit 6 exit
7} 7}
8 8
@@ -17,6 +17,7 @@ while [[ $# -gt 0 ]]; do
17 name="$(echo "$content" | jq -r ".meta.name")" 17 name="$(echo "$content" | jq -r ".meta.name")"
18 url="$(echo "$content" | jq -r ".meta.url")" 18 url="$(echo "$content" | jq -r ".meta.url")"
19 branch="$(echo "$content" | jq -r ".meta.branch")" 19 branch="$(echo "$content" | jq -r ".meta.branch")"
20 break
20 ;; 21 ;;
21 -n|--name) 22 -n|--name)
22 name=$1 23 name=$1
@@ -30,6 +31,10 @@ while [[ $# -gt 0 ]]; do
30 branch=$1 31 branch=$1
31 shift 32 shift
32 ;; 33 ;;
34 -f|--file)
35 file=$1
36 shift
37 ;;
33 -h|--help) 38 -h|--help)
34 usage 39 usage
35 ;; 40 ;;
@@ -75,26 +80,52 @@ function fetch_github () {
75 tag=${rev:0:7}-$branch 80 tag=${rev:0:7}-$branch
76} 81}
77 82
78fetch_github 2>/dev/null 83function fetch_other () {
84 rev="$(git ls-remote --refs $url refs/heads/$branch | head -n1 | cut -f1)"
85 sha="$(nix-prefetch-git --url $url --rev refs/heads/$branch | jq -r '.sha256')"
86 tag=${rev:0:7}-$branch
87}
79 88
80owner=$(echo "$url" | cut -d"/" -f4) 89case "$url" in
81repo=$(echo "$url" | cut -d"/" -f5) 90 https://*github.com/*)
91 fetch_github 2>/dev/null
92 owner=$(echo "$url" | cut -d"/" -f4)
93 repo=$(echo "$url" | cut -d"/" -f5)
82 94
83F='{ 95 F='{
84 "tag": $tag, 96 "tag": $tag,
85 "meta": { 97 "meta": {
86 "name": $name, 98 "name": $name,
87 "url": $url, 99 "url": $url,
88 "branch": $branch 100 "branch": $branch
89 }, 101 },
90 "github": { 102 "github": {
91 "owner": $owner, 103 "owner": $owner,
92 "repo": $repo, 104 "repo": $repo,
93 "rev": $rev, 105 "rev": $rev,
94 "sha256": $sha, 106 "sha256": $sha,
95 "fetchSubmodules": true 107 "fetchSubmodules": true
96 } 108 }
97}' 109 }'
110 ;;
111 *)
112 fetch_other 2>/dev/null
113 F='{
114 "tag": $tag,
115 "meta": {
116 "name": $name,
117 "url": $url,
118 "branch": $branch
119 },
120 "git": {
121 "url": $url,
122 "rev": $rev,
123 "sha256": $sha,
124 "fetchSubmodules": true
125 }
126 }'
127 ;;
128esac
98 129
99jq -n \ 130jq -n \
100 --arg name "$name" \ 131 --arg name "$name" \