diff --git a/bin/publish-latest-branch-build.php b/bin/publish-latest-branch-build.php index 1ce874c..49da3dd 100755 --- a/bin/publish-latest-branch-build.php +++ b/bin/publish-latest-branch-build.php @@ -1,243 +1,249 @@ #!/usr/bin/env php $ABI != null) + $telegram_apk_lines[] = "APK for {$generated_apk->$ABI}:"; foreach ($generated_apk->getTelegramCommentLines() as $apk_line) { $telegram_apk_lines[] = $apk_line; - $telegram_apk_lines[] = ""; + //$telegram_apk_lines[] = ""; } + $telegram_apk_lines[] = ""; + foreach ($generated_apk->getPhorgeCommentLines() as $apk_line) { $phorge_apk_lines[] = $apk_line; $phorge_apk_lines[] = ""; } } $telegram_apk_lines_str = implode("\n", $telegram_apk_lines); $phorge_apk_lines_str = implode("\n", $phorge_apk_lines); // add a comment to the build URL if (!empty($phorge_document_id) && empty(getenv('NO_COMMENT'))) { // We have a Differentials revision under review! $telegram_chat_content = implode("\n", [ // In Telegram, normal text must be escaped. Link destinations must not be escaped. TelegramStupidSDK::escapeMarkdownV2("⚙ Dear Android hackers, please review this promising patch:"), TelegramStupidSDK::escapeMarkdownV2("https://gitpull.it/$phorge_document_id"), "", TelegramStupidSDK::escapeMarkdownV2("Here the related fresh test builds:"), "", // The texts in these links are already escaped. $telegram_apk_lines_str, ]); // Send message to Telegram groups. echo "DEBUG TELEGRAM CONTENT\n"; echo "$telegram_chat_content\n"; // Send message to your default Telegram group. // See the TELEGRAM_* environment variables. (new TelegramStupidSDK())->sendMessage($telegram_chat_content); // Send message to Phorge. echo "Adding bipbop Comment to $phorge_document_id\n"; shell_exec(sprintf( "~/bin/phab-comment.php %s %s %s", escapeshellarg($phorge_document_id), escapeshellarg($apk_aligned_signed_url), escapeshellarg($apk_raw_sha256) )); } else { // We have NOT a Differentials revision under review! // So this is an atomic commit. $telegram_chat_content = implode("\n", [ "🌚 New commit: *$git_commit_title*", "https://gitpull.it/R4:$git_commit", "", "Here the related fresh test builds:", "", $telegram_apk_lines_str, ]); echo "DEBUG TELEGRAM CONTENT\n"; echo "$telegram_chat_content\n"; // Send message to your default Telegram group. // See the TELEGRAM_* environment variables. (new TelegramStupidSDK())->sendMessage($telegram_chat_content); } // delete very old files print_log_info("Cleaning old artifacts"); shell_exec(sprintf( "find %s -type f -mtime +120 -delete", escapeshellarg($ARTIFACTS_PATH) )); print_log_info("Done"); diff --git a/include/APK.php b/include/APK.php index 7566293..bb22ec0 100644 --- a/include/APK.php +++ b/include/APK.php @@ -1,78 +1,81 @@ name = $name; $this->url = $url; $this->sha256 = $sha256; + $this->ABI = $ABI; } /** * @return array */ public function getPhorgeCommentLines() { return [ $this->getPhorgeDownloadLink(), $this->getPhorgeAPKSignatureLine() ]; } /** * @return array */ public function getTelegramCommentLines() { return [ $this->getTelegramDownloadLink(), $this->getPhorgeAPKSignatureLine() ]; } /** * Get a very generic download link for Phorge. * @return string */ private function getPhorgeDownloadLink(): string { return sprintf( "[%s](%s)", "Download {$this->name}", $this->url ); } /** * Get a very generic download link for Phorge. * @return string */ private function getTelegramDownloadLink(): string { // In Telegram it seems we must escape the link text from special characters. // The link, instead, can be returned as-is. // So the Text from: "Download asd.apk" // to: "Download asd\\.apk" + $tempname = basename($this->name); return sprintf( "[%s](%s)", - TelegramStupidSDK::escapeMarkdownV2("Download {$this->name}"), + TelegramStupidSDK::escapeMarkdownV2("Download {$tempname}"), $this->url ); } /** * Get a very generic line about the sha256sum of this APK. * @return string */ private function getPhorgeAPKSignatureLine() { // NOTE: if you write a ":" here, Telegram will crash. Sanitize it for Telegram asd. return sprintf( - "APK sha256 `%s`", + "APK sha256: `%s`", $this->sha256 ); } } diff --git a/include/functions.php b/include/functions.php index 7a534aa..556da33 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,141 +1,153 @@ stdout); } /** * Execute a shell command and get the first output line. * @param string $command e.g. 'git' * @param string $args Command line arguments not-escaped (we will escape them) e.g. ['status'] * @return string First line of output from git status. */ function shell_line(string $command, array $args) { $lines = shell_lines($command, $args); foreach ($lines as $line) { return trim($line); } return null; } /** * Show a stupidly formatted log line. * @param string $msg */ function print_log($level, $msg) { printf("[%s][%s] %s\n", $level, date('Y-m-d H:i:s'), $msg ); } /** * Show a stupidly formatted log INFO line. * @param string $msg */ function print_log_info($msg) { print_log('INFO', $msg); } /** * Show a stupidly formatted log ERROR line. * @param string $msg */ function print_log_error($msg) { print_log('ERROR', $msg); } + +function extractABIFromAPK($filename) { + $start = strpos($filename, "app-"); + $end = strpos($filename, "-gitpull"); + + if ($start !== false && $end !== false && $end > $start + 4) { + return substr($filename, $start + 4, $end - ($start + 4)); + } else { + return null; // Or handle the case where the pattern is not found differently + } +} +