-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-release-assets
executable file
·84 lines (75 loc) · 2.58 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
#!/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
DIE() {
echo "ERROR: ""$1" >&2
echo "Usage: $0 TAG asset(s)" >&2
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 existing_tags
# 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 [ 1 -eq 1 ] ; then
for asset in "$@" ; do
test -r "$asset" || DIE "asset '$asset' does not exist."
assets+=("-a" "$asset")
[ $quietly = no ] && echo "adding asset $(basename "$asset")" >&2
done
if [ $quietly = no ] ; then
hub release edit "${assets[@]}" -m "" "$TAG"
else
hub release edit "${assets[@]}" -m "" "$TAG" 2> /dev/null
fi
else
for asset in "$@" ; do
test -r "$asset" || DIE "asset '$asset' does not exist."
if [ -z "$(release-asset-names "$TAG" "$asset")" ] ; then
[ $quietly = no ] && echo "adding asset $(basename "$asset") to '$TAG'" >&2
hub release edit -a "$asset" -m "" "$TAG"
sleep 0.5
else
DIE "asset '$asset' already exists at github!?"
fi
done
fi
}
Main "$@"