commandExecutor = new CommandExecutor($this); $this->install_dir = env('SENTRY_ROOT', getenv('HOME').'/.local/bin'); parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { if (! config('monica.sentry_support') || ! $this->check()) { return; } if ($this->confirmToProceed()) { $release = $this->option('release') ?? config('sentry.release'); $commit = $this->option('commit') ?? (is_dir(__DIR__.'/../../../.git') ? trim(exec('git log --pretty="%H" -n1 HEAD')) : $release); // Sentry update $this->commandExecutor->exec('Update sentry', $this->getSentryCli().' update'); // Create a release $this->execSentryCli('Create a release', 'releases new '.$release.' --finalize --project '.config('sentry-release.project')); // Associate commits with the release $this->execSentryCli('Associate commits with the release', 'releases set-commits '.$release.' --commit "'.config('sentry-release.repo').'@'.$commit.'"'); // Create a deploy $this->execSentryCli('Create a deploy', 'releases deploys '.$release.' new --env '.$this->option('environment').' --name '.config('monica.app_version')); if ($this->option('store-release')) { // Set sentry release $this->line('Store release in .sentry-release file', null, OutputInterface::VERBOSITY_VERBOSE); file_put_contents(__DIR__.'/../../../.sentry-release', $release); } } } private function check(): bool { $check = true; if (empty(config('sentry-release.auth_token'))) { $this->error('You must provide an auth_token (SENTRY_AUTH_TOKEN)'); $check = false; } if (empty(config('sentry-release.organisation'))) { $this->error('You must provide an organisation slug (SENTRY_ORG)'); $check = false; } if (empty(config('sentry-release.project'))) { $this->error('You must set the project (SENTRY_PROJECT)'); $check = false; } if (empty(config('sentry-release.repo'))) { $this->error('You must set the repository (SENTRY_REPO)'); $check = false; } if (empty($this->option('environment'))) { $this->error('No environment given'); $check = false; } return $check; } private function getSentryCli() { if (! file_exists($this->install_dir.'/'.self::SENTRY_CLI)) { mkdir($this->install_dir, 0777, true); $this->commandExecutor->exec('Downloading sentry-cli', 'curl -sL '.self::SENTRY_URL.' | INSTALL_DIR='.$this->install_dir.' bash'); } return $this->install_dir.'/'.self::SENTRY_CLI; } private function execSentryCli($message, $command) { $this->commandExecutor->exec($message, $this->getSentryCli().' '.$command); } }