diff --git a/entrypoint.php b/entrypoint.php index 61cbac3..74f844d 100755 --- a/entrypoint.php +++ b/entrypoint.php @@ -44,7 +44,9 @@ // info $clonedRepository='https://' . $hostRepositoryOrganizationName; note(sprintf('Cloning "%s" repository to "%s" directory', $clonedRepository, $cloneDirectory)); -exec('git clone -- https://' . $publicAccessTokens . '@' . $hostRepositoryOrganizationName . ' ' . $cloneDirectory); + +$commandLine = 'git clone -- https://' . $publicAccessTokens . '@' . $hostRepositoryOrganizationName . ' ' . $cloneDirectory; +exec_with_note($commandLine); note('Cleaning destination repository of old files'); @@ -86,8 +88,7 @@ // avoids doing the git commit failing if there are no changes to be commit, see https://stackoverflow.com/a/8123841/1348344 -exec('git status', $outputLines); -print_output_lines($outputLines); +exec_with_output_print('git status'); exec('git diff-index --quiet HEAD', $outputLines, $hasChangedFiles); @@ -97,8 +98,7 @@ if ($hasChangedFiles === 1) { note('Adding git commit'); - exec('git add .', $outputLines); - print_output_lines($outputLines); + exec_with_output_print('git add .'); $message = sprintf('Pushing git commit with "%s" message to "%s"', $commitMessage, $branch); note($message); @@ -115,18 +115,10 @@ $message = sprintf('Publishing "%s"', $tag); note($message); - // [debug] - show existing tags - exec('git tag', $outputLines); - note('Present tags:'); - print_output_lines($outputLines); - $commandLine = sprintf('git tag %s -m "%s"', $tag, $message); - note('Running: ' . $commandLine); - exec($commandLine); + exec_with_note($commandLine); - $commandLine = 'git push --quiet origin ' . $tag; - note('Running: ' . $commandLine); - exec($commandLine); + exec_with_note('git push --quiet origin ' . $tag); } @@ -167,15 +159,21 @@ function resolve_public_access_token(): string function list_directory_files(string $directory) { - exec('ls -la ' . $directory, $outputLines); - print_output_lines($outputLines); + exec_with_output_print('ls -la ' . $directory); } -/** - * @param string[] $outputLines - */ -function print_output_lines(array $outputLines): void + +/********************* helper functions *********************/ + +function exec_with_note(string $commandLine): void { - echo implode(PHP_EOL, $outputLines); + note('Running: ' . $commandLine); + exec($commandLine); } + +function exec_with_output_print(string $commandLine): void +{ + exec($commandLine, $outputLines); + echo implode(PHP_EOL, $outputLines); +}