@@ -4,7 +4,10 @@ set -euo pipefail
4
4
5
5
declare -r tag=" ${INPUT_TAG} "
6
6
7
- declare -r SRC=" $( dirname $( realpath " ${BASH_SOURCE[0]} " ) ) "
7
+ declare -r ROOT_DIR=" $( dirname $( realpath " ${BASH_SOURCE[0]} " ) ) "
8
+ declare -r ARCHIVES_DIR=" ${ROOT_DIR} /.neovim-cache/archives"
9
+ declare -r REPOS_DIR=" ${ROOT_DIR} /.neovim-cache/repos"
10
+ declare -r INSTALLATION_DIR=" ${ROOT_DIR} /neovim"
8
11
9
12
declare platform=" "
10
13
case " ${RUNNER_OS} " in
@@ -19,16 +22,116 @@ case "${RUNNER_OS}" in
19
22
exit 1;
20
23
esac
21
24
22
- declare -r url =" https://github.com/neovim/neovim/releases/download/${tag} /nvim-${platform} .tar.gz"
23
- declare -r filename =$( basename " ${url } " )
25
+ declare -r prebuilt_package_url =" https://github.com/neovim/neovim/releases/download/${tag} /nvim-${platform} .tar.gz"
26
+ declare -r prebuilt_package_filename =$( basename " ${prebuilt_package_url } " )
24
27
25
- mkdir -p " ${SRC} /neovim/.archives "
28
+ declare -r repo_url= " https://github.com/neovim/neovim "
26
29
27
- echo " Downloading archive..."
28
- curl --progress-bar --continue-at - --output " ${SRC} /neovim/.archives/${filename} " -L " ${url} "
30
+ function command_exists() {
31
+ type " ${1} " > /dev/null 2>&1
32
+ }
29
33
30
- echo " Extracting archive..."
31
- tar --strip-components=1 -xzf " ${SRC} /neovim/.archives/${filename} " -C " ${SRC} /neovim"
34
+ function is_darwin() {
35
+ [[ " ${RUNNER_OS} " = " macOS" ]]
36
+ }
32
37
33
- echo " Setting PATH..."
34
- echo " ${SRC} /neovim/bin" >> ${GITHUB_PATH}
38
+ function is_linux() {
39
+ [[ " ${RUNNER_OS} " = " Linux" ]]
40
+ }
41
+
42
+ function setup_apt_packages() {
43
+ local apt_bin=" apt"
44
+ if command_exists apt-fast; then
45
+ apt_bin=" apt-fast"
46
+ fi
47
+ echo " Installing packages: $* "
48
+ sudo $apt_bin install -qq --yes " $@ "
49
+ }
50
+
51
+ function setup_brew_packages() {
52
+ echo " Installing packages: $* "
53
+ printf ' brew "%s"\n' $* | brew bundle --no-lock --file=-
54
+ }
55
+
56
+ function get_latest_reposiotry() {
57
+ mkdir -p " ${REPOS_DIR} "
58
+
59
+ local -r repo_uri=" ${1} "
60
+ local -r repo_dir=" ${2} "
61
+
62
+ echo " Repository URI: ${repo_uri} "
63
+ if [[ ! -d " ${repo_dir} " ]]; then
64
+ echo " Cloning repository..."
65
+ git clone --recursive " ${repo_uri} " " ${repo_dir} "
66
+ pushd " ${repo_dir} " > /dev/null
67
+ else
68
+ echo " Pulling latest commits..."
69
+ pushd " ${repo_dir} " > /dev/null
70
+ git fetch --all --tags
71
+ git submodule update --init
72
+ fi
73
+
74
+ popd > /dev/null
75
+ }
76
+
77
+ function setup_from_source() {
78
+ get_latest_reposiotry " ${repo_url} " " ${REPOS_DIR} /neovim" " ${branch} "
79
+ pushd " ${REPOS_DIR} /neovim" > /dev/null
80
+
81
+ local ref=" stable"
82
+ if git tag --list | grep -q " ${tag} " ; then
83
+ ref=" ${tag} "
84
+ elif test " ${tag} " = " nightly" ; then
85
+ ref=" master"
86
+ fi
87
+ git checkout " ${ref} "
88
+
89
+ echo " Installing dependencies..."
90
+
91
+ if is_darwin; then
92
+ setup_brew_packages ninja libtool automake cmake pkg-config gettext curl
93
+ fi
94
+
95
+ if is_linux; then
96
+ setup_apt_packages ninja-build gettext libtool libtool-bin autoconf automake cmake g++ pkg-config unzip curl
97
+ fi
98
+
99
+ echo " Running build..."
100
+ make distclean
101
+ make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX=" ${INSTALLATION_DIR} " cmake
102
+
103
+ echo " Installing..."
104
+ make install
105
+
106
+ echo " Setting PATH..."
107
+ echo " ${INSTALLATION_DIR} /bin" >> ${GITHUB_PATH}
108
+ }
109
+
110
+ function is_prebuilt_package_available() {
111
+ local status_code=" $( curl -sL --head --write-out " %{http_code}" --output /dev/null " ${prebuilt_package_url} " ) "
112
+ test " ${status_code} " = " 200"
113
+ }
114
+
115
+ function setup_prebuilt_package() {
116
+ if is_prebuilt_package_available; then
117
+ mkdir -p " ${ARCHIVES_DIR} "
118
+
119
+ echo " Downloading archive..."
120
+ curl --progress-bar --continue-at - --output " ${ARCHIVES_DIR} /${prebuilt_package_filename} " -L " ${prebuilt_package_url} "
121
+
122
+ echo " Extracting archive..."
123
+ tar --strip-components=1 -xzf " ${ARCHIVES_DIR} /${prebuilt_package_filename} " -C " ${INSTALLATION_DIR} "
124
+
125
+ echo " Setting PATH..."
126
+ echo " ${INSTALLATION_DIR} /bin" >> ${GITHUB_PATH}
127
+ else
128
+ echo " Prebuilt package for tag '${tag} ' not available!"
129
+ echo " Falling back to source compilation."
130
+ echo
131
+ setup_from_source
132
+ fi
133
+ }
134
+
135
+ mkdir -p " ${INSTALLATION_DIR} "
136
+
137
+ setup_prebuilt_package
0 commit comments