Skip to content

Commit

Permalink
feat(plugins): support plugin specs in slug@branch format
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lotem committed Jun 5, 2022
1 parent ffdcc3c commit 7d11455
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 16 deletions.
20 changes: 12 additions & 8 deletions action-install-plugins-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ export RIME_ROOT="$(cd "$(dirname "$0")"; pwd)"
echo "RIME_PLUGINS=${RIME_PLUGINS}" > version-info.txt
echo "librime $(git describe --always)" >> version-info.txt

function action_install_plugin() {
local plugin="$1"
local plugin_dir="$2"
echo "${plugin} $(git -C "${plugin_dir}" describe --always)" >> version-info.txt
if [[ -e "${plugin_dir}/action-install.sh" ]]; then
(cd "${plugin_dir}"; bash ./action-install.sh)
fi
}

declare -fx action_install_plugin

if [[ -n "${RIME_PLUGINS}" ]]; then
# intentionally unquoted: ${RIME_PLUGINS} is a space separated list of slugs
bash ./install-plugins.sh ${RIME_PLUGINS}
for plugin_dir in plugins/*; do
[[ -d "${plugin_dir}" ]] || continue
echo "${plugin_dir} $(git -C "${plugin_dir}" describe --always)" >> version-info.txt
if [[ -e "${plugin_dir}/action-install.sh" ]]; then
(cd "${plugin_dir}"; bash ./action-install.sh)
fi
done
bash ./install-plugins.sh run=action_install_plugin ${RIME_PLUGINS}
fi
30 changes: 26 additions & 4 deletions action-install-plugins-windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ setlocal

if not defined RIME_ROOT set RIME_ROOT=%CD%

rem for GitHub pull request #1, git checkout 1/merge
set clone_options=^
--config "remote.origin.fetch=+refs/pull/*:refs/remotes/origin/*" ^
--depth 1 ^
--no-single-branch

echo RIME_PLUGINS=%RIME_PLUGINS% > version-info.txt
echo librime >> version-info.txt
git describe --always >> version-info.txt
Expand All @@ -12,13 +18,29 @@ if defined RIME_PLUGINS (
exit /b

:install_plugin
set slug=%1
echo plugin: %slug%
set plugin=%1
echo plugin: %plugin%
for /f "delims=@" %%i in ("%plugin%") do (
set slug=%%i
goto :got_slug
)
:got_slug
if %slug% == %plugin% (
set branch=
) else (
set branch=%plugin:*@=%
)
set plugin_project=%slug:*/=%
set plugin_dir=plugins\%plugin_project:librime-=%
git clone --depth 1 "https://github.com/%slug%.git" %plugin_dir%
git clone %clone_options% "https://github.com/%slug%.git" %plugin_dir%
if errorlevel 1 exit /b
echo %plugin_dir% >> version-info.txt
rem pull request ref doesn't work with git clone --branch
if not [%branch%] == [] (
git -C %plugin_dir% checkout %branch%
if errorlevel 1 exit /b
)
:action_install_plugin
echo %plugin% >> version-info.txt
git -C %plugin_dir% describe --always >> version-info.txt
if exist %plugin_dir%\action-install.bat (
pushd %plugin_dir%
Expand Down
41 changes: 37 additions & 4 deletions install-plugins.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
#!/bin/bash

set -e

cd "$(dirname "$0")"

for slug in "$@"
clone_options=(
# for GitHub pull request #1, git checkout 1/merge
--config 'remote.origin.fetch=+refs/pull/*:refs/remotes/origin/*'
# shallow clone
--depth 1
# fetch all branches
--no-single-branch
)

if [[ "${1}" =~ run=.* ]]; then
custom_install="${1#run=}"
shift
fi

for plugin in "$@"
do
if [[ "${plugin}" =~ @ ]]; then
slug="${plugin%@*}"
branch="${plugin#*@}"
else
slug="${plugin}"
branch=''
fi
plugin_project="${slug##*/}"
plugin_dir="plugins/${plugin_project#librime-}"
if [[ -d "${plugin_dir}" ]]
then
echo "Updating plugin: ${plugin_dir}"
git -C "${plugin_dir}" checkout master
echo "Updating ${plugin} in ${plugin_dir}"
if [[ -n "${branch}" ]]; then
git -C "${plugin_dir}" checkout "${branch}"
fi
git -C "${plugin_dir}" pull
else
git clone --depth 1 "https://github.com/${slug}.git" "${plugin_dir}"
echo "Checking out ${plugin} to ${plugin_dir}"
git clone "${clone_options[@]}" "https://github.com/${slug}.git" "${plugin_dir}"
# pull request ref doesn't work with git clone --branch
if [[ -n "${branch}" ]]; then
git -C "${plugin_dir}" checkout "${branch}"
fi
fi
if [[ -n "${custom_install}" ]]; then
${custom_install} "${plugin}" "${plugin_dir}"
fi
done
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if(DEFINED ENV{RIME_PLUGINS})
set(plugins $ENV{RIME_PLUGINS})
message(STATUS "Prescribed plugins: ${plugins}")
if(NOT "${plugins}" STREQUAL "")
string(REGEX REPLACE "@[^ ]*" "" plugins ${plugins})
string(REGEX REPLACE "[^ ]*/(librime-)?" "" plugins ${plugins})
string(REPLACE " " ";" plugins ${plugins})
endif()
Expand Down

0 comments on commit 7d11455

Please sign in to comment.