|
44 | 44 | // info
|
45 | 45 | $clonedRepository='https://' . $hostRepositoryOrganizationName;
|
46 | 46 | note(sprintf('Cloning "%s" repository to "%s" directory', $clonedRepository, $cloneDirectory));
|
47 |
| -exec('git clone -- https://' . $publicAccessTokens . '@' . $hostRepositoryOrganizationName . ' ' . $cloneDirectory); |
| 47 | + |
| 48 | +$commandLine = 'git clone -- https://' . $publicAccessTokens . '@' . $hostRepositoryOrganizationName . ' ' . $cloneDirectory; |
| 49 | +exec_with_note($commandLine); |
48 | 50 |
|
49 | 51 |
|
50 | 52 | note('Cleaning destination repository of old files');
|
|
86 | 88 |
|
87 | 89 |
|
88 | 90 | // avoids doing the git commit failing if there are no changes to be commit, see https://stackoverflow.com/a/8123841/1348344
|
89 |
| -exec('git status', $outputLines); |
90 |
| -print_output_lines($outputLines); |
| 91 | +exec_with_output_print('git status'); |
91 | 92 |
|
92 | 93 | exec('git diff-index --quiet HEAD', $outputLines, $hasChangedFiles);
|
93 | 94 |
|
|
97 | 98 |
|
98 | 99 | if ($hasChangedFiles === 1) {
|
99 | 100 | note('Adding git commit');
|
100 |
| - exec('git add .', $outputLines); |
101 |
| - print_output_lines($outputLines); |
| 101 | + exec_with_output_print('git add .'); |
102 | 102 |
|
103 | 103 | $message = sprintf('Pushing git commit with "%s" message to "%s"', $commitMessage, $branch);
|
104 | 104 | note($message);
|
|
115 | 115 | $message = sprintf('Publishing "%s"', $tag);
|
116 | 116 | note($message);
|
117 | 117 |
|
118 |
| - // [debug] - show existing tags |
119 |
| - exec('git tag', $outputLines); |
120 |
| - note('Present tags:'); |
121 |
| - print_output_lines($outputLines); |
122 |
| - |
123 | 118 | $commandLine = sprintf('git tag %s -m "%s"', $tag, $message);
|
124 |
| - note('Running: ' . $commandLine); |
125 |
| - exec($commandLine); |
| 119 | + exec_with_note($commandLine); |
126 | 120 |
|
127 |
| - $commandLine = 'git push --quiet origin ' . $tag; |
128 |
| - note('Running: ' . $commandLine); |
129 |
| - exec($commandLine); |
| 121 | + exec_with_note('git push --quiet origin ' . $tag); |
130 | 122 | }
|
131 | 123 |
|
132 | 124 |
|
@@ -167,15 +159,21 @@ function resolve_public_access_token(): string
|
167 | 159 |
|
168 | 160 |
|
169 | 161 | function list_directory_files(string $directory) {
|
170 |
| - exec('ls -la ' . $directory, $outputLines); |
171 |
| - print_output_lines($outputLines); |
| 162 | + exec_with_output_print('ls -la ' . $directory); |
172 | 163 | }
|
173 | 164 |
|
174 |
| -/** |
175 |
| - * @param string[] $outputLines |
176 |
| - */ |
177 |
| -function print_output_lines(array $outputLines): void |
| 165 | + |
| 166 | +/********************* helper functions *********************/ |
| 167 | + |
| 168 | +function exec_with_note(string $commandLine): void |
178 | 169 | {
|
179 |
| - echo implode(PHP_EOL, $outputLines); |
| 170 | + note('Running: ' . $commandLine); |
| 171 | + exec($commandLine); |
180 | 172 | }
|
181 | 173 |
|
| 174 | + |
| 175 | +function exec_with_output_print(string $commandLine): void |
| 176 | +{ |
| 177 | + exec($commandLine, $outputLines); |
| 178 | + echo implode(PHP_EOL, $outputLines); |
| 179 | +} |
0 commit comments