Skip to content

Commit 94bb5e2

Browse files
authored
Introduce Packaging and Version Distribution Commands for Plugins (#115)
* Introduce Packaging and Version Distribution Commands for Plugins * Apply cs fix
1 parent 16b7176 commit 94bb5e2

File tree

8 files changed

+173
-2
lines changed

8 files changed

+173
-2
lines changed

src/AppStore/bin/release.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
if (( "$#" == 0 ))
4+
then
5+
echo "Tag has to be provided"
6+
7+
exit 1
8+
fi
9+
10+
NOW=$(date +%s)
11+
CURRENT_BRANCH=$(cd $1 && git rev-parse --abbrev-ref HEAD)
12+
BASEPATH=$1
13+
VERSION=$3
14+
REMOTE=$2
15+
# Always prepend with "v"
16+
if [[ $VERSION != v* ]]
17+
then
18+
VERSION="v$VERSION"
19+
fi
20+
21+
echo ""
22+
echo ""
23+
echo "Cloning $REMOTE";
24+
TMP_DIR="/tmp/mineAdmin-split"
25+
REMOTE_URL=$REMOTE
26+
27+
rm -rf $TMP_DIR;
28+
mkdir $TMP_DIR;
29+
30+
(
31+
cd $TMP_DIR;
32+
33+
git clone $REMOTE_URL .
34+
git checkout "$CURRENT_BRANCH";
35+
36+
if [[ $(git log --pretty="%d" -n 1 | grep tag --count) -eq 0 ]]; then
37+
echo "Releasing $REMOTE"
38+
git tag $VERSION
39+
git push origin --tags
40+
fi
41+
)
42+
43+
TIME=$(echo "$(date +%s) - $NOW" | bc)
44+
45+
printf "Execution time: %f seconds" $TIME

src/AppStore/bin/split-linux.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
set -x
4+
CURRENT_BRANCH=$(cd $1 && git rev-parse --abbrev-ref HEAD)
5+
bin=$3
6+
BASEPATH=$1
7+
REPO=$2
8+
function split()
9+
{
10+
SHA1=`$bin/splitsh-lite-linux --prefix=$1`
11+
git push $2 "$SHA1:refs/heads/$CURRENT_BRANCH" -f
12+
}
13+
14+
function remote()
15+
{
16+
git remote add $1 $2 || true
17+
}
18+
19+
remote 'appStore' $REPO
20+
split $BASEPATH $REPO

src/AppStore/bin/splitsh-lite

3.22 MB
Binary file not shown.

src/AppStore/bin/splitsh-lite-linux

3.33 MB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact [email protected]
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Mine\AppStore\Command\Repository;
14+
15+
use Hyperf\Command\Annotation\Command;
16+
use Mine\AppStore\Command\AbstractCommand;
17+
use Mine\AppStore\Plugin;
18+
use Swoole\Coroutine\System;
19+
use Symfony\Component\Console\Input\InputArgument;
20+
21+
#[Command]
22+
class PushCommand extends AbstractCommand
23+
{
24+
protected const COMMAND_NAME = 'push';
25+
26+
public function __invoke(): int
27+
{
28+
$path = $this->input->getArgument('path');
29+
$repository = $this->input->getArgument('repository');
30+
$bin = dirname(__DIR__, 3) . '/bin';
31+
$repositoryPath = Plugin::PLUGIN_PREFIX . DIRECTORY_SEPARATOR . $path;
32+
$splitLinuxBin = $bin . DIRECTORY_SEPARATOR . 'split-linux.sh';
33+
$basepath = BASE_PATH;
34+
$shell = <<<SHELL
35+
cd {$basepath} && {$splitLinuxBin} {$repositoryPath} {$repository} {$bin}
36+
SHELL;
37+
$result = System::exec($shell);
38+
if ($result['code'] !== 0) {
39+
$this->output->error('Fail' . $result['output']);
40+
return $result['code'];
41+
}
42+
$this->output->success('Push successfully');
43+
return 0;
44+
}
45+
46+
protected function configure()
47+
{
48+
$this->setDescription('Quickly perform plugin packaging and deployment processing.');
49+
$this->addArgument('path', InputArgument::REQUIRED, 'Plugin path');
50+
$this->addArgument('repository', InputArgument::REQUIRED, 'Git Repository path');
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of MineAdmin.
6+
*
7+
* @link https://www.mineadmin.com
8+
* @document https://doc.mineadmin.com
9+
* @contact [email protected]
10+
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
11+
*/
12+
13+
namespace Mine\AppStore\Command\Repository;
14+
15+
use Hyperf\Command\Annotation\Command;
16+
use Mine\AppStore\Command\AbstractCommand;
17+
use Mine\AppStore\Plugin;
18+
use Swoole\Coroutine\System;
19+
use Symfony\Component\Console\Input\InputArgument;
20+
21+
#[Command]
22+
class ReleaseCommand extends AbstractCommand
23+
{
24+
public const COMMAND_NAME = 'release';
25+
26+
public function __invoke(): int
27+
{
28+
$path = $this->argument('path');
29+
$repository = $this->argument('repository');
30+
$version = $this->argument('version');
31+
$bin = dirname(__DIR__, 3) . '/bin';
32+
$repositoryPath = Plugin::PLUGIN_PREFIX . DIRECTORY_SEPARATOR . $path;
33+
$splitLinuxBin = $bin . DIRECTORY_SEPARATOR . 'release.sh';
34+
$basepath = BASE_PATH;
35+
$shell = <<<SHELL
36+
cd {$basepath} && {$splitLinuxBin} {$repositoryPath} {$repository} {$version} {$bin}
37+
SHELL;
38+
$result = System::exec($shell);
39+
if ($result['code'] !== 0) {
40+
$this->output->error('Fail' . $result['output']);
41+
return $result['code'];
42+
}
43+
$this->output->success('Push successfully');
44+
return 0;
45+
}
46+
47+
protected function configure()
48+
{
49+
$this->addArgument('path', InputArgument::REQUIRED, 'Plugin path');
50+
$this->addArgument('repository', InputArgument::REQUIRED, 'Git Repository path');
51+
$this->addArgument('version', InputArgument::REQUIRED, 'Repository version');
52+
}
53+
}

src/AppStore/src/Plugin.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class Plugin
3636
/**
3737
* Plugin root directory.
3838
*/
39-
public const PLUGIN_PATH = BASE_PATH . '/plugin';
39+
public const PLUGIN_PATH = BASE_PATH . '/' . self::PLUGIN_PREFIX;
40+
41+
public const PLUGIN_PREFIX = 'plugin';
4042

4143
private static array $mineJsonPaths = [];
4244

src/mine-core/src/Aspect/ResubmitAspect.php

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Hyperf\Logger\LoggerFactory;
2020
use Hyperf\Redis\Redis;
2121
use Mine\Annotation\Resubmit;
22-
use Mine\Exception\MineException;
2322
use Mine\Exception\NormalStatusException;
2423
use Mine\MineRequest;
2524
use Mine\Redis\MineLockRedis;

0 commit comments

Comments
 (0)