Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tagui update command to automatically fetch latest version of TagUI - done #968

Closed
kensoh opened this issue Mar 15, 2021 · 10 comments
Closed
Assignees
Labels

Comments

@kensoh
Copy link
Member

kensoh commented Mar 15, 2021

No description provided.

@kensoh kensoh added the feature label Mar 15, 2021
@steewel
Copy link

steewel commented Mar 30, 2021

This could be very useful. So we can make a cron and fetch updates more regularly.
In addition i think we could have a tagui -version or even a tagui command alone give back the version number as a response

@kensoh
Copy link
Member Author

kensoh commented Mar 30, 2021

Thanks @steewel, oh yes, when you type tagui without options and parameters it will show the version and options list.

@kensoh
Copy link
Member Author

kensoh commented Mar 30, 2021

However, I don't advise using cron to update regularly. For staging and test environments yes that is ok, but for production best is only put to your production environment what has been tested to be working ok in staging/test.

@kensoh
Copy link
Member Author

kensoh commented Mar 30, 2021

Added your notes from telegram group chat -

about overwriting custom codes over /src... is really something to worry about, but I think if there is a warning or a backup / restore command, that possible problem can be mitigated

@kensoh kensoh self-assigned this May 28, 2021
@kensoh kensoh changed the title Review tagui update command to automatically fetch latest version of TagUI * Review tagui update command to automatically fetch latest version of TagUI Jun 8, 2021
@kensoh kensoh changed the title * Review tagui update command to automatically fetch latest version of TagUI Review tagui update command to automatically fetch latest version of TagUI Jun 8, 2021
@kensoh kensoh changed the title Review tagui update command to automatically fetch latest version of TagUI * Review tagui update command to automatically fetch latest version of TagUI Jun 9, 2021
@kensoh
Copy link
Member Author

kensoh commented Jun 9, 2021

Added PHP code to compare versions and download from master, and also initial entry points from tagui / tagui.cmd -

// return TagUI version of given runner file
function tagui_version($tagui_runner_file) {
$tagui_runner = file_get_contents($tagui_runner_file);
$left_anchor = 'echo "tagui v'; $right_anchor = ': ';
$version_start_pos = strpos($tagui_runner, $left_anchor) + strlen($left_anchor);
$tagui_version = substr($tagui_runner, $version_start_pos);
$version_end_pos = strpos($tagui_version, $right_anchor);
$tagui_version = substr($tagui_version, 0, $version_end_pos); return $tagui_version;}

$tagui_master_version = tagui_version('https://raw.githubusercontent.com/kelaberetiv/TagUI/master/src/tagui');
$tagui_local_version = tagui_version(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tagui');

if (floatval($tagui_local_version) == floatval($tagui_master_version))
echo "You are already using the latest version of TagUI - v" . $tagui_master_version . "\n";
else {echo "Downloading and updating to latest version of TagUI - v" . $tagui_master_version . "\n";

file_put_contents(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "TagUI-master_v" . $tagui_master_version . ".zip",
fopen("https://github.com/kelaberetiv/TagUI/archive/refs/heads/master.zip", 'r'));

Next would be

  • unzipping and setting file permissions (at least for macOS and Linux, to have executable flag)
  • iterating and validating entry points to call php -q tagui_update.php in tagui and tagui.cmd
  • check RPA for Python source code to see if any other things to take note of

@kensoh
Copy link
Member Author

kensoh commented Jun 9, 2021

need to find another path, default PHP does not have the ZipArchive class

<?php
  
// return TagUI version of given runner file
function tagui_version($tagui_runner_file) {
$tagui_runner = file_get_contents($tagui_runner_file);
$left_anchor = 'echo "tagui v'; $right_anchor = ': ';
$version_start_pos = strpos($tagui_runner, $left_anchor) + strlen($left_anchor);
$tagui_version = substr($tagui_runner, $version_start_pos);
$version_end_pos = strpos($tagui_version, $right_anchor);
$tagui_version = substr($tagui_version, 0, $version_end_pos); return $tagui_version;}

// retrieve TagUI versions for local and master
$tagui_master_version = tagui_version('https://raw.githubusercontent.com/kelaberetiv/TagUI/master/src/tagui');
$tagui_local_version = tagui_version(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tagui');

// download and update if there is a new version
if (floatval($tagui_local_version) == floatval($tagui_master_version))
echo "You are already using the latest version of TagUI (v" . $tagui_master_version . ")\n";
else {echo "Downloading and updating to latest version of TagUI (v" . $tagui_master_version . ")\n";
$zip_file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "TagUI-master-v" . $tagui_master_version . ".zip";
if (file_put_contents($zip_file,fopen("https://github.com/kelaberetiv/TagUI/archive/refs/heads/master.zip",'r')) == false)
echo "ERROR - cannot download new TagUI version from below GitHub URL\n" .
"https://github.com/kelaberetiv/TagUI/archive/refs/heads/master.zip\n";
else {$zip = new ZipArchive; if ($zip->open($zip_file) === true) {$zip->extractTo(dirname($zip_file)); $zip->close();
echo "TagUI updated (v" . $tagui_master_version . ")\n";} else echo "ERROR - cannot unzip " . basename($zip_file) . "\n";}}

?>

@kensoh
Copy link
Member Author

kensoh commented Jun 10, 2021

Seems to find a working solution by doing the entry in shell, version detection and downloading in php, and unzipping in shell. checklist of test cases before this feature can be considered done. may have to use curl due to allow_url_fopen blocker.

  • version older
  • version newer
  • version same
  • no web connection
  • can't access URL
  • files already exist
  • folders already exist
  • post update can run
  • repeat above for linux - file_get_contents blocked by allow_url_fopen off (solution - do fully in shell, don't use php)
  • port bash script to batch script and repeat above for windows

@kensoh
Copy link
Member Author

kensoh commented Jun 11, 2021

working implementation for mac and linux fully in shell in tagui/src/tagui. the single 1 long line at the end is needed because the script will also be overwritten during execution by the update, doing this way can help to exit cleanly instead of crashing.

note that this version of update command does not handle major upgrade where a full package zip (150+ MB) is needed including dependencies like SikuliX. this handles version updates directly retrieving from GitHub source code (~10MB).

PS - looks like have to use unzip for mac / linux and tar for Windows (for Windows that's the only native command that can unzip file from batch file, instead of calling PowerShell or VB Script)

# go into download and update process if tagui update is given
if [ "$1" = "update" ]; then
SOURCE="${BASH_SOURCE[0]}" # slimerjs's implementation instead of cd "`dirname "$0"`"
while [ -h "$SOURCE" ]; do TAGUI_PARENT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"; [[ $SOURCE != /* ]] && SOURCE="$TAGUI_PARENT_DIR/$SOURCE"; done
TAGUI_PARENT_DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
if [ -f "$TAGUI_PARENT_DIR/TagUI-master.zip" ]; then rm "$TAGUI_PARENT_DIR/TagUI-master.zip"; fi
if [ -f "$TAGUI_PARENT_DIR/src/tagui_master" ]; then rm "$TAGUI_PARENT_DIR/src/tagui_master"; fi

curl -k -s -o "$TAGUI_PARENT_DIR/src/tagui_master" "https://raw.githubusercontent.com/kelaberetiv/TagUI/master/src/tagui"
if [ -f "$TAGUI_PARENT_DIR/src/tagui_master" ]; then
if ! grep -iq 'echo "tagui v' "$TAGUI_PARENT_DIR/src/tagui_master"; then
rm "$TAGUI_PARENT_DIR/src/tagui_master"; fi; fi
if ! [ -f "$TAGUI_PARENT_DIR/src/tagui_master" ]; then
echo "ERROR - internet connection to access GitHub is required to update TagUI"; exit 1; fi

TAGUI_MASTER_VERSION="$(grep 'echo "tagui v' "$TAGUI_PARENT_DIR/src/tagui_master" | cut -d' ' -f 3 | head -n 1)";
TAGUI_LOCAL_VERSION="$(grep 'echo "tagui v' "$TAGUI_PARENT_DIR/src/tagui" | cut -d' ' -f 3 | head -n 1)";
rm "$TAGUI_PARENT_DIR/src/tagui_master"
if [[ "$TAGUI_MASTER_VERSION" == "$TAGUI_LOCAL_VERSION" ]]; then
echo "You are already using the latest version of TagUI (${TAGUI_LOCAL_VERSION%?})"; exit 0; fi

echo "Downloading and updating to latest version of TagUI (${TAGUI_MASTER_VERSION%?})"
curl -k -s -L -o "$TAGUI_PARENT_DIR/TagUI-master.zip" "https://github.com/kelaberetiv/TagUI/archive/refs/heads/master.zip"
if [ -f "$TAGUI_PARENT_DIR/TagUI-master.zip" ]; then
if grep -iq "not found\|bad request" "$TAGUI_PARENT_DIR/TagUI-master.zip"; then
rm "$TAGUI_PARENT_DIR/TagUI-master.zip"; fi; fi
if ! [ -f "$TAGUI_PARENT_DIR/TagUI-master.zip" ]; then
echo "ERROR - cannot download from https://github.com/kelaberetiv/TagUI/archive/refs/heads/master.zip"; exit 1; fi

unzip -qq "$TAGUI_PARENT_DIR/TagUI-master.zip" -d "$TAGUI_PARENT_DIR"; \cp -R "$TAGUI_PARENT_DIR/TagUI-master/src" "$TAGUI_PARENT_DIR/."; \cp -R "$TAGUI_PARENT_DIR/TagUI-master/flows" "$TAGUI_PARENT_DIR/."; \cp -R "$TAGUI_PARENT_DIR/TagUI-master/docs" "$TAGUI_PARENT_DIR/."; \cp "$TAGUI_PARENT_DIR/TagUI-master/README.md" "$TAGUI_PARENT_DIR/."; \cp "$TAGUI_PARENT_DIR/TagUI-master/LICENSE.md" "$TAGUI_PARENT_DIR/."; chmod -R 755 "$TAGUI_PARENT_DIR"; if [ -d "$TAGUI_PARENT_DIR/TagUI-master" ]; then \rm -R "$TAGUI_PARENT_DIR/TagUI-master"; echo "TagUI successfully updated at $TAGUI_PARENT_DIR"; fi; exit 0

# end of if block to handle download and update process
fi

added working version for Windows batch file -

rem go into download and update process if tagui update is given
rem set TAGUI_PARENT_DIR here to avoid complication in for loop
set "TAGUI_PARENT_DIR=%~dp0.."
if "%1"=="update" (
	if exist "%TAGUI_PARENT_DIR%\TagUI-master.zip" del "%TAGUI_PARENT_DIR%\TagUI-master.zip"
	if exist "%TAGUI_PARENT_DIR%\src\tagui_master.cmd" del "%TAGUI_PARENT_DIR%\src\tagui_master.cmd"

	if exist "%~dp0unx\curl.exe" (
		set "path=%~dp0unx;%path%"
	) else (
		echo ERROR - cannot find curl command tagui\src\unx\curl.exe needed to update TagUI
		exit /b 1
	)
	curl -k -s -o "%TAGUI_PARENT_DIR%\src\tagui_master.cmd" "https://raw.githubusercontent.com/kelaberetiv/TagUI/master/src/tagui.cmd"
	if exist "%TAGUI_PARENT_DIR%\src\tagui_master.cmd" (
		find /i /c "echo tagui v" "%TAGUI_PARENT_DIR%\src\tagui_master.cmd" > nul
		if errorlevel 1 del "%TAGUI_PARENT_DIR%\src\tagui_master.cmd"
	)
	if not exist "%TAGUI_PARENT_DIR%\src\tagui_master.cmd" (
		echo ERROR - internet connection to access GitHub is required to update TagUI
		exit /b 1
	)

	for /f "tokens=* usebackq delims=" %%v in (`grep "echo tagui v" "%TAGUI_PARENT_DIR%\src\tagui_master.cmd" ^| cut -d" " -f 3 ^| head -n 1`) do set TAGUI_MASTER_VERSION=%%v
	for /f "tokens=* usebackq delims=" %%v in (`grep "echo tagui v" "%TAGUI_PARENT_DIR%\src\tagui.cmd" ^| cut -d" " -f 3 ^| head -n 1`) do set TAGUI_LOCAL_VERSION=%%v
	del "%TAGUI_PARENT_DIR%\src\tagui_master.cmd"
	if "!TAGUI_MASTER_VERSION!" == "!TAGUI_LOCAL_VERSION!" (
		echo You are already using the latest version of TagUI ^(!TAGUI_LOCAL_VERSION:~0,-1!^)
		exit /b 0
	)

	echo Downloading and updating to latest version of TagUI ^(!TAGUI_MASTER_VERSION:~0,-1!^)
	curl -k -s -L -o "%TAGUI_PARENT_DIR%\TagUI-master.zip" "https://github.com/kelaberetiv/TagUI/archive/refs/heads/master.zip"
	if exist "%TAGUI_PARENT_DIR%\TagUI-master.zip" (
		find /i /c "not found" "%TAGUI_PARENT_DIR%\TagUI-master.zip" > nul || find /i /c "bad request" "%TAGUI_PARENT_DIR%\TagUI-master.zip" > nul
		if not errorlevel 1 del "%TAGUI_PARENT_DIR%\TagUI-master.zip"
	)
	if not exist "%TAGUI_PARENT_DIR%\TagUI-master.zip" ( 
		echo ERROR - cannot download from https://github.com/kelaberetiv/TagUI/archive/refs/heads/master.zip
		exit /b 1
	)

	tar -xf "%TAGUI_PARENT_DIR%\TagUI-master.zip" -C "%TAGUI_PARENT_DIR%" & xcopy "%TAGUI_PARENT_DIR%\TagUI-master\*" "%TAGUI_PARENT_DIR%\" /y /s /q  > nul & if exist "%TAGUI_PARENT_DIR%\TagUI-master\" ( rmdir /S /Q "%TAGUI_PARENT_DIR%\TagUI-master" & echo TagUI successfully updated at %TAGUI_PARENT_DIR:~0,-7% ) & exit /b 0

rem end of if block to handle download and update process
)

kensoh added a commit that referenced this issue Jun 15, 2021
@kensoh kensoh changed the title * Review tagui update command to automatically fetch latest version of TagUI Review tagui update command to automatically fetch latest version of TagUI - done Jun 15, 2021
@kensoh
Copy link
Member Author

kensoh commented Jun 15, 2021

Above commit adds this. Users can download the latest copy of TagUI with this and unzip to overwrite existing installation (please drag the folders under tagui\src to overwrite your existing installation) - https://github.com/kelaberetiv/TagUI/archive/master.zip

In the next release, this will become part of the packaged zip files.

@kensoh kensoh changed the title Review tagui update command to automatically fetch latest version of TagUI - done Add tagui update command to automatically fetch latest version of TagUI - done Jun 15, 2021
@kensoh
Copy link
Member Author

kensoh commented Jun 18, 2021

Closing issue, change included in latest packaged release - https://github.com/kelaberetiv/TagUI/releases/tag/v6.46.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants