diff --git a/bin/publish-latest-branch-build.php b/bin/publish-latest-branch-build.php index b2a281d..80784d9 100755 --- a/bin/publish-latest-branch-build.php +++ b/bin/publish-latest-branch-build.php @@ -1,318 +1,319 @@ #!/usr/bin/env php getABI()) { $phorge_apk_lines[] = sprintf( - "APK for **%s**:", + "APK for **%s**: %s", $generated_apk->getABI(), + $generated_apk->getPhorgeDownloadLink() ); // TODO: understand why Telegram does not render as bold text lol. $telegram_apk_lines[] = sprintf( - "APK for **%s**:", - TelegramStupidSDK::escapeMarkdownV2($generated_apk->getABI()), + "APK for **%s**", + TelegramStupidSDK::escapeMarkdownV2($generated_apk->getABI()) ); } foreach ($generated_apk->getTelegramCommentLines() as $apk_line) { $telegram_apk_lines[] = $apk_line; } $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); $phorge_api = new ConduitClient($PHORGE_API_URL); $phorge_api->setConduitToken($PHORGE_API_TOKEN); // 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); // Publish comment on Phorge too. $phorge_chat_content = implode("\n", [ "Bip bop I'm a bot. Here fresh Android builds {icon cog spin}", "", $phorge_apk_lines_str, ]); $differential_args = [ 'objectIdentifier' => $phorge_document_id, 'transactions' => [ [ 'type' => 'comment', 'value' => $phorge_chat_content, ], ], ]; $phorge_result = $phorge_api->callMethodSynchronous('differential.revision.edit', $differential_args); } elseif (empty(getenv('NO_COMMENT'))) { // 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); // Publish comment on Phorge too. On the commit page? Uhm. To be tested. // $phorge_chat_content = implode("\n", [ // "{icon gear spin} Bip bop I'm a bot. Here fresh Android builds:", // "", // // The texts in these links are already escaped. // $phorge_apk_lines_str, // ]); // $differential_args = [ // 'objectIdentifier' => $phorge_document_id, // 'transactions' => [ // [ // 'type' => 'comment', // 'value' => $phorge_chat_content, // ], // ], // ]; // $phorge_result = $phorge_api->callMethodSynchronous('diffusion.commit.edit', $differential_args); } // 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 ead0e59..7c118cf 100644 --- a/include/APK.php +++ b/include/APK.php @@ -1,105 +1,108 @@ name = $name; $this->url = $url; $this->sha256 = $sha256; $this->ABI = $ABI; } /** * @return array */ public function getPhorgeCommentLines() { return [ - $this->getPhorgeDownloadLink(), - $this->getPhorgeAPKSignatureLine() + // In Phorge the download link is inline +// $this->getPhorgeDownloadLink(), + $this->getPhorgeAPKSignatureLine(), ]; } /** * Get the ABI architecture. */ public function getABI(): string { // TODO: calculate this. return $this->ABI; } /** * Get the final URL. */ public function getURL(): string { return $this->url; } /** * Get the sha256 of the APK file. */ public function getHash(): string { return $this->sha256; } /** * @return array */ public function getTelegramCommentLines() { return [ $this->getTelegramDownloadLink(), $this->getPhorgeAPKSignatureLine() ]; } /** * Get a very generic download link for Phorge. * @return string */ - private function getPhorgeDownloadLink(): string { + public function getPhorgeDownloadLink(): string { return sprintf( "[%s](%s)", - "Download {$this->name}", + $this->name, $this->url ); } /** * Get a very generic download link for Phorge. * @return string */ - private function getTelegramDownloadLink(): string { + public function getTelegramDownloadLink(): string { // In Telegram it seems we must escape the link text from special characters. // The link, instead, can be returned as-is. + // For some reasons, an emoji cannot be inside the link lol. // So the Text from: "Download asd.apk" // to: "Download asd\\.apk" return sprintf( - "[%s](%s)", - TelegramStupidSDK::escapeMarkdownV2("Download {$this->name}"), + "⬇️ [%s](%s)", + TelegramStupidSDK::escapeMarkdownV2("$this->name}"), $this->url ); } /** * Get a very generic line about the sha256sum of this APK. * @return string */ private function getPhorgeAPKSignatureLine() { return sprintf( - "APK sha256: `%s`", + "sha256 for %s: `%s`", + $this->getABI(), $this->sha256 ); } }