Public Access
b491241a58
Universal: Sync Feature Branch Versions / Sync feature branches with dev (push) Has been skipped
# Conflicts: # .mokogitea/CLAUDE.md # .mokogitea/ISSUE_TEMPLATE/config.yml # .mokogitea/ISSUE_TEMPLATE/documentation.md # .mokogitea/ISSUE_TEMPLATE/feature_request.md # .mokogitea/ISSUE_TEMPLATE/security.md # .mokogitea/branch-protection.yml # .mokogitea/bulk-repo-sync.yml # .mokogitea/pr-branch-check.yml # .mokogitea/renovate.yml # .mokogitea/sync-wikis.yml # .mokogitea/workflows/auto-bump.yml # .mokogitea/workflows/auto-release.yml # .mokogitea/workflows/ci-platform.yml # .mokogitea/workflows/cleanup.yml # .mokogitea/workflows/gitleaks.yml # .mokogitea/workflows/issue-branch.yml # .mokogitea/workflows/notify.yml # .mokogitea/workflows/pre-release.yml # .mokogitea/workflows/repo-health.yml # .mokogitea/workflows/security-audit.yml # .script-registry.json # CHANGELOG.md # PLUGIN_SCRIPTS.md # README.md # analysis/index.md # automation/bulk_joomla_template.php # automation/bulk_sync.php # automation/enrich_manifest_xml.php # automation/enrich_mokostandards_xml.php # automation/index.md # automation/migrate_to_gitea.php # automation/push_files.php # automation/push_manifest_xml.php # automation/push_mokostandards_xml.php # automation/repo_cleanup.php # bin/moko # cli/archive_repo.php # cli/audit_query.php # cli/badge_update.php # cli/branch_rename.php # cli/bulk_workflow_push.php # cli/bulk_workflow_trigger.php # cli/changelog_promote.php # cli/changelog_prune.php # cli/client_dashboard.php # cli/client_health_check.php # cli/client_inventory.php # cli/client_provision.php # cli/completion.php # cli/create_project.php # cli/create_repo.php # cli/deploy_joomla.php # cli/dev_branch_reset.php # cli/grafana_dashboard.php # cli/joomla_build.php # cli/joomla_compat_check.php # cli/joomla_metadata_validate.php # cli/joomla_release.php # cli/license_manage.php # cli/manifest_element.php # cli/manifest_licensing.php # cli/manifest_read.php # cli/package_build.php # cli/platform_detect.php # cli/release.php # cli/release_body_update.php # cli/release_cascade.php # cli/release_create.php # cli/release_manage.php # cli/release_mirror.php # cli/release_notes.php # cli/release_package.php # cli/release_promote.php # cli/release_publish.php # cli/release_validate.php # cli/release_verify.php # cli/scaffold_client.php # cli/sync_rulesets.php # cli/theme_lint.php # cli/updates_xml_build.php # cli/updates_xml_sync.php # cli/version_auto_bump.php # cli/version_bump.php # cli/version_bump_remote.php # cli/version_check.php # cli/version_read.php # cli/version_reset_dev.php # cli/version_set_platform.php # cli/wiki_sync.php # cli/workflow_sync.php # composer.json # deploy/backup-before-deploy.php # deploy/deploy-dolibarr.php # deploy/deploy-joomla.php # deploy/deploy-sftp.php # deploy/health-check.php # deploy/rollback-joomla.php # deploy/sync-joomla.php # fix/fix_line_endings.php # fix/fix_permissions.php # fix/fix_tabs.php # fix/fix_trailing_spaces.php # fix/index.md # index.md # lib/CliBase.php # lib/Common.php # lib/Enterprise/AbstractProjectPlugin.php # lib/Enterprise/ApiClient.php # lib/Enterprise/AuditLogger.php # lib/Enterprise/CheckpointManager.php # lib/Enterprise/CliFramework.php # lib/Enterprise/Config.php # lib/Enterprise/ConfigValidator.php # lib/Enterprise/EnterpriseReadinessValidator.php # lib/Enterprise/ErrorRecovery.php # lib/Enterprise/FileFixUtility.php # lib/Enterprise/GitHubAdapter.php # lib/Enterprise/GitPlatformAdapter.php # lib/Enterprise/InputValidator.php # lib/Enterprise/ManifestParser.php # lib/Enterprise/ManifestReader.php # lib/Enterprise/MetricsCollector.php # lib/Enterprise/MokoGiteaAdapter.php # lib/Enterprise/PackageBuilder.php # lib/Enterprise/PlatformAdapterFactory.php # lib/Enterprise/PluginFactory.php # lib/Enterprise/PluginRegistry.php # lib/Enterprise/Plugins/ApiPlugin.php # lib/Enterprise/Plugins/DocumentationPlugin.php # lib/Enterprise/Plugins/DolibarrPlugin.php # lib/Enterprise/Plugins/GenericPlugin.php # lib/Enterprise/Plugins/JoomlaPlugin.php # lib/Enterprise/Plugins/McpServerPlugin.php # lib/Enterprise/Plugins/MobilePlugin.php # lib/Enterprise/Plugins/NodeJsPlugin.php # lib/Enterprise/Plugins/PythonPlugin.php # lib/Enterprise/Plugins/TerraformPlugin.php # lib/Enterprise/Plugins/WordPressPlugin.php # lib/Enterprise/ProjectConfigValidator.php # lib/Enterprise/ProjectMetricsCollector.php # lib/Enterprise/ProjectPluginInterface.php # lib/Enterprise/ProjectTypeDetector.php # lib/Enterprise/RecoveryError.php # lib/Enterprise/RecoveryManager.php # lib/Enterprise/RepositoryHealthChecker.php # lib/Enterprise/RepositorySynchronizer.php # lib/Enterprise/RetryHelper.php # lib/Enterprise/SecurityValidator.php # lib/Enterprise/SourceResolver.php # lib/Enterprise/SynchronizationException.php # lib/Enterprise/TransactionManager.php # lib/Enterprise/UnifiedValidation.php # lib/index.md # lib/plugins/Joomla/UpdateXmlGenerator.php # maintenance/index.md # maintenance/pin_action_shas.php # maintenance/repo_inventory.php # maintenance/rotate_secrets.php # maintenance/setup_labels.php # maintenance/sync_dolibarr_readmes.php # maintenance/update_repo_inventory.php # maintenance/update_sha_hashes.php # maintenance/update_version_from_readme.php # mcp/config.example.json # mcp/package.json # mcp/src/config.ts # mcp/src/index.ts # mcp/src/runner.ts # mcp/src/types.ts # phpcs.xml # plugin_health_check.php # plugin_list.php # plugin_metrics.php # plugin_readiness.php # plugin_validate.php # release/generate_dolibarr_version_txt.php # release/generate_joomla_update_xml.php # src/functions.php # templates/configs/README.md # templates/configs/index.md # templates/configs/manifest.xml.template # templates/configs/manifest.yml.template # templates/configs/mokostandards.xml.template # templates/configs/mokostandards.yml.template # templates/configs/phpcs.xml # templates/docs/README.md # templates/docs/extra/README.md # templates/docs/extra/index.md # templates/docs/index.md # templates/docs/required/GOVERNANCE.md # templates/docs/required/README.md # templates/docs/required/index.md # templates/docs/required/template-CONTRIBUTING.md # templates/docs/required/template-README.md # templates/docs/required/template-SECURITY.md # templates/index.md # templates/licenses/README.md # templates/licenses/index.md # templates/makefiles/README.md # templates/mokogitea/CLAUDE.dolibarr.md.template # templates/mokogitea/CLAUDE.joomla.md.template # templates/mokogitea/CLAUDE.md.template # templates/mokogitea/ISSUE_TEMPLATE/config.yml # templates/mokogitea/ISSUE_TEMPLATE/documentation.md # templates/mokogitea/ISSUE_TEMPLATE/dolibarr_module_id_request.md # templates/mokogitea/ISSUE_TEMPLATE/feature_request.md # templates/mokogitea/ISSUE_TEMPLATE/security.md # templates/mokogitea/README.md # templates/mokogitea/copilot-instructions.dolibarr.md.template # templates/mokogitea/copilot-instructions.joomla.md.template # templates/mokogitea/copilot-instructions.md.template # templates/mokogitea/dependabot.yml.template # templates/mokogitea/override.tf.template # templates/required/README.md # templates/schemas/README.md # templates/schemas/manifest-schema.xsd # templates/schemas/moko-platform-schema.xsd # templates/schemas/mokostandards-schema.xsd # templates/schemas/schemas/README.md # templates/schemas/template-repository-structure.xml # templates/scripts/README.md # templates/scripts/common/CliBase.template.php # templates/scripts/fix/index.md # templates/scripts/index.md # templates/scripts/release/index.md # templates/scripts/release/package_dolibarr.php # templates/scripts/release/package_joomla.php # templates/scripts/sftp-config/README.md # templates/scripts/validate/dolibarr_module.php # templates/scripts/validate/index.md # templates/scripts/validate/validate_manifest.php # templates/scripts/validate/validate_structure.php # templates/security/README.md # templates/security/index.php # templates/stubs/dolibarr.php # templates/stubs/joomla.php # templates/web/index.php # tests/Enterprise/GitPlatformAdapterTest.php # tests/Unit/VersionBumpTest.php # tests/Unit/VersionReadTest.php # tests/index.md # tests/test_circuit_breaker_handling.php # tests/test_enterprise_libraries.php # validate/SECURITY_SCANNING.md # validate/auto_detect_platform.php # validate/check_changelog.php # validate/check_client_theme.php # validate/check_composer_deps.php # validate/check_dolibarr_module.php # validate/check_enterprise_readiness.php # validate/check_file_integrity.php # validate/check_joomla_manifest.php # validate/check_language_structure.php # validate/check_license_headers.php # validate/check_no_secrets.php # validate/check_paths.php # validate/check_php_syntax.php # validate/check_repo_health.php # validate/check_structure.php # validate/check_tabs.php # validate/check_version_consistency.php # validate/check_wiki_health.php # validate/check_xml_wellformed.php # validate/index.md # validate/scan_drift.php # wrappers/auto_detect_platform.php # wrappers/bulk_sync.php # wrappers/check_changelog.php # wrappers/check_dolibarr_module.php # wrappers/check_enterprise_readiness.php # wrappers/check_joomla_manifest.php # wrappers/check_language_structure.php # wrappers/check_license_headers.php # wrappers/check_no_secrets.php # wrappers/check_paths.php # wrappers/check_php_syntax.php # wrappers/check_repo_health.php # wrappers/check_structure.php # wrappers/check_tabs.php # wrappers/check_version_consistency.php # wrappers/check_xml_wellformed.php # wrappers/deploy_sftp.php # wrappers/fix_line_endings.php # wrappers/fix_permissions.php # wrappers/fix_tabs.php # wrappers/fix_trailing_spaces.php # wrappers/gen_wrappers.php # wrappers/index.md # wrappers/pin_action_shas.php # wrappers/plugin_health_check.php # wrappers/plugin_list.php # wrappers/plugin_metrics.php # wrappers/plugin_readiness.php # wrappers/plugin_validate.php # wrappers/scan_drift.php # wrappers/setup_labels.php # wrappers/sync_dolibarr_readmes.php # wrappers/update_sha_hashes.php # wrappers/update_version_from_readme.php
554 lines
22 KiB
PHP
554 lines
22 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
|
|
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* This file is part of a Moko Consulting project.
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
<<<<<<< HEAD
|
|
* DEFGROUP: MokoCLI.CLI
|
|
* INGROUP: MokoCLI
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli
|
|
=======
|
|
* DEFGROUP: mokoplatform.CLI
|
|
* INGROUP: mokoplatform
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
|
>>>>>>> main
|
|
* PATH: /cli/joomla_release.php
|
|
* BRIEF: Joomla release pipeline — build ZIP+tar.gz, upload to GitHub Release, update updates.xml
|
|
*
|
|
* USAGE
|
|
* php cli/joomla_release.php --repo MokoCassiopeia --stability stable
|
|
* php cli/joomla_release.php --repo MokoCassiopeia --stability development
|
|
* php cli/joomla_release.php --repo MokoCassiopeia --stability rc --dry-run
|
|
* php cli/joomla_release.php --path /local/repo --stability stable
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use MokoCli\{ApiClient, AuditLogger, CliFramework, Config, PlatformAdapterFactory, SourceResolver};
|
|
|
|
/**
|
|
* Joomla Release Manager
|
|
*
|
|
* Creates and manages Joomla extension releases on Gitea, including
|
|
* package building, asset upload, and update stream management.
|
|
*
|
|
* @since 04.06.00
|
|
*/
|
|
class JoomlaRelease extends CliFramework
|
|
{
|
|
private const VERSION = '09.23.00';
|
|
private const ORG = 'MokoConsulting';
|
|
|
|
private const STABILITY_TAGS = [
|
|
'development' => 'development',
|
|
'alpha' => 'alpha',
|
|
'beta' => 'beta',
|
|
'rc' => 'release-candidate',
|
|
'stable' => null,
|
|
];
|
|
|
|
private const SUFFIXES = [
|
|
'development' => '-dev',
|
|
'alpha' => '-alpha',
|
|
'beta' => '-beta',
|
|
'rc' => '-rc',
|
|
'stable' => '',
|
|
];
|
|
|
|
private ApiClient $api;
|
|
private \MokoCli\GitPlatformAdapter $adapter;
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this->setDescription('Joomla release pipeline — build packages, upload, update updates.xml');
|
|
$this->addArgument('--repo', 'Repository name (e.g., MokoCassiopeia)', '');
|
|
$this->addArgument('--path', 'Local repo path (alternative to --repo)', '.');
|
|
$this->addArgument('--stability', 'Stability level: development|alpha|beta|rc|stable', 'stable');
|
|
$this->addArgument('--dry-run', 'Preview without making changes', false);
|
|
$this->addArgument('--verbose', 'Show detailed output', false);
|
|
}
|
|
|
|
protected function run(): int
|
|
{
|
|
$repo = (string) $this->getArgument('--repo');
|
|
$path = (string) $this->getArgument('--path');
|
|
$stability = (string) $this->getArgument('--stability');
|
|
$dryRun = (bool) $this->getArgument('--dry-run');
|
|
|
|
if (!array_key_exists($stability, self::STABILITY_TAGS)) {
|
|
$this->log('ERROR', "Invalid stability: {$stability}. Use: " . implode(', ', array_keys(self::STABILITY_TAGS)));
|
|
return 1;
|
|
}
|
|
|
|
$config = Config::load();
|
|
$this->adapter = PlatformAdapterFactory::create($config);
|
|
$this->api = $this->adapter->getApiClient();
|
|
|
|
if ($repo !== '') {
|
|
$path = $this->cloneRepo($repo);
|
|
if ($path === null) {
|
|
return 1;
|
|
}
|
|
}
|
|
$path = rtrim($path, '/\\');
|
|
|
|
$this->log('INFO', "Joomla Release Pipeline v" . self::VERSION);
|
|
$this->log('INFO', "Path: {$path} | Stability: {$stability} | Dry run: " . ($dryRun ? 'yes' : 'no'));
|
|
|
|
// ── Step 1: Parse manifest ────────────────────────────────────
|
|
$manifest = $this->findManifest($path);
|
|
if ($manifest === null) {
|
|
$this->log('ERROR', 'No Joomla XML manifest found');
|
|
return 1;
|
|
}
|
|
|
|
$meta = $this->parseManifest($manifest);
|
|
$this->log('INFO', "Extension: {$meta['name']} ({$meta['type']}) — element: {$meta['element']}");
|
|
|
|
// ── Step 2: Read version ──────────────────────────────────────
|
|
$version = $this->readVersion($path) ?? $meta['version'];
|
|
if ($version === '') {
|
|
$this->log('ERROR', 'No version found in README.md or manifest');
|
|
return 1;
|
|
}
|
|
|
|
$suffix = self::SUFFIXES[$stability];
|
|
$displayVersion = $version . $suffix;
|
|
$major = explode('.', $version)[0];
|
|
$releaseTag = self::STABILITY_TAGS[$stability] ?? "v{$major}";
|
|
|
|
$this->log('INFO', "Version: {$displayVersion} | Release tag: {$releaseTag}");
|
|
|
|
// ── Step 3: Build packages ────────────────────────────────────
|
|
$srcDir = SourceResolver::resolveAbsolute($path);
|
|
if ($srcDir === null) {
|
|
$this->log('ERROR', 'No source/ or src/ directory');
|
|
return 1;
|
|
}
|
|
SourceResolver::warnIfLegacy($path);
|
|
|
|
$prefix = $this->typePrefix($meta);
|
|
$zipName = "{$prefix}{$meta['element']}-{$displayVersion}.zip";
|
|
$tarName = "{$prefix}{$meta['element']}-{$displayVersion}.tar.gz";
|
|
$zipPath = sys_get_temp_dir() . "/{$zipName}";
|
|
$tarPath = sys_get_temp_dir() . "/{$tarName}";
|
|
|
|
$this->log('INFO', "Type: {$meta['type']} | Element: {$meta['element']} | Group: {$meta['group']}");
|
|
|
|
$sha256 = 'dry-run';
|
|
if (!$dryRun) {
|
|
if ($meta['type'] === 'package') {
|
|
$this->buildPackageZip($srcDir, $zipPath);
|
|
} else {
|
|
$this->buildZip($srcDir, $zipPath);
|
|
}
|
|
$this->buildTarGz($srcDir, $tarPath);
|
|
$sha256 = hash_file('sha256', $zipPath);
|
|
$this->log('SUCCESS', "ZIP: {$zipName} (" . filesize($zipPath) . " bytes)");
|
|
$this->log('SUCCESS', "tar.gz: {$tarName} (" . filesize($tarPath) . " bytes)");
|
|
$this->log('SUCCESS', "SHA-256: {$sha256}");
|
|
} else {
|
|
$this->log('INFO', "[DRY-RUN] Would build: {$zipName} + {$tarName}");
|
|
}
|
|
|
|
// ── Step 4: Upload to GitHub Release ──────────────────────────
|
|
$repoFullName = self::ORG . '/' . ($repo ?: basename(realpath($path) ?: $path));
|
|
|
|
if (!$dryRun) {
|
|
$packageName = "{$prefix}{$meta['element']}-{$displayVersion}";
|
|
$this->ensureRelease($repoFullName, $releaseTag, $displayVersion, $stability, $meta['name'], $packageName);
|
|
$this->uploadAsset($repoFullName, $releaseTag, $zipPath, $zipName);
|
|
$this->uploadAsset($repoFullName, $releaseTag, $tarPath, $tarName);
|
|
$this->log('SUCCESS', "Uploaded to release: {$releaseTag}");
|
|
} else {
|
|
$this->log('INFO', "[DRY-RUN] Would upload to {$releaseTag}");
|
|
}
|
|
|
|
// ── Step 5: Update updates.xml ────────────────────────────────
|
|
$updatesXml = "{$path}/updates.xml";
|
|
$zipUrl = "https://github.com/{$repoFullName}/releases/download/{$releaseTag}/{$zipName}";
|
|
$tarUrl = "https://github.com/{$repoFullName}/releases/download/{$releaseTag}/{$tarName}";
|
|
|
|
$entry = $this->buildUpdateEntry($meta, $displayVersion, $stability, $zipUrl, $tarUrl, $sha256);
|
|
|
|
if (!$dryRun) {
|
|
$this->mergeUpdateEntry($updatesXml, $stability, $entry);
|
|
$this->log('SUCCESS', "updates.xml updated ({$stability}: {$displayVersion})");
|
|
} else {
|
|
$this->log('INFO', "[DRY-RUN] Would update updates.xml");
|
|
}
|
|
|
|
echo "\n";
|
|
$this->log('SUCCESS', "Release complete: {$displayVersion} → {$releaseTag}");
|
|
|
|
if (!$dryRun) {
|
|
@unlink($zipPath);
|
|
@unlink($tarPath);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// ── Manifest ─────────────────────────────────────────────────────
|
|
|
|
private function findManifest(string $path): ?string
|
|
{
|
|
foreach ([$path, "{$path}/src", "{$path}/htdocs"] as $dir) {
|
|
if (!is_dir($dir)) {
|
|
continue;
|
|
}
|
|
foreach (glob("{$dir}/*.xml") as $file) {
|
|
if (str_contains((string) file_get_contents($file), '<extension')) {
|
|
return $file;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private function parseManifest(string $file): array
|
|
{
|
|
$xml = simplexml_load_file($file);
|
|
$name = (string) ($xml->name ?? '');
|
|
$type = (string) ($xml->attributes()->type ?? 'component');
|
|
$element = (string) ($xml->element ?? '');
|
|
$client = (string) ($xml->attributes()->client ?? '');
|
|
$group = (string) ($xml->attributes()->group ?? '');
|
|
$version = (string) ($xml->version ?? '');
|
|
$phpMin = (string) ($xml->php_minimum ?? '');
|
|
|
|
// Templates don't have <element> — derive from <name>
|
|
if ($element === '') {
|
|
// Strip type prefix (e.g. "Template - ") before deriving element
|
|
$baseName = preg_replace('/^(Package|Plugin|Module|Component|Template|Library|File)\s*-\s*/i', '', $name);
|
|
$element = strtolower(str_replace([' ', '-'], '', $baseName));
|
|
}
|
|
|
|
$tp = '';
|
|
if (isset($xml->targetplatform)) {
|
|
$tpNode = $xml->targetplatform;
|
|
$tp = '<targetplatform name="' . ($tpNode->attributes()->name ?? 'joomla')
|
|
. '" version="' . ($tpNode->attributes()->version ?? '5.*') . '" />';
|
|
}
|
|
if ($tp === '') {
|
|
$tp = '<targetplatform name="joomla" version="5.*" />';
|
|
}
|
|
|
|
return compact('name', 'type', 'element', 'client', 'group', 'version', 'tp', 'phpMin');
|
|
}
|
|
|
|
private function readVersion(string $path): ?string
|
|
{
|
|
$readme = "{$path}/README.md";
|
|
if (!is_file($readme)) {
|
|
return null;
|
|
}
|
|
if (preg_match('/VERSION:\s*(\d{2}\.\d{2}\.\d{2})/', file_get_contents($readme), $m)) {
|
|
return $m[1];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// ── Package building ─────────────────────────────────────────────
|
|
|
|
|
|
/**
|
|
* Get the Joomla type prefix for ZIP naming.
|
|
*
|
|
* @param array $meta Parsed manifest metadata
|
|
* @return string Prefix like "plg_system_", "mod_", "com_", etc.
|
|
*/
|
|
private function typePrefix(array $meta): string
|
|
{
|
|
return match ($meta['type']) {
|
|
'plugin' => "plg_{$meta['group']}_",
|
|
'module' => 'mod_',
|
|
'component' => 'com_',
|
|
'template' => 'tpl_',
|
|
'package' => 'pkg_',
|
|
'library' => 'lib_',
|
|
default => '',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Build a Joomla package ZIP (type="package") with nested sub-extension zips.
|
|
*
|
|
* @param string $srcDir Source directory containing pkg_*.xml and packages/
|
|
* @param string $outPath Output ZIP path
|
|
*/
|
|
private function buildPackageZip(string $srcDir, string $outPath): void
|
|
{
|
|
$staging = sys_get_temp_dir() . '/moko_pkg_' . uniqid();
|
|
mkdir($staging, 0755, true);
|
|
|
|
// 1. Zip each sub-extension in packages/
|
|
$packagesDir = $srcDir . '/packages';
|
|
if (is_dir($packagesDir)) {
|
|
foreach (glob("{$packagesDir}/*", GLOB_ONLYDIR) as $extDir) {
|
|
$subManifest = null;
|
|
foreach (glob("{$extDir}/*.xml") as $xml) {
|
|
if (str_contains(file_get_contents($xml), '<extension')) {
|
|
$subManifest = $xml;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($subManifest) {
|
|
$sub = $this->parseManifest($subManifest);
|
|
$prefix = $this->typePrefix($sub);
|
|
$subZipName = "{$prefix}{$sub['element']}.zip";
|
|
} else {
|
|
$subZipName = basename($extDir) . '.zip';
|
|
}
|
|
|
|
$this->log('INFO', " Sub-extension: {$subZipName}");
|
|
$this->buildZip($extDir, "{$staging}/{$subZipName}");
|
|
}
|
|
}
|
|
|
|
// 2. Copy package-level files (manifest, script, language)
|
|
foreach (glob("{$srcDir}/*.xml") as $f) {
|
|
copy($f, "{$staging}/" . basename($f));
|
|
}
|
|
foreach (glob("{$srcDir}/*.php") as $f) {
|
|
copy($f, "{$staging}/" . basename($f));
|
|
}
|
|
foreach (['language', 'administrator'] as $d) {
|
|
if (is_dir("{$srcDir}/{$d}")) {
|
|
$this->copyDir("{$srcDir}/{$d}", "{$staging}/{$d}");
|
|
}
|
|
}
|
|
|
|
// 3. Create the outer zip
|
|
$this->buildZip($staging, $outPath);
|
|
|
|
// Cleanup
|
|
$this->rmdir($staging);
|
|
}
|
|
|
|
/**
|
|
* Recursively copy a directory.
|
|
*/
|
|
private function copyDir(string $src, string $dst): void
|
|
{
|
|
if (!is_dir($dst)) {
|
|
mkdir($dst, 0755, true);
|
|
}
|
|
$iter = new \RecursiveIteratorIterator(
|
|
new \RecursiveDirectoryIterator($src, \FilesystemIterator::SKIP_DOTS),
|
|
\RecursiveIteratorIterator::SELF_FIRST
|
|
);
|
|
foreach ($iter as $item) {
|
|
$target = $dst . '/' . $iter->getSubPathname();
|
|
$item->isDir() ? (is_dir($target) || mkdir($target, 0755, true)) : copy($item->getPathname(), $target);
|
|
}
|
|
}
|
|
|
|
private function buildZip(string $srcDir, string $outPath): void
|
|
{
|
|
$zip = new \ZipArchive();
|
|
$zip->open($outPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
|
|
$iter = new \RecursiveIteratorIterator(
|
|
new \RecursiveDirectoryIterator($srcDir, \FilesystemIterator::SKIP_DOTS),
|
|
\RecursiveIteratorIterator::SELF_FIRST
|
|
);
|
|
foreach ($iter as $file) {
|
|
$local = str_replace('\\', '/', str_replace($srcDir . DIRECTORY_SEPARATOR, '', $file->getPathname()));
|
|
if ($this->isExcluded(basename($local))) {
|
|
continue;
|
|
}
|
|
$file->isDir() ? $zip->addEmptyDir($local) : $zip->addFile($file->getPathname(), $local);
|
|
}
|
|
$zip->close();
|
|
}
|
|
|
|
private function buildTarGz(string $srcDir, string $outPath): void
|
|
{
|
|
$tarPath = preg_replace('/\.gz$/', '', $outPath);
|
|
$phar = new \PharData($tarPath);
|
|
$phar->buildFromDirectory($srcDir);
|
|
$phar->compress(\Phar::GZ);
|
|
@unlink($tarPath);
|
|
}
|
|
|
|
private function isExcluded(string $name): bool
|
|
{
|
|
if ($name === '.ftpignore') {
|
|
return true;
|
|
}
|
|
if (str_starts_with($name, 'sftp-config')) {
|
|
return true;
|
|
}
|
|
if (str_starts_with($name, '.env')) {
|
|
return true;
|
|
}
|
|
$ext = pathinfo($name, PATHINFO_EXTENSION);
|
|
return in_array($ext, ['ppk', 'pem', 'key'], true);
|
|
}
|
|
|
|
// ── GitHub Release ───────────────────────────────────────────────
|
|
|
|
private function ensureRelease(
|
|
string $repo,
|
|
string $tag,
|
|
string $version,
|
|
string $stability,
|
|
string $extName = '',
|
|
string $packageName = ''
|
|
): void {
|
|
$releaseName = $extName !== ''
|
|
? "{$extName} {$version} ({$packageName})"
|
|
: (($stability === 'stable') ? "v" . explode('.', $version)[0] . " (latest: {$version})" : "{$tag} ({$version})");
|
|
try {
|
|
$this->api->get("/repos/{$repo}/releases/tags/{$tag}");
|
|
} catch (\Exception $e) {
|
|
$this->api->post("/repos/{$repo}/releases", [
|
|
'tag_name' => $tag,
|
|
'name' => $releaseName,
|
|
<<<<<<< HEAD
|
|
'body' => "## {$version}\n\nCreated by MokoCLI release pipeline.",
|
|
=======
|
|
'body' => "## {$version}\n\nCreated by mokoplatform release pipeline.",
|
|
>>>>>>> main
|
|
'prerelease' => ($stability !== 'stable'),
|
|
]);
|
|
}
|
|
}
|
|
|
|
private function uploadAsset(string $repo, string $tag, string $filePath, string $fileName): void
|
|
{
|
|
$release = $this->api->get("/repos/{$repo}/releases/tags/{$tag}");
|
|
$uploadUrl = str_replace('{?name,label}', '', $release['upload_url']);
|
|
|
|
foreach ($release['assets'] ?? [] as $asset) {
|
|
if ($asset['name'] === $fileName) {
|
|
$this->api->delete("/repos/{$repo}/releases/{$release['id']}/assets/{$asset['id']}");
|
|
}
|
|
}
|
|
|
|
$releaseConfig = Config::load();
|
|
$releasePlatform = $releaseConfig->getString('platform', 'gitea');
|
|
$releaseToken = $releasePlatform === 'gitea'
|
|
? $releaseConfig->getString('gitea.token', '')
|
|
: $releaseConfig->getString('github.token', '');
|
|
$acceptHeader = $releasePlatform === 'github' ? 'application/vnd.github+json' : 'application/json';
|
|
$ch = curl_init();
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_URL => "{$uploadUrl}?name=" . urlencode($fileName),
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => file_get_contents($filePath),
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HTTPHEADER => [
|
|
"Authorization: token {$releaseToken}",
|
|
'Content-Type: application/octet-stream',
|
|
"Accept: {$acceptHeader}",
|
|
],
|
|
]);
|
|
curl_exec($ch);
|
|
curl_close($ch);
|
|
}
|
|
|
|
// ── updates.xml ──────────────────────────────────────────────────
|
|
|
|
private function buildUpdateEntry(array $meta, string $version, string $stability, string $zipUrl, string $tarUrl, string $sha256): string
|
|
{
|
|
$lines = [' <update>'];
|
|
$lines[] = " <name>{$meta['name']}</name>";
|
|
$lines[] = " <description>{$meta['name']} ({$stability})</description>";
|
|
$lines[] = " <element>{$meta['element']}</element>";
|
|
$lines[] = " <type>{$meta['type']}</type>";
|
|
$lines[] = " <version>{$version}</version>";
|
|
|
|
if ($meta['client'] !== '') {
|
|
$lines[] = " <client>{$meta['client']}</client>";
|
|
} elseif (in_array($meta['type'], ['module', 'plugin'])) {
|
|
$lines[] = ' <client>site</client>';
|
|
}
|
|
if ($meta['group'] !== '' && $meta['type'] === 'plugin') {
|
|
$lines[] = " <folder>{$meta['group']}</folder>";
|
|
}
|
|
|
|
$lines[] = ' <tags>';
|
|
$lines[] = " <tag>{$stability}</tag>";
|
|
$lines[] = ' </tags>';
|
|
$lines[] = " <infourl title=\"{$meta['name']}\">https://git.mokoconsulting.tech/" . self::ORG . "</infourl>";
|
|
$lines[] = ' <downloads>';
|
|
$lines[] = " <downloadurl type=\"full\" format=\"zip\">{$zipUrl}</downloadurl>";
|
|
$lines[] = " <downloadurl type=\"full\" format=\"tar.gz\">{$tarUrl}</downloadurl>";
|
|
$lines[] = ' </downloads>';
|
|
|
|
if ($sha256 !== '' && $sha256 !== 'dry-run') {
|
|
$lines[] = " <sha256>sha256:{$sha256}</sha256>";
|
|
}
|
|
|
|
$lines[] = " {$meta['tp']}";
|
|
if ($meta['phpMin'] !== '') {
|
|
$lines[] = " <php_minimum>{$meta['phpMin']}</php_minimum>";
|
|
}
|
|
$lines[] = ' <maintainer>Moko Consulting</maintainer>';
|
|
$lines[] = ' <maintainerurl>https://mokoconsulting.tech</maintainerurl>';
|
|
$lines[] = ' </update>';
|
|
|
|
return implode("\n", $lines);
|
|
}
|
|
|
|
private function mergeUpdateEntry(string $xmlPath, string $stability, string $newEntry): void
|
|
{
|
|
if (!is_file($xmlPath)) {
|
|
file_put_contents($xmlPath, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<updates>\n{$newEntry}\n</updates>\n");
|
|
return;
|
|
}
|
|
|
|
$content = file_get_contents($xmlPath);
|
|
$pattern = '#\s*<update>.*?<tag>' . preg_quote($stability, '#') . '</tag>.*?</update>#s';
|
|
$content = preg_replace($pattern, '', $content);
|
|
$content = str_replace('</updates>', "{$newEntry}\n</updates>", $content);
|
|
$content = preg_replace('/\n{3,}/', "\n\n", $content);
|
|
file_put_contents($xmlPath, $content);
|
|
}
|
|
|
|
private function cloneRepo(string $repo): ?string
|
|
{
|
|
$tmpDir = sys_get_temp_dir() . "/joomla_release_{$repo}";
|
|
if (is_dir($tmpDir)) {
|
|
$this->rmdir($tmpDir);
|
|
}
|
|
$config = Config::load();
|
|
$platform = $config->getString('platform', 'gitea');
|
|
$token = $platform === 'gitea'
|
|
? $config->getString('gitea.token', '')
|
|
: $config->getString('github.token', '');
|
|
$cloneHost = $platform === 'gitea'
|
|
? rtrim($config->getString('gitea.url', 'https://git.mokoconsulting.tech'), '/')
|
|
: 'https://github.com';
|
|
$url = "https://x-access-token:{$token}@" . preg_replace('#^https?://#', '', $cloneHost) . '/' . self::ORG . "/{$repo}.git";
|
|
$cmd = ['git', 'clone', '--depth', '1', '--quiet', $url, $tmpDir];
|
|
$proc = proc_open($cmd, [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
|
|
proc_close($proc);
|
|
return is_dir($tmpDir) ? $tmpDir : null;
|
|
}
|
|
|
|
private function rmdir(string $dir): void
|
|
{
|
|
$iter = new \RecursiveIteratorIterator(
|
|
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS),
|
|
\RecursiveIteratorIterator::CHILD_FIRST
|
|
);
|
|
foreach ($iter as $file) {
|
|
$file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname());
|
|
}
|
|
rmdir($dir);
|
|
}
|
|
}
|
|
|
|
$app = new JoomlaRelease();
|
|
exit($app->execute());
|