protected function taskArtifactCreatePackages()
    {
        $rootDir      = getcwd();
        $tarBin       = $this->config(Config::KEY_ENV . '/' . Config::KEY_TAR_BIN);
        $gitDir       = $this->config(Config::KEY_DEPLOY . '/' . Config::KEY_GIT_DIR);
        $artifactsDir = $this->config(Config::KEY_DEPLOY . '/' . Config::KEY_ARTIFACTS_DIR);

        /** @var array $artifacts */
        $artifacts = $this->config(Config::KEY_DEPLOY . '/' . Config::KEY_ARTIFACTS);

        /** @var RoboFile|CollectionBuilder $collection */
        $collection = $this->collectionBuilder();
        $collection->progressMessage('cleanup old packages');

        // Ensure artifacts-dir is present
        $collection->taskFilesystemStack()->mkdir($artifactsDir);

        // Cleanup old tars
        foreach ($artifacts as $artifactName => $artifactConfig) {
            $file = "$artifactsDir/$artifactName";

            $task = $collection->taskFilesystemStack();
            $task->remove($file);
        }

        // Create Tars
        $collection->progressMessage('creating packages');
        foreach ($artifacts as $artifactName => $artifactConfig) {
            $dir = $artifactConfig['dir'];

            $artifactPath = "$rootDir/$artifactsDir/$artifactName";

            $tarOptions = '';
            if (array_key_exists('options', $artifactConfig)) {
                $options    = $artifactConfig['options'];
                $tarOptions = implode(' ', $options);
            }

            $tarCmd = "$tarBin $tarOptions -czf $artifactPath $dir";
            $task   = $collection->taskExec($tarCmd);
            $task->dir($gitDir);
        }

        return $collection;
    }