From 704168fdb891a2caec1e04090b6fe438d91f71e7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 13 Aug 2024 19:45:19 +0300 Subject: [PATCH] added logic to take into account files added to .gitignore --- .gitignore | 1 + src/Action.php | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8a9b5a6..c9242a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.git .idea .env vendor diff --git a/src/Action.php b/src/Action.php index 74fe9f0..ca93f39 100644 --- a/src/Action.php +++ b/src/Action.php @@ -4,6 +4,7 @@ namespace App; +use Automattic\IgnoreFile; use App\Configuration\Configuration; class Action @@ -38,6 +39,8 @@ public function run() mkdir($directory, 0755, true); + $ignore = new IgnoreFile(); + $zip = new \ZipArchive(); if ($zip->open((string) $this->configuration->get('build.file'), \ZipArchive::CREATE) !== true) { throw new \Exception('Failed to create zip archive'); @@ -55,10 +58,24 @@ public function run() /** * @var \SplFileInfo $path */ + if ($path->getBasename() === '.gitignore') { + $ignore->add( + file_get_contents($path->getRealPath()), + dirname($path->getRealPath()) . '/' + ); + } + } + + foreach ($iterator as $path) { - // exclude files described in .gitignore + /** + * @var \SplFileInfo $path + */ + if (!$path->isFile()) { + continue; + } - if ($path->isFile()) { + if (!$ignore->ignores($path->getPathname())) { $zip->addFile($path->getPathname(), str_replace($rootDirectory . DIRECTORY_SEPARATOR, '', $path->getPathname())); } }