Skip to content

Commit

Permalink
Introduce Packaging and Version Distribution Commands for Plugins (#115)
Browse files Browse the repository at this point in the history
* Introduce Packaging and Version Distribution Commands for Plugins

* Apply cs fix
  • Loading branch information
zds-s authored Jul 10, 2024
1 parent 3c9ad09 commit d7f7fc7
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 1 deletion.
45 changes: 45 additions & 0 deletions bin/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -e
if (( "$#" == 0 ))
then
echo "Tag has to be provided"

exit 1
fi

NOW=$(date +%s)
CURRENT_BRANCH=$(cd $1 && git rev-parse --abbrev-ref HEAD)
BASEPATH=$1
VERSION=$3
REMOTE=$2
# Always prepend with "v"
if [[ $VERSION != v* ]]
then
VERSION="v$VERSION"
fi

echo ""
echo ""
echo "Cloning $REMOTE";
TMP_DIR="/tmp/mineAdmin-split"
REMOTE_URL=$REMOTE

rm -rf $TMP_DIR;
mkdir $TMP_DIR;

(
cd $TMP_DIR;

git clone $REMOTE_URL .
git checkout "$CURRENT_BRANCH";

if [[ $(git log --pretty="%d" -n 1 | grep tag --count) -eq 0 ]]; then
echo "Releasing $REMOTE"
git tag $VERSION
git push origin --tags
fi
)

TIME=$(echo "$(date +%s) - $NOW" | bc)

printf "Execution time: %f seconds" $TIME
20 changes: 20 additions & 0 deletions bin/split-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -e
set -x
CURRENT_BRANCH=$(cd $1 && git rev-parse --abbrev-ref HEAD)
bin=$3
BASEPATH=$1
REPO=$2
function split()
{
SHA1=`$bin/splitsh-lite-linux --prefix=$1`
git push $2 "$SHA1:refs/heads/$CURRENT_BRANCH" -f
}

function remote()
{
git remote add $1 $2 || true
}

remote 'appStore' $REPO
split $BASEPATH $REPO
Binary file added bin/splitsh-lite
Binary file not shown.
Binary file added bin/splitsh-lite-linux
Binary file not shown.
52 changes: 52 additions & 0 deletions src/Command/Repository/PushCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);
/**
* This file is part of MineAdmin.
*
* @link https://www.mineadmin.com
* @document https://doc.mineadmin.com
* @contact [email protected]
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
*/

namespace Mine\AppStore\Command\Repository;

use Hyperf\Command\Annotation\Command;
use Mine\AppStore\Command\AbstractCommand;
use Mine\AppStore\Plugin;
use Swoole\Coroutine\System;
use Symfony\Component\Console\Input\InputArgument;

#[Command]
class PushCommand extends AbstractCommand
{
protected const COMMAND_NAME = 'push';

public function __invoke(): int
{
$path = $this->input->getArgument('path');
$repository = $this->input->getArgument('repository');
$bin = dirname(__DIR__, 3) . '/bin';
$repositoryPath = Plugin::PLUGIN_PREFIX . DIRECTORY_SEPARATOR . $path;
$splitLinuxBin = $bin . DIRECTORY_SEPARATOR . 'split-linux.sh';
$basepath = BASE_PATH;
$shell = <<<SHELL
cd {$basepath} && {$splitLinuxBin} {$repositoryPath} {$repository} {$bin}
SHELL;
$result = System::exec($shell);
if ($result['code'] !== 0) {
$this->output->error('Fail' . $result['output']);
return $result['code'];
}
$this->output->success('Push successfully');
return 0;
}

protected function configure()
{
$this->setDescription('Quickly perform plugin packaging and deployment processing.');
$this->addArgument('path', InputArgument::REQUIRED, 'Plugin path');
$this->addArgument('repository', InputArgument::REQUIRED, 'Git Repository path');
}
}
53 changes: 53 additions & 0 deletions src/Command/Repository/ReleaseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);
/**
* This file is part of MineAdmin.
*
* @link https://www.mineadmin.com
* @document https://doc.mineadmin.com
* @contact [email protected]
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
*/

namespace Mine\AppStore\Command\Repository;

use Hyperf\Command\Annotation\Command;
use Mine\AppStore\Command\AbstractCommand;
use Mine\AppStore\Plugin;
use Swoole\Coroutine\System;
use Symfony\Component\Console\Input\InputArgument;

#[Command]
class ReleaseCommand extends AbstractCommand
{
public const COMMAND_NAME = 'release';

public function __invoke(): int
{
$path = $this->argument('path');
$repository = $this->argument('repository');
$version = $this->argument('version');
$bin = dirname(__DIR__, 3) . '/bin';
$repositoryPath = Plugin::PLUGIN_PREFIX . DIRECTORY_SEPARATOR . $path;
$splitLinuxBin = $bin . DIRECTORY_SEPARATOR . 'release.sh';
$basepath = BASE_PATH;
$shell = <<<SHELL
cd {$basepath} && {$splitLinuxBin} {$repositoryPath} {$repository} {$version} {$bin}
SHELL;
$result = System::exec($shell);
if ($result['code'] !== 0) {
$this->output->error('Fail' . $result['output']);
return $result['code'];
}
$this->output->success('Push successfully');
return 0;
}

protected function configure()
{
$this->addArgument('path', InputArgument::REQUIRED, 'Plugin path');
$this->addArgument('repository', InputArgument::REQUIRED, 'Git Repository path');
$this->addArgument('version', InputArgument::REQUIRED, 'Repository version');
}
}
4 changes: 3 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class Plugin
/**
* Plugin root directory.
*/
public const PLUGIN_PATH = BASE_PATH . '/plugin';
public const PLUGIN_PATH = BASE_PATH . '/' . self::PLUGIN_PREFIX;

public const PLUGIN_PREFIX = 'plugin';

private static array $mineJsonPaths = [];

Expand Down

0 comments on commit d7f7fc7

Please sign in to comment.