1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 05:37:32 +02:00

Bare minimum to build releases in GitHub Actions

This commit is contained in:
Nick Liu
2020-02-28 20:25:26 +01:00
parent 537106c64f
commit 0d80b82b49
4 changed files with 202 additions and 117 deletions

36
.github/workflows/build-release.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: Build Release
on:
push:
pull_request:
jobs:
build:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Update operating system software repository
run: sudo apt-get update
- name: Install operating system dependencies
run: sudo apt-get install -y git tar gzip xz-utils zip php-cli
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Fetch version information
run: git fetch origin +refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*
- name: Run build script
run: php e107_make.php
working-directory: ./.github/workflows/build-release/
- name: Upload build artifacts
uses: actions/upload-artifact@v1
with:
name: release_files
path: ./.github/workflows/build-release/target/e107/release/

View File

@@ -0,0 +1 @@
target/

View File

@@ -8,21 +8,22 @@
* *
*/ */
$builder = new e107Build();
$builder->init();
$builder->makeBuild();
class e107Build class e107Build
{ {
public $config, $version, $tag, $lastversion, $lastversiondate, $beta, $error, $rc; public $config, $version, $lastversion, $lastversiondate, $beta, $error, $rc;
var $createdFiles = array(); var $createdFiles = array();
var $releaseDir = ""; var $releaseDir = "";
var $pause = false;
var $tempDir = null; var $tempDir = null;
var $exportDir = null; var $exportDir = null;
var $gitDir = null; var $gitDir = null;
var $gitRepo = null; var $stagingDir = null;
public function __construct() public function __construct()
{ {
@@ -31,12 +32,46 @@ class e107Build
$this->rc = false; $this->rc = false;
$this->config['baseDir'] = dirname(__FILE__); $this->config['baseDir'] = dirname(__FILE__);
} }
public function init($module) private static function getVerFileVersion($verFilePath)
{ {
$iniFile = $this->config['baseDir'] . '/config/config_' . $module . '.ini'; $verFileTokens = token_get_all(file_get_contents($verFilePath));
$nextConstantEncapsedStringIsVersion = false;
foreach ($verFileTokens as $verFileToken)
{
if (!isset($verFileToken[1])) continue;
$token = $verFileToken[0];
$value = trim($verFileToken[1], "'\"");
if ($token === T_CONSTANT_ENCAPSED_STRING)
{
if ($nextConstantEncapsedStringIsVersion)
{
return $value;
}
if ($value === 'e107_version') $nextConstantEncapsedStringIsVersion = true;
}
}
return '0';
}
private static function gitVersionToPhpVersion($gitVersion, $verFileVersion)
{
$verFileVersion = array_shift(explode(" ", $verFileVersion));
$version = preg_replace("/^v/", "", $gitVersion);
$versionSplit = explode("-", $version);
if (count($versionSplit) > 1)
{
if (version_compare($verFileVersion, $versionSplit[0], '>')) $versionSplit[0] = $verFileVersion;
$versionSplit[0] .= "dev";
}
return implode("-", $versionSplit);
}
public function init($module = null)
{
$iniFile = $this->config['baseDir'] . '/make.ini';
if (is_readable($iniFile)) if (is_readable($iniFile))
{ {
@@ -63,24 +98,25 @@ class e107Build
$this->exportDir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/export/"; $this->exportDir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/export/";
$this->tempDir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/temp/"; $this->tempDir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/temp/";
$this->gitDir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/checkout/"; $this->stagingDir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/staging/";
$this->gitRepo = $this->config['main']['git_repo'];
if (!$this->version) $rc = 255;
$output = [];
exec("git rev-parse --show-toplevel", $output, $rc);
$gitRoot = array_pop($output);
if (!is_dir($gitRoot))
{ {
echo "Error: No Version Set\n"; // eg. 0.7.22 $this->status("Error getting Git repo root (rc=$rc). Output was garbage: $gitRoot");
$this->error = TRUE; return false;
return;
} }
$this->gitDir = realpath($gitRoot);
if (!$this->tag) exec("git describe --tags", $output, $rc);
{ $gitVersion = array_pop($output);
echo "Error: No Tag Set\n"; // eg. e107_v07_22_release $verFileVersion = self::getVerFileVersion($this->gitDir . "/e107_admin/ver.php");
$this->error = TRUE; $this->version = self::gitVersionToPhpVersion($gitVersion, $verFileVersion);
}
$this->config['preprocess']['version'] = $this->version; $this->config['preprocess']['version'] = $this->version;
$this->config['preprocess']['tag'] = $this->tag;
if ($this->ReadMeProblems()) if ($this->ReadMeProblems())
{ {
@@ -281,9 +317,6 @@ class e107Build
$cmd = "mkdir -p {$dir}/temp"; $cmd = "mkdir -p {$dir}/temp";
`$cmd`; `$cmd`;
$cmd = "mkdir -p {$dir}/checkout";
`$cmd`;
$cmd = "mkdir -p {$dir}/release"; $cmd = "mkdir -p {$dir}/release";
`$cmd`; `$cmd`;
@@ -305,36 +338,41 @@ class e107Build
private function preprocess() private function preprocess()
{ {
$this->gitClone();
return true; return true;
} }
private function gitClone() /*
private function targetClone()
{ {
if (empty($this->gitRepo)) $rc = 255;
$output = [];
exec("git rev-parse --show-toplevel", $output, $rc);
$gitRoot = array_pop($output);
if (!is_dir($gitRoot))
{ {
$this->status("No Repo selected"); $this->status("Error getting Git repo root (rc=$rc). Output was garbage: $gitRoot");
return false; return false;
} }
$gitRoot = realpath($gitRoot);
$this->status("Cloning git repo", true); mkdir($this->stagingDir, 0755, true);
$stagingDir = realpath($this->stagingDir);
$this->run("git clone " . $this->gitRepo . " " . $this->gitDir); $stagingDirLocalSegment = preg_replace("/^" . preg_quote($gitRoot, "/") . "/", "", $stagingDir);
$this->run("chmod 0755 " . $this->gitDir); if ($stagingDirLocalSegment == $stagingDir)
if (!is_dir($this->gitDir . "/.git"))
{ {
$this->status("There was a problem. Check your setup:\n $this->status("Staging dir \"$stagingDir\" is currently not supported outside repo root \"$gitRoot\"");
cd /usr/bin/<br />
sudo ln -s /usr/local/cpanel/3rdparty/bin/git* .<br />
git --version
<br /><br />
Make sure TCP port 9418 is open!");
} }
$cloneCommand =
"rsync -avHXShPs" .
" --exclude=" . escapeshellarg($stagingDirLocalSegment . "/") .
" --delete-after --delete-excluded" .
" --link-dest=" . escapeshellarg($gitRoot) .
" " . escapeshellarg($gitRoot . "/") .
" " . escapeshellarg($stagingDir . "/");
exec($cloneCommand, $output, $rc);
return true; return $rc;
} }
*/
private function run($cmd) private function run($cmd)
{ {
@@ -382,6 +420,7 @@ class e107Build
case "files_delete" : case "files_delete" :
$this->filesDelete($val); $this->filesDelete($val);
break; break;
case "plugin_delete" : case "plugin_delete" :
$this->pluginRemove($val); $this->pluginRemove($val);
break; break;
@@ -394,13 +433,8 @@ class e107Build
$this->CreateCoreImage(); // Create Image $this->CreateCoreImage(); // Create Image
} }
$this->pause(20);
$this->copyCoreImage(); $this->copyCoreImage();
$this->pause(20);
if (isset($rel['readme'])) if (isset($rel['readme']))
{ {
$this->moveReadme($rel['readme']); $this->moveReadme($rel['readme']);
@@ -444,21 +478,28 @@ class e107Build
$zipfile = $releaseDir . '/' . $newfile . '.zip'; $zipfile = $releaseDir . '/' . $newfile . '.zip';
$gzfile = $releaseDir . '/' . $newfile . '.tar.gz'; $tarfile = $releaseDir . '/' . $newfile . '.tar';
$zipcmd = "zip -r{$zipsince} $zipfile * >/dev/null 2>&1"; $zipcmd = "zip -9 -r{$zipsince} $zipfile . 2>&1";
$tarcmd = "tar cz {$ts} -f$gzfile * >/dev/null 2>&1"; $tarcmd = "tar --owner=0 --group=0 -cf $tarfile {$ts} . 2>&1";
$this->status('Creating ZIP archive'); $this->status('Creating ZIP archive');
$this->status($zipcmd); $this->status($zipcmd);
`$zipcmd`; `$zipcmd`;
$this->status('Creating TAR.GZ archive'); $this->status('Creating TAR archive');
$this->status($tarcmd); $this->status($tarcmd);
`$tarcmd`; `$tarcmd`;
$this->status('Creating TAR.GZ archive');
`(cat $tarfile | gzip -9 > $tarfile.gz)`;
// $this->status('Creating TAR.XZ archive');
// `(cat $tarfile | xz -9e > $tarfile.xz)`;
$this->createdFiles[] = array('path' => $releaseDir . "/", 'file' => $newfile . '.zip'); $this->createdFiles[] = array('path' => $releaseDir . "/", 'file' => $newfile . '.zip');
$this->createdFiles[] = array('path' => $releaseDir . "/", 'file' => $newfile . '.tar');
$this->createdFiles[] = array('path' => $releaseDir . "/", 'file' => $newfile . '.tar.gz'); $this->createdFiles[] = array('path' => $releaseDir . "/", 'file' => $newfile . '.tar.gz');
// $this->createdFiles[] = array('path' => $releaseDir . "/", 'file' => $newfile . '.tar.xz');
} // end loop } // end loop
@@ -481,7 +522,7 @@ class e107Build
private function rmdir($dir) private function rmdir($dir)
{ {
if (empty($dir)) if (!is_dir($dir))
{ {
return false; return false;
} }
@@ -490,10 +531,7 @@ class e107Build
$dir = rtrim($dir, "/"); $dir = rtrim($dir, "/");
$cmd = "rm -rf {$dir}/*"; $cmd = "rm -rf {$dir}";
$this->status($cmd);
`$cmd`;
$cmd = "rmdir {$dir}";
$this->status($cmd); $this->status($cmd);
`$cmd`; `$cmd`;
@@ -533,22 +571,17 @@ class e107Build
$cmd = 'unzip -q -o ' . $filepath . ' -d ' . $this->exportDir; $cmd = 'unzip -q -o ' . $filepath . ' -d ' . $this->exportDir;
$this->run($cmd); $this->run($cmd);
$this->run('chmod -R a=,u+rwX,go+rX ' . escapeshellarg($this->exportDir));
} }
private function editVersion($dir = 'checkout') private function editVersion($dir = 'export')
{ {
$version = $this->config['preprocess']['version']; $version = $this->config['preprocess']['version'];
if ($this->beta && !$this->rc) if (strpos($version, "-") !== false)
{ {
$version .= " beta build " . date('Ymd'); $version .= " nightly build " . date('Ymd');
} }
elseif ($this->rc)
{
$version .= " " . $this->rc;
}
$fname = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/" . $dir . "/e107_admin/ver.php"; $fname = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/" . $dir . "/e107_admin/ver.php";
@@ -599,12 +632,14 @@ class e107Build
$fn = trim($fn); $fn = trim($fn);
if (file_exists($fn)) if (file_exists($fn))
{ {
$result = unlink($fn); if (is_file($fn)) $result = unlink($fn);
elseif (is_dir($fn)) $result = $this->rmdir($fn);
else $result = false;
$this->status("Deleting $fn - " . ($result ? "SUCCESS" : "FAIL")); $this->status("Deleting $fn - " . ($result ? "SUCCESS" : "FAIL"));
} }
else else
{ {
$this->status("File already deleted or abscent - " . $fn); $this->status("File already deleted or absent - " . $fn);
} }
} }
@@ -654,19 +689,6 @@ class e107Build
chdir($dir); chdir($dir);
} }
private function pause($seconds)
{
if ($this->pause !== true)
{
return false;
}
$this->status(" (Pausing for " . $seconds . " seconds...)", true);
sleep($seconds);
return true;
}
private function copyCoreImage() private function copyCoreImage()
{ {
$orig = $this->tempDir . "core_image.php"; $orig = $this->tempDir . "core_image.php";
@@ -796,7 +818,7 @@ class coreImage
$data .= "+ ----------------------------------------------------------------------------+\n"; $data .= "+ ----------------------------------------------------------------------------+\n";
$data .= "| e107 website system\n"; $data .= "| e107 website system\n";
$data .= "|\n"; $data .= "|\n";
$data .= "| Copyright (C) 2008-2010 e107 Inc. \n"; $data .= "| Copyright (C) 2008-" . date("Y") . " e107 Inc. \n";
$data .= "| http://e107.org\n"; $data .= "| http://e107.org\n";
// $data .= "| jalist@e107.org\n"; // $data .= "| jalist@e107.org\n";
$data .= "|\n"; $data .= "|\n";
@@ -831,47 +853,73 @@ class coreImage
function scan($dir, $image = array()) function scan($dir, $image = array())
{ {
$handle = opendir($dir . '/'); $absoluteBase = realpath($dir);
if (!is_dir($absoluteBase)) return false;
$exclude = array('e107_config.php', 'install.php', 'CVS', '.svn', 'Thumbs.db', '.gitignore'); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
$files = [];
while (false !== ($readdir = readdir($handle))) /**
* @var $file DirectoryIterator
*/
foreach ($iterator as $file)
{ {
if ($readdir != '.' && $readdir != '..' && $readdir != '/' && !in_array($readdir, $exclude) && (strpos('._', $readdir) === FALSE)) if ($file->isDir()) continue;
{
$path = $dir . '/' . $readdir;
if (is_dir($path))
{
$dirs[$path] = $readdir;
}
else if (!isset($image[$readdir]))
{
$files[$readdir] = $this->checksum($path);
}
}
}
closedir($handle);
$list = []; $absolutePath = $file->getRealPath();
if (isset($dirs)) $relativePath = preg_replace("/^" . preg_quote($absoluteBase . "/", "/") . "/", "", $absolutePath);
{
ksort($dirs); if (empty($relativePath) || $relativePath == $absolutePath) continue;
foreach ($dirs as $dir_path => $dir_list)
{ self::array_set($files, $relativePath, $this->checksum($absolutePath));
$list[$dir_list] = ($set = $this->scan($dir_path, $image[$dir_list])) ? $set : array();
}
} }
if (isset($files)) ksort($files);
return $files;
}
/**
* Set an array item to a given value using "slash" notation.
*
* If no key is given to the method, the entire array will be replaced.
*
* Based on Illuminate\Support\Arr::set()
*
* @param array $array
* @param string|null $key
* @param mixed $value
* @return array
* @copyright Copyright (c) Taylor Otwell
* @license https://github.com/illuminate/support/blob/master/LICENSE.md MIT License
*/
private static function array_set(&$array, $key, $value)
{
if (is_null($key))
{ {
ksort($files); return $array = $value;
foreach ($files as $file_name => $file_list)
{
$list[$file_name] = $file_list;
}
} }
return $list; $keys = explode('/', $key);
while (count($keys) > 1)
{
$key = array_shift($keys);
// If the key doesn't exist at this depth, we will just create an empty array
// to hold the next value, allowing us to create the arrays to hold final
// values at the correct depth. Then we'll keep digging into the array.
if (!isset($array[$key]) || !is_array($array[$key]))
{
$array[$key] = [];
}
$array = &$array[$key];
}
$array[array_shift($keys)] = $value;
return $array;
} }
function checksum($filename) function checksum($filename)

View File

@@ -1,5 +1,5 @@
[main] [main]
name=e107_0.8 name=e107
svn_path=https://github.com/e107inc/e107/trunk svn_path=https://github.com/e107inc/e107/trunk
svn_tag_path=https://github.com/e107inc/e107/tags svn_tag_path=https://github.com/e107inc/e107/tags
svn_username=<username> svn_username=<username>
@@ -14,17 +14,17 @@ files_create=e107_config.php
type=full type=full
plugin_delete=alt_auth,newsletter,faqs,metaweblog,pdf,newforumposts_main plugin_delete=alt_auth,newsletter,faqs,metaweblog,pdf,newforumposts_main
files_create=e107_config.php files_create=e107_config.php
files_delete=.gitignore,.codeclimate.yml,.editorconfig,composer.json,composer.lock files_delete=.gitignore,.gitmodules,.codeclimate.yml,.editorconfig,composer.json,composer.lock,e107_tests,.github
[release_2] [release_2]
type=upgrade type=upgrade
plugin_delete=faqs,metaweblog,pdf plugin_delete=faqs,metaweblog,pdf
files_delete=install.php,favicon.ico,.gitignore,.codeclimate.yml,.editorconfig,composer.json,composer.lock files_delete=install.php,favicon.ico,.gitignore,.gitmodules,.codeclimate.yml,.editorconfig,composer.json,composer.lock,e107_tests,.github
from_version=v1.x from_version=v1.x
[release_3] [release_3]
type=upgrade type=upgrade
plugin_delete=alt_auth,newsletter,calendar_menu,tree_menu,faqs,metaweblog,pdf plugin_delete=alt_auth,newsletter,calendar_menu,tree_menu,faqs,metaweblog,pdf
files_delete=install.php,favicon.ico,.gitignore,.codeclimate.yml,.editorconfig,composer.json,composer.lock files_delete=install.php,favicon.ico,.gitignore,.gitmodules,.codeclimate.yml,.editorconfig,composer.json,composer.lock,e107_tests,.github
from_version=v2.x from_version=v2.x
since=2bd75d426b320ee0192e6f403ff1e561d2f38098 since=2bd75d426b320ee0192e6f403ff1e561d2f38098