Good12313 commited on
Commit
294c471
·
verified ·
1 Parent(s): bad9b3e

Upload 2 files

Browse files
Files changed (1) hide show
  1. scripts/release-common.sh +36 -15
scripts/release-common.sh CHANGED
@@ -1,6 +1,6 @@
1
  #!/bin/sh
2
 
3
- : "${REPO_API_URL:=https://api.github.com/repos/caidaoli/ccload/releases/latest}"
4
  : "${RUNTIME_DIR:=/tmp/runtime}"
5
  : "${RELEASES_DIR:=$RUNTIME_DIR/releases}"
6
  : "${CURRENT_LINK:=$RUNTIME_DIR/current}"
@@ -39,28 +39,49 @@ current_binary_path() {
39
  printf '%s/%s\n' "$CURRENT_LINK" "$CURRENT_BINARY_NAME"
40
  }
41
 
42
- fetch_latest_release_info() {
43
- response=$(curl -fsSL "$REPO_API_URL") || return 1
 
 
 
 
 
 
44
 
45
  tag_name=$(
46
- printf '%s\n' "$response" \
47
- | grep -Eo '"tag_name"[[:space:]]*:[[:space:]]*"[^"]+"' \
48
- | head -n 1 \
49
- | cut -d '"' -f 4 \
50
- || true
51
  )
52
- asset_url=$(
53
- printf '%s\n' "$response" \
54
- | grep -Eo '"browser_download_url"[[:space:]]*:[[:space:]]*"[^"]*"' \
55
- | cut -d '"' -f 4 \
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  | grep -E '/[^/]*linux[-_]amd64(\.tar\.gz)?$' \
57
  | head -n 1 \
58
  || true
59
  )
60
 
61
- if [ -z "$tag_name" ] || [ -z "$asset_url" ]; then
62
- return 1
63
- fi
 
 
 
 
64
 
65
  printf '%s|%s\n' "$tag_name" "$asset_url"
66
  }
 
1
  #!/bin/sh
2
 
3
+ : "${REPO_RELEASES_URL:=https://github.com/caidaoli/ccLoad/releases}"
4
  : "${RUNTIME_DIR:=/tmp/runtime}"
5
  : "${RELEASES_DIR:=$RUNTIME_DIR/releases}"
6
  : "${CURRENT_LINK:=$RUNTIME_DIR/current}"
 
39
  printf '%s/%s\n' "$CURRENT_LINK" "$CURRENT_BINARY_NAME"
40
  }
41
 
42
+ repo_base_url() {
43
+ # Strip a trailing "/releases" (and any trailing slash) to get the repo root.
44
+ printf '%s\n' "$REPO_RELEASES_URL" | sed -E 's#/+$##; s#/releases$##'
45
+ }
46
+
47
+ resolve_latest_tag() {
48
+ # The Atom feed is ordered newest-first and includes prereleases.
49
+ releases_feed=$(curl -fsSL "$(repo_base_url)/releases.atom") || return 1
50
 
51
  tag_name=$(
52
+ printf '%s\n' "$releases_feed" \
53
+ | sed -n 's#.*href="[^"]*/releases/tag/\([^"]*\)".*#\1#p' \
54
+ | head -n 1
 
 
55
  )
56
+
57
+ [ -n "$tag_name" ] || return 1
58
+ printf '%s\n' "$tag_name"
59
+ }
60
+
61
+ fetch_latest_release_info() {
62
+ tag_name=$(resolve_latest_tag) || return 1
63
+
64
+ base_url=$(repo_base_url)
65
+
66
+ # The expanded_assets fragment lists every asset as an <a href="..."> link.
67
+ assets_html=$(curl -fsSL "$base_url/releases/expanded_assets/$tag_name") || return 1
68
+
69
+ asset_path=$(
70
+ printf '%s\n' "$assets_html" \
71
+ | grep -Eo 'href="[^"]*/releases/download/[^"]+"' \
72
+ | cut -d '"' -f 2 \
73
  | grep -E '/[^/]*linux[-_]amd64(\.tar\.gz)?$' \
74
  | head -n 1 \
75
  || true
76
  )
77
 
78
+ [ -n "$asset_path" ] || return 1
79
+
80
+ case "$asset_path" in
81
+ http://*|https://*) asset_url=$asset_path ;;
82
+ /*) asset_url="https://github.com$asset_path" ;;
83
+ *) asset_url="$base_url/$asset_path" ;;
84
+ esac
85
 
86
  printf '%s|%s\n' "$tag_name" "$asset_url"
87
  }