diff --git a/CHANGELOG.md b/CHANGELOG.md index 06eb335..9ea8439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This update introduces minor bug fixes & improvements - Added new dynamic constant `%BUILD_OUTPUT_PATH%` which can be used as `%BUILD_OUTPUT_PATH%:release` to show the output path of a specific build configuration - Refactor CI templates to support dynamic build targets + - Added template `phpexe` & `phpgz` for generating executable binaries and compressed executables for the project ### Changed - Refactor phpmake template to support dynamic build targets diff --git a/src/ncc/Classes/PhpExtension/Templates/CompressedTemplate.php b/src/ncc/Classes/PhpExtension/Templates/CompressedTemplate.php new file mode 100644 index 0000000..8f3a52c --- /dev/null +++ b/src/ncc/Classes/PhpExtension/Templates/CompressedTemplate.php @@ -0,0 +1,61 @@ +value . '.gz.ncc' + ); + $release_compressed->setBuildType(BuildOutputType::NCC_PACKAGE->value); + $release_compressed->setOption(BuildConfigurationOptions::COMPRESSION->value, BuildConfigurationOptions\CompressionOptions::HIGH->value); + $project_manager->getProjectConfiguration()->getBuild()->addBuildConfiguration($release_compressed); + + // Create the debug build configuration + $debug_compressed = new BuildConfiguration('debug-compressed', + 'build' . DIRECTORY_SEPARATOR . 'debug' . DIRECTORY_SEPARATOR . AssemblyConstants::ASSEMBLY_PACKAGE->value . '.gz.ncc' + ); + $debug_compressed->setBuildType(BuildOutputType::NCC_PACKAGE->value); + $debug_compressed->setOption(BuildConfigurationOptions::COMPRESSION->value, BuildConfigurationOptions\CompressionOptions::HIGH->value); + $debug_compressed->setDefinedConstant('DEBUG', '1'); + $project_manager->getProjectConfiguration()->getBuild()->addBuildConfiguration($debug_compressed); + + $project_manager->save(); + } + } \ No newline at end of file diff --git a/src/ncc/Classes/PhpExtension/Templates/ExecutableTemplate.php b/src/ncc/Classes/PhpExtension/Templates/ExecutableTemplate.php new file mode 100644 index 0000000..39458a3 --- /dev/null +++ b/src/ncc/Classes/PhpExtension/Templates/ExecutableTemplate.php @@ -0,0 +1,77 @@ +getProjectConfiguration()->getBuild()->getBuildConfigurations() as $build_configuration) + { + $executable_name = sprintf('%s-executable', $build_configuration); + $configuration = $project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration); + + // Skip if the executable version of the build configuration already exists + if($project_manager->getProjectConfiguration()->getBuild()->buildConfigurationExists($executable_name)) + { + continue; + } + + // Skip if the build configuration is not an ncc package that the executable can be based on + if($configuration->getBuildType() !== BuildOutputType::NCC_PACKAGE->value) + { + continue; + } + + if(isset($configuration->getOptions()[BuildConfigurationOptions::COMPRESSION->value])) + { + $output = dirname($configuration->getOutput()) . DIRECTORY_SEPARATOR . str_replace('-', '_', $executable_name); + } + else + { + $output = dirname($configuration->getOutput()) . DIRECTORY_SEPARATOR . str_replace('-', '_', $executable_name) . '_gz'; + } + + // Create the executable build configuration + $executable = new BuildConfiguration($executable_name, $output); + $executable->setBuildType(BuildOutputType::EXECUTABLE->value); + $executable->setOption(BuildConfigurationOptions::NCC_CONFIGURATION->value, $configuration->getName()); + $project_manager->getProjectConfiguration()->getBuild()->addBuildConfiguration($executable); + } + + $project_manager->save(); + } + } \ No newline at end of file diff --git a/src/ncc/Classes/PhpExtension/Templates/github_ci.yml.tpl b/src/ncc/Classes/PhpExtension/Templates/github_ci.yml.tpl index 6cdee6b..24f65af 100644 --- a/src/ncc/Classes/PhpExtension/Templates/github_ci.yml.tpl +++ b/src/ncc/Classes/PhpExtension/Templates/github_ci.yml.tpl @@ -68,11 +68,15 @@ jobs: run: | php phpDocumentor.phar -d src -t docs + - name: Archive PHPDoc + run: | + zip -r docs.zip docs + - name: Upload PHPDoc uses: actions/upload-artifact@v4 with: name: documentation - path: docs + path: docs.zip test: needs: [%TPL_BUILD_NAMES%, check-phpunit] @@ -132,10 +136,17 @@ jobs: - name: Run PHPUnit tests run: | wget https://phar.phpunit.de/phpunit-11.3.phar - php phpunit-11.3.phar --configuration phpunit.xml + php phpunit-11.3.phar --configuration phpunit.xml --log-junit reports/junit.xml --log-teamcity reports/teamcity --testdox-html reports/testdox.html --testdox-text reports/testdox.txt - upload-artifacts: - needs: [%TPL_BUILD_NAMES%, test] + - name: Upload test reports + uses: actions/upload-artifact@v4 + with: + name: reports + path: reports + + + release-documentation: + needs: generate-phpdoc permissions: write-all runs-on: ubuntu-latest container: @@ -146,12 +157,31 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 -%TPL_DOWNLOAD_ARTIFACTS% + - name: Download documentation artifact + uses: actions/download-artifact@v4 + with: + name: documentation + path: documentation - - name: Upload to GitHub Release + - name: Upload documentation artifact uses: softprops/action-gh-release@v1 with: - files: | -%TPL_ARTIFACT_FILES% + files: | + documentation/* env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + + release-artifacts: + needs: [%TPL_BUILD_NAMES%] + permissions: write-all + runs-on: ubuntu-latest + container: + image: php:8.3 + if: github.event_name == 'release' + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + +%TPL_DOWNLOAD_ARTIFACTS% \ No newline at end of file diff --git a/src/ncc/Classes/PhpExtension/Templates/github_ci_download.yml.tpl b/src/ncc/Classes/PhpExtension/Templates/github_ci_download.yml.tpl index 108d931..bf26309 100644 --- a/src/ncc/Classes/PhpExtension/Templates/github_ci_download.yml.tpl +++ b/src/ncc/Classes/PhpExtension/Templates/github_ci_download.yml.tpl @@ -2,4 +2,11 @@ uses: actions/download-artifact@v4 with: name: %TPL_BUILD_NAME% - path: %TPL_BUILD_NAME% \ No newline at end of file + path: %TPL_BUILD_NAME% + - name: Upload %TPL_BUILD_NAME% artifact to release + uses: softprops/action-gh-release@v1 + with: + files: | + %TPL_BUILD_NAME%/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/src/ncc/Enums/ProjectTemplates.php b/src/ncc/Enums/ProjectTemplates.php index a5f08fa..57f1037 100644 --- a/src/ncc/Enums/ProjectTemplates.php +++ b/src/ncc/Enums/ProjectTemplates.php @@ -44,6 +44,16 @@ */ case PHP_UNIT = 'phpunit'; + /** + * A template that is used to create a PHP executable project + */ + case PHP_COMPRESSED = 'phpgz'; + + /** + * A template that is used to create a PHP executable project + */ + case PHP_EXECUTABLE = 'phpexe'; + /** * Template that combines PHP_LIBRARY, PHP_MAKE and PHP_UNIT in one */ diff --git a/src/ncc/Managers/ProjectManager.php b/src/ncc/Managers/ProjectManager.php index ace3ed5..fed4d3b 100644 --- a/src/ncc/Managers/ProjectManager.php +++ b/src/ncc/Managers/ProjectManager.php @@ -29,6 +29,8 @@ use ncc\Classes\PhpExtension\ExecutableCompiler; use ncc\Classes\PhpExtension\NccCompiler; use ncc\Classes\PhpExtension\Templates\CliTemplate; + use ncc\Classes\PhpExtension\Templates\CompressedTemplate; + use ncc\Classes\PhpExtension\Templates\ExecutableTemplate; use ncc\Classes\PhpExtension\Templates\GitHubWorkflowTemplate; use ncc\Classes\PhpExtension\Templates\LibraryTemplate; use ncc\Classes\PhpExtension\Templates\MakefileTemplate; @@ -209,10 +211,19 @@ PhpUnitTemplate::applyTemplate($this); break; + case ProjectTemplates::PHP_COMPRESSED: + CompressedTemplate::applyTemplate($this); + break; + + case ProjectTemplates::PHP_EXECUTABLE: + ExecutableTemplate::applyTemplate($this); + break; + case ProjectTemplates::PHP_LIBRARY_FULL: LibraryTemplate::applyTemplate($this); MakefileTemplate::applyTemplate($this); PhpUnitTemplate::applyTemplate($this); + CompressedTemplate::applyTemplate($this); break; case ProjectTemplates::PHP_CLI_FULL: @@ -220,6 +231,8 @@ LibraryTemplate::applyTemplate($this); MakefileTemplate::applyTemplate($this); PhpUnitTemplate::applyTemplate($this); + CompressedTemplate::applyTemplate($this); + ExecutableTemplate::applyTemplate($this); break; case ProjectTemplates::PHP_GITHUB_CI: diff --git a/src/ncc/Objects/ProjectConfiguration/Build.php b/src/ncc/Objects/ProjectConfiguration/Build.php index 577d7b7..e954b62 100644 --- a/src/ncc/Objects/ProjectConfiguration/Build.php +++ b/src/ncc/Objects/ProjectConfiguration/Build.php @@ -500,6 +500,25 @@ throw new InvalidArgumentException(sprintf('The build configuration "%s" does not exist', $name)); } + /** + * Checks if a build configuration exists + * + * @param string $name The name of the build configuration to check + * @return bool Returns true if the build configuration exists, false otherwise + */ + public function buildConfigurationExists(string $name): bool + { + try + { + $this->getBuildConfiguration($name); + return true; + } + catch(InvalidArgumentException) + { + return false; + } + } + /** * @param array $build_configurations * @return void