Skip to content

Commit

Permalink
added logic to take into account files added to .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
rosven9856 committed Aug 13, 2024
1 parent 1de072b commit 704168f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.git
.idea
.env
vendor
Expand Down
21 changes: 19 additions & 2 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App;

use Automattic\IgnoreFile;
use App\Configuration\Configuration;

class Action
Expand Down Expand Up @@ -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');
Expand All @@ -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()));
}
}
Expand Down

0 comments on commit 704168f

Please sign in to comment.