deployment
This commit is contained in:
parent
fcc2ba65c4
commit
4973521a9c
13 changed files with 329 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,3 +12,4 @@
|
|||
/vendor/
|
||||
.env
|
||||
.phpunit.result.cache
|
||||
/release/
|
32
.travis.yml
32
.travis.yml
|
@ -18,6 +18,11 @@ env:
|
|||
|
||||
stages:
|
||||
- test
|
||||
- deploy
|
||||
|
||||
before_install:
|
||||
- export LAST_TAG=`git describe --abbrev=0 --tags`
|
||||
- export CURRENT_VERSION=v`php bin/bitrix-version`
|
||||
|
||||
install:
|
||||
- echo 'short_open_tag = On' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
||||
|
@ -33,18 +38,45 @@ script: make test
|
|||
jobs:
|
||||
include:
|
||||
- php: 7.0
|
||||
before_install: skip
|
||||
env: NOT_USE_VENDOR=1 BITRIX_EDITION=small_business_encode
|
||||
- php: 7.1
|
||||
before_install: skip
|
||||
env: BITRIX_EDITION=small_business_encode
|
||||
- php: 7.2
|
||||
before_install: skip
|
||||
env: BITRIX_EDITION=small_business_encode
|
||||
- php: 7.3
|
||||
before_install: skip
|
||||
env: BITRIX_EDITION=small_business_encode
|
||||
- php: 7.0
|
||||
before_install: skip
|
||||
env: NOT_USE_VENDOR=1 BITRIX_EDITION=business_encode
|
||||
- php: 7.1
|
||||
before_install: skip
|
||||
env: BITRIX_EDITION=business_encode
|
||||
- php: 7.2
|
||||
before_install: skip
|
||||
env: BITRIX_EDITION=business_encode
|
||||
- php: 7.3
|
||||
before_install: skip
|
||||
env: BITRIX_EDITION=business_encode
|
||||
- stage: deploy
|
||||
before_script: skip
|
||||
script: make build_release_dir
|
||||
before_deploy:
|
||||
- export VERSION=`php bin/bitrix-version`
|
||||
- export ARCHIVE_NAME=$TRAVIS_BUILD_DIR/release/$VERSION
|
||||
- git config --local user.name "retailCRM"
|
||||
- git config --local user.email "support@retailcrm.ru"
|
||||
- export TRAVIS_TAG=v$VERSION
|
||||
- git tag $TRAVIS_TAG
|
||||
deploy:
|
||||
provider: releases
|
||||
token: $GITHUB_OAUTH_TOKEN
|
||||
cleanup: false
|
||||
file: $ARCHIVE_NAME
|
||||
on:
|
||||
condition: "$LAST_TAG != $CURRENT_VERSION"
|
||||
if: branch = master AND type = push
|
||||
after_deploy: make cleanup
|
||||
|
|
13
Makefile
13
Makefile
|
@ -40,6 +40,19 @@ create_db:
|
|||
echo "USE mysql;\nUPDATE user SET password=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root
|
||||
mysqladmin create $(DB_BITRIX_NAME) --user=$(DB_BITRIX_LOGIN) --password=$(DB_BITRIX_PASS)
|
||||
|
||||
build_release: build_release_dir
|
||||
bin/build $(ROOT_DIR)/release/$(CURRENT_VERSION)
|
||||
|
||||
build_release_dir: build_diff_file
|
||||
php bin/build-release
|
||||
|
||||
build_diff_file:
|
||||
git diff --name-status $(LAST_TAG) HEAD > $(ROOT_DIR)/release/diff
|
||||
|
||||
cleanup:
|
||||
rm $(ROOT_DIR)/release/$(CURRENT_VERSION)
|
||||
rm $(ROOT_DIR)/release/$(CURRENT_VERSION).tar.gz
|
||||
|
||||
# docker commands
|
||||
install:
|
||||
docker-compose exec bitrix make bitrix_install
|
||||
|
|
|
@ -17,8 +17,8 @@ if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/install/wizar
|
|||
}
|
||||
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/install/wizard/wizard.php';
|
||||
require_once __DIR__ . '/../installation/ExtendedCreateModulesStep.php';
|
||||
require_once __DIR__ . '/../installation/Installer.php';
|
||||
require_once __DIR__ . '/../helpers/installation/ExtendedCreateModulesStep.php';
|
||||
require_once __DIR__ . '/../helpers/installation/Installer.php';
|
||||
|
||||
$installer = new Installer();
|
||||
|
||||
|
|
13
bin/bitrix-version
Normal file
13
bin/bitrix-version
Normal file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
if (ini_get('memory_limit') > 0 && (int)ini_get('memory_limit') < 784) {
|
||||
ini_set('memory_limit', '784M');
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../intaro.retailcrm/install/version.php';
|
||||
|
||||
echo $arModuleVersion['VERSION'];
|
||||
exit(0);
|
44
bin/build
Normal file
44
bin/build
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash
|
||||
# $1 -- folder name to pack;
|
||||
|
||||
version=$1
|
||||
date=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
|
||||
if [ ! -d "$version/install" ]; then
|
||||
mkdir -p "./$version/install"
|
||||
echo "Created a folder \"install\""
|
||||
fi
|
||||
|
||||
if [ ! -f "$version/install/version.php" ]; then
|
||||
touch "./$version/install/version.php"
|
||||
echo "Created a file \"version.php\""
|
||||
fi
|
||||
|
||||
echo "
|
||||
<?
|
||||
\$arModuleVersion = array(
|
||||
\"VERSION\" => \"$version\",
|
||||
\"VERSION_DATE\" => \"$date\"
|
||||
);
|
||||
" > "./$version/install/version.php"
|
||||
echo "Update version and date in the file \"version.php\""
|
||||
|
||||
if [ ! -f "$version/description.ru" ] || [ -s "$version/description.ru" ]; then
|
||||
echo -n "Create Description? (y/n) "
|
||||
read report
|
||||
if [ "$report" = "y" ] || [ "$report" = "Y" ]; then
|
||||
vim "$version/description.ru"
|
||||
fi
|
||||
fi
|
||||
|
||||
for i in `find ./"$version" -type f -name '*.*'`; do
|
||||
encoding=`file -b --mime-encoding "$i"`
|
||||
if [ "$encoding" != "iso-8859-1" ] && [ "$encoding" != "binary" ]; then
|
||||
iconv -f $encoding -t "cp1251" $i >> $i.cp1251
|
||||
mv $i.cp1251 $i
|
||||
fi
|
||||
done
|
||||
echo "Encoding the file has changed"
|
||||
|
||||
tar -czf "$version.tar.gz" "$version"
|
||||
echo "Update has been successfully packaged"
|
31
bin/build-release
Normal file
31
bin/build-release
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../helpers/release/ReleaseBuilder.php';
|
||||
require_once __DIR__ . '/../helpers/release/ModifiedFile.php';
|
||||
require_once __DIR__ . '/../intaro.retailcrm/install/version.php';
|
||||
|
||||
define('RELEASE_DIR', __DIR__ . '/../release/');
|
||||
define('ORIGINAL', __DIR__ . '/../intaro.retailcrm/');
|
||||
|
||||
if (!file_exists(RELEASE_DIR . 'diff')) {
|
||||
print('Diff file does not exists');
|
||||
exit(255);
|
||||
}
|
||||
|
||||
$handle = fopen(RELEASE_DIR . 'diff', 'r');
|
||||
|
||||
if (!$handle) {
|
||||
exit(255);
|
||||
}
|
||||
|
||||
$modifiedFiles = [];
|
||||
|
||||
while (($buffer = fgets($handle)) !== false) {
|
||||
$file = explode("\t", trim($buffer));
|
||||
$modifiedFile = new ModifiedFile($file[1], $file[0]{0});
|
||||
$modifiedFiles[] = $modifiedFile;
|
||||
}
|
||||
|
||||
$builder = new ReleaseBuilder($modifiedFiles, $arModuleVersion['VERSION']);
|
||||
$builder->build();
|
0
installation/ExtendedCreateModulesStep.php → helpers/installation/ExtendedCreateModulesStep.php
Executable file → Normal file
0
installation/ExtendedCreateModulesStep.php → helpers/installation/ExtendedCreateModulesStep.php
Executable file → Normal file
0
installation/Installer.php → helpers/installation/Installer.php
Executable file → Normal file
0
installation/Installer.php → helpers/installation/Installer.php
Executable file → Normal file
87
helpers/release/ModifiedFile.php
Normal file
87
helpers/release/ModifiedFile.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Class ModifiedFile
|
||||
*/
|
||||
class ModifiedFile
|
||||
{
|
||||
/** @var string */
|
||||
const ADDED = 'A';
|
||||
|
||||
/** @var string */
|
||||
const DELETED = 'D';
|
||||
|
||||
/** @var string */
|
||||
const MODIFIED = 'M';
|
||||
|
||||
/** @var string */
|
||||
const RENAMED = 'R';
|
||||
|
||||
/** @var string */
|
||||
const MODULE_ID = 'intaro.retailcrm';
|
||||
|
||||
/** @var string */
|
||||
protected $filename;
|
||||
|
||||
/** @var string */
|
||||
protected $modificator;
|
||||
|
||||
/**
|
||||
* ModifiedFile constructor.
|
||||
* @param string $filename
|
||||
* @param string $modificator
|
||||
*/
|
||||
public function __construct($filename, $modificator = self::Modified)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->modificator = $modificator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAdded()
|
||||
{
|
||||
return $this->modificator === static::ADDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeleted()
|
||||
{
|
||||
return $this->modificator === static::DELETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isModified()
|
||||
{
|
||||
return $this->modificator === static::MODIFIED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isRenamed()
|
||||
{
|
||||
return $this->modificator === static::RENAMED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isModuleFile()
|
||||
{
|
||||
return strpos($this->filename, static::MODULE_ID) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
}
|
105
helpers/release/ReleaseBuilder.php
Normal file
105
helpers/release/ReleaseBuilder.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
require_once 'ModifiedFile.php';
|
||||
|
||||
/**
|
||||
* Class ReleaseBuilder
|
||||
*/
|
||||
class ReleaseBuilder
|
||||
{
|
||||
/** @var ModifiedFile[] */
|
||||
protected $files;
|
||||
|
||||
/** @var string */
|
||||
protected $releaseDir;
|
||||
|
||||
/**
|
||||
* ReleaseBuilder constructor.
|
||||
* @param ModifiedFile[] $files
|
||||
* @param string $releaseVersion
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct($files, $releaseVersion)
|
||||
{
|
||||
$this->files = $files;
|
||||
|
||||
if (!defined('RELEASE_DIR') || !defined('ORIGINAL')) {
|
||||
throw new \RuntimeException('`RELEASE_DIR` or `ORIGINAL` not defined');
|
||||
}
|
||||
|
||||
$this->releaseDir = RELEASE_DIR . $releaseVersion . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$this->createReleaseDir();
|
||||
$modifiedFiles = [];
|
||||
|
||||
foreach ($this->files as $file) {
|
||||
if (!$file->isModuleFile() || $file->isDeleted()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$modifiedFiles[] = $this->getRealFilename($file->getFilename());
|
||||
}
|
||||
|
||||
$this->createDirNodes($modifiedFiles);
|
||||
$this->copyFiles($modifiedFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $files
|
||||
*/
|
||||
private function copyFiles($files)
|
||||
{
|
||||
foreach ($files as $file) {
|
||||
copy(ORIGINAL . $file, $this->releaseDir . $file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $files
|
||||
*/
|
||||
private function createDirNodes($files)
|
||||
{
|
||||
$paths = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$dirs = explode('/', $file, -1);
|
||||
$path = $this->releaseDir;
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
$path .= $dir . '/';
|
||||
$paths[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (!file_exists($path)) {
|
||||
mkdir($path, 0755);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function createReleaseDir()
|
||||
{
|
||||
if (!file_exists($this->releaseDir)) {
|
||||
mkdir($this->releaseDir, 0755);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return string
|
||||
*/
|
||||
private function getRealFilename($filename)
|
||||
{
|
||||
return str_replace(ModifiedFile::MODULE_ID . '/', '', $filename);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?
|
||||
$arModuleVersion = array(
|
||||
"VERSION" => "5.2.5",
|
||||
"VERSION" => "5.2.6",
|
||||
"VERSION_DATE" => "2020-01-09 12:02:00"
|
||||
);
|
||||
|
|
0
release/.gitkeep
Normal file
0
release/.gitkeep
Normal file
Loading…
Add table
Reference in a new issue