-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-release-assets
executable file
·96 lines (87 loc) · 3.02 KB
/
add-release-assets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
#
# Add release assets (any files) to an existing tagged release in a github repo.
#
# Usage:
# add-release-assets TAG asset-files
# where
# TAG the github release tag (find your git repo tags with command: hub release)
# asset-files the assets to add
#
# Example:
# cd /mygitrepo
# add-release-assets v1.0 /mygitrepoassets/*
# would add all files under /myrepoassets to github for the corresponding repo at /mygitrepo.
#
# Note1: requires packages 'hub' (and 'git') to be installed.
# Note2: working folder must be the github repo folder, not the assets folder.
# Note3: adding an already existing asset (file with the same name) simply overwrites the old one.
#
# The assets can be downloaded from:
# https://github.com/USER/REPONAME/releases/download/TAG
echo2() { echo "$@" >&2 ; }
DIE() {
echo2 "ERROR: ""$1"
echo2 "Usage: $0 TAG asset(s)"
exit 1
}
Main() {
local quietly=no
if [ "$1" = "--quietly" ] ; then
quietly=yes
shift
fi
local TAG="$1"
test -n "$TAG" || DIE "TAG is missing."
test -n "$2" || DIE "assets are missing."
shift 1 # rest of the parameters are the assets
local xx
for xx in hub git ; do
test -x /usr/bin/$xx || DIE "required package '$xx' is not installed."
done
local asset
local assets=()
local coloned=()
local existing_tags
local remo
# Note: we do this in the git folder, not in the asset folder
existing_tags="$(hub release)"
test -n "$existing_tags" || DIE "no existing release tags were found!"
for xx in $existing_tags ; do
test "$TAG" = "$xx" && break
done
test "$TAG" = "$xx" || DIE "TAG '$TAG' is not in existing tags [$existing_tags]"
if true ; then
for asset in "$@" ; do
test -r "$asset" || DIE "asset '$asset' does not exist."
remo=${asset/:/COLON} # convert special chars for github !!
remo=${remo/+/PLUS} # convert special chars for github !!
if [ "$remo" != "$asset" ] ; then
cp "$asset" "$remo"
coloned+=("$remo")
assets+=("-a" "$remo")
else
assets+=("-a" "$asset")
fi
[ $quietly = no ] && echo2 "adding asset $(basename "$asset")"
done
if [ $quietly = no ] ; then
hub release edit "${assets[@]}" -m "" "$TAG"
else
hub release edit "${assets[@]}" -m "" "$TAG" 2> /dev/null
fi
rm -f "${coloned[@]}"
# else
# for asset in "$@" ; do
# test -r "$asset" || DIE "asset '$asset' does not exist."
# if [ -z "$(release-asset-names "$TAG" "$asset")" ] ; then
# [ $quietly = no ] && echo2 "adding asset $(basename "$asset") to '$TAG'"
# hub release edit -a "$asset" -m "" "$TAG"
# sleep 0.5
# else
# DIE "asset '$asset' already exists at github!?"
# fi
# done
fi
}
Main "$@"