Skip to content

Commit 7d11455

Browse files
committed
feat(plugins): support plugin specs in slug@branch format
after checking out, run a custom function for each plugin. (action-install-plugins-macos.sh): loop over RIME_PLUGINS instead of plugins/* directories; the behaviour is now consistent with the windows script. ci scripts: update version-info.txt to log plugin slugs instead of directories.
1 parent ffdcc3c commit 7d11455

4 files changed

+76
-16
lines changed

action-install-plugins-macos.sh

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ export RIME_ROOT="$(cd "$(dirname "$0")"; pwd)"
55
echo "RIME_PLUGINS=${RIME_PLUGINS}" > version-info.txt
66
echo "librime $(git describe --always)" >> version-info.txt
77

8+
function action_install_plugin() {
9+
local plugin="$1"
10+
local plugin_dir="$2"
11+
echo "${plugin} $(git -C "${plugin_dir}" describe --always)" >> version-info.txt
12+
if [[ -e "${plugin_dir}/action-install.sh" ]]; then
13+
(cd "${plugin_dir}"; bash ./action-install.sh)
14+
fi
15+
}
16+
17+
declare -fx action_install_plugin
18+
819
if [[ -n "${RIME_PLUGINS}" ]]; then
920
# intentionally unquoted: ${RIME_PLUGINS} is a space separated list of slugs
10-
bash ./install-plugins.sh ${RIME_PLUGINS}
11-
for plugin_dir in plugins/*; do
12-
[[ -d "${plugin_dir}" ]] || continue
13-
echo "${plugin_dir} $(git -C "${plugin_dir}" describe --always)" >> version-info.txt
14-
if [[ -e "${plugin_dir}/action-install.sh" ]]; then
15-
(cd "${plugin_dir}"; bash ./action-install.sh)
16-
fi
17-
done
21+
bash ./install-plugins.sh run=action_install_plugin ${RIME_PLUGINS}
1822
fi

action-install-plugins-windows.bat

+26-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ setlocal
22

33
if not defined RIME_ROOT set RIME_ROOT=%CD%
44

5+
rem for GitHub pull request #1, git checkout 1/merge
6+
set clone_options=^
7+
--config "remote.origin.fetch=+refs/pull/*:refs/remotes/origin/*" ^
8+
--depth 1 ^
9+
--no-single-branch
10+
511
echo RIME_PLUGINS=%RIME_PLUGINS% > version-info.txt
612
echo librime >> version-info.txt
713
git describe --always >> version-info.txt
@@ -12,13 +18,29 @@ if defined RIME_PLUGINS (
1218
exit /b
1319

1420
:install_plugin
15-
set slug=%1
16-
echo plugin: %slug%
21+
set plugin=%1
22+
echo plugin: %plugin%
23+
for /f "delims=@" %%i in ("%plugin%") do (
24+
set slug=%%i
25+
goto :got_slug
26+
)
27+
:got_slug
28+
if %slug% == %plugin% (
29+
set branch=
30+
) else (
31+
set branch=%plugin:*@=%
32+
)
1733
set plugin_project=%slug:*/=%
1834
set plugin_dir=plugins\%plugin_project:librime-=%
19-
git clone --depth 1 "https://github.com/%slug%.git" %plugin_dir%
35+
git clone %clone_options% "https://github.com/%slug%.git" %plugin_dir%
2036
if errorlevel 1 exit /b
21-
echo %plugin_dir% >> version-info.txt
37+
rem pull request ref doesn't work with git clone --branch
38+
if not [%branch%] == [] (
39+
git -C %plugin_dir% checkout %branch%
40+
if errorlevel 1 exit /b
41+
)
42+
:action_install_plugin
43+
echo %plugin% >> version-info.txt
2244
git -C %plugin_dir% describe --always >> version-info.txt
2345
if exist %plugin_dir%\action-install.bat (
2446
pushd %plugin_dir%

install-plugins.sh

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,50 @@
11
#!/bin/bash
22

3+
set -e
4+
35
cd "$(dirname "$0")"
46

5-
for slug in "$@"
7+
clone_options=(
8+
# for GitHub pull request #1, git checkout 1/merge
9+
--config 'remote.origin.fetch=+refs/pull/*:refs/remotes/origin/*'
10+
# shallow clone
11+
--depth 1
12+
# fetch all branches
13+
--no-single-branch
14+
)
15+
16+
if [[ "${1}" =~ run=.* ]]; then
17+
custom_install="${1#run=}"
18+
shift
19+
fi
20+
21+
for plugin in "$@"
622
do
23+
if [[ "${plugin}" =~ @ ]]; then
24+
slug="${plugin%@*}"
25+
branch="${plugin#*@}"
26+
else
27+
slug="${plugin}"
28+
branch=''
29+
fi
730
plugin_project="${slug##*/}"
831
plugin_dir="plugins/${plugin_project#librime-}"
932
if [[ -d "${plugin_dir}" ]]
1033
then
11-
echo "Updating plugin: ${plugin_dir}"
12-
git -C "${plugin_dir}" checkout master
34+
echo "Updating ${plugin} in ${plugin_dir}"
35+
if [[ -n "${branch}" ]]; then
36+
git -C "${plugin_dir}" checkout "${branch}"
37+
fi
1338
git -C "${plugin_dir}" pull
1439
else
15-
git clone --depth 1 "https://github.com/${slug}.git" "${plugin_dir}"
40+
echo "Checking out ${plugin} to ${plugin_dir}"
41+
git clone "${clone_options[@]}" "https://github.com/${slug}.git" "${plugin_dir}"
42+
# pull request ref doesn't work with git clone --branch
43+
if [[ -n "${branch}" ]]; then
44+
git -C "${plugin_dir}" checkout "${branch}"
45+
fi
46+
fi
47+
if [[ -n "${custom_install}" ]]; then
48+
${custom_install} "${plugin}" "${plugin_dir}"
1649
fi
1750
done

plugins/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if(DEFINED ENV{RIME_PLUGINS})
2626
set(plugins $ENV{RIME_PLUGINS})
2727
message(STATUS "Prescribed plugins: ${plugins}")
2828
if(NOT "${plugins}" STREQUAL "")
29+
string(REGEX REPLACE "@[^ ]*" "" plugins ${plugins})
2930
string(REGEX REPLACE "[^ ]*/(librime-)?" "" plugins ${plugins})
3031
string(REPLACE " " ";" plugins ${plugins})
3132
endif()

0 commit comments

Comments
 (0)