Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Apr 16, 2021
1 parent bca42d1 commit 70e57e3
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions entrypoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
}


Expand Down Expand Up @@ -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);
}

0 comments on commit 70e57e3

Please sign in to comment.