Skip to content

Commit

Permalink
Merge pull request #417 from range-of-motion/416-create-command-for-u…
Browse files Browse the repository at this point in the history
…pdating-version-file

Create command for updating version file
  • Loading branch information
range-of-motion authored Aug 16, 2023
2 parents 6ad9665 + 20f1c09 commit 1188f1b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions app/Console/Commands/UpdateVersionFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class UpdateVersionFile extends Command
{
protected $signature = 'app:update-version-file';

protected $description = 'Updates the version in version.txt';

public function handle(): int
{
if (trim(shell_exec('git rev-parse --is-inside-work-tree')) !== 'true') {
$this->warn('Not inside a Git repository, skipping');

return 0;
}

$version = trim(shell_exec('git describe --always --tags'));

$versionFile = fopen('version.txt', 'w');

fwrite($versionFile, $version);

fclose($versionFile);

$this->info('Detected ' . $version . ' and wrote to version file');

return 0;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"git rev-parse --is-inside-work-tree >/dev/null 2>&1 && git describe --always --tags > version.txt"
"php artisan app:update-version-file"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate"
Expand Down

0 comments on commit 1188f1b

Please sign in to comment.