-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpublish-gem.sh
More file actions
executable file
·91 lines (78 loc) · 2.42 KB
/
publish-gem.sh
File metadata and controls
executable file
·91 lines (78 loc) · 2.42 KB
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
#!/usr/bin/env bash
if readlink -f . >/dev/null 2>&1 # {{{ makes readlink work on mac
then
readlink=readlink
else
if greadlink -f . >/dev/null 2>&1
then
readlink=greadlink
else
printf "You must install greadlink to use this (brew install coreutils)\n" >&2
fi
fi # }}}
# Set here to the full path to this script
me=${BASH_SOURCE[0]}
[ -L "$me" ] && me=$($readlink -f "$me")
here=$(cd "$(dirname "$me")" && pwd)
root=$(cd "$here/.." && pwd)
just_me=$(basename "$me")
: "${GEM_NAME:=linear-cli}"
: "${GIT_ORG:=rubyists}"
GEM_HOST=$1
: "${GEM_HOST:=rubygems}"
case "$GEM_HOST" in
rubygems)
gem_key='rubygems'
gem_host='https://rubygems.org'
;;
github)
gem_key='github'
gem_host="https://rubygems.pkg.github.com/$GIT_ORG"
# Replace the gem host in the gemspec, so it allows pushing to the GitHub package registry
sed --in-place=.bak -e "s|https://rubygems.org|https://rubygems.pkg.github.com/$GIT_ORG|" "$here/../$GEM_NAME".gemspec
# Restore the original gemspec after the script finishes
trap 'mv -v "$here/../$GEM_NAME".gemspec.bak "$here/../$GEM_NAME".gemspec' EXIT
;;
*)
printf 'Unknown GEM_HOST: %s\n' "$GEM_HOST" >&2
exit 1
;;
esac
# We only want this part running in CI, with no ~/.gem dir
# For local testing, you should have a ~/.gem/credentials file with
# the keys you need to push to rubygems or github
if [ ! -d ~/.gem ]
then
if [ -z "$GEM_TOKEN" ]
then
printf 'No GEM_TOKEN provided, cannot publish\n' >&2
exit 1
fi
mkdir -p ~/.gem
printf '%s\n:%s: %s\n' '---' "$gem_key" "$GEM_TOKEN" > ~/.gem/credentials
chmod 600 ~/.gem/credentials
fi
bundle exec gem build
if [ -f "$here"/../.version.txt ]
then
version=$(<"$here"/../.version.txt)
else
version=$(git describe --tags --abbrev=0 | sed -e 's/^v//')
fi
if [ -z "$version" ]
then
gem="$(ls "$root"/"$GEM_NAME"-*.gem | tail -1)"
else
gem="$(printf '%s/%s-%s.gem' "$root" "$GEM_NAME" "$version")"
fi
if [ ! -f "$gem" ]
then
printf 'No gem file found: %s\n' "$gem" >&2
exit 1
fi
if [[ "${TRACE:-false}" == true || "${ACTIONS_STEP_DEBUG:-false}" == true ]]
then
printf "DEBUG: [%s] Building And Publishing %s to %s\n" "$just_me" "$gem" "$gem_host" >&2
fi
bundle exec gem push -k "$gem_key" --host "$gem_host" "$(basename "$gem")"
# vim: set foldmethod=marker et ts=4 sts=4 sw=4 ft=bash :