• Homebrew macOS पर CLI टूल्स को आसानी से install और manage करने वाला एक package manager है, जिसकी मदद से डेवलपर्स अक्सर इस्तेमाल होने वाले टूल्स के जरिए system environment को efficiently configure कर सकते हैं
  • यह गाइड Homebrew का उपयोग करके personal CLI scripts को distribute करने की प्रक्रिया समझाती है, और GitHub integration व automated workflow के जरिए maintenance को सरल बनाने का तरीका बताती है
  • distribution process CLI बनाना → GitHub release → Tap बनाना → Formula लिखना और update करना के क्रम में आगे बढ़ती है, और अंत में सिर्फ brew tap और brew install commands से installation संभव हो जाता है
  • Homebrew की terminology और best practices को समझने पर reproducibility और supply-chain security को मजबूत करने वाली stable distribution संभव होती है
  • GitHub Actions workflow के जरिए इसे automate किया जा सकता है, और एक बार setup हो जाने पर बाद में दूसरे CLI distribute करना भी काफ़ी आसान हो जाता है

पृष्ठभूमि और प्रेरणा

  • Homebrew CLI टूल install करने के लिए पसंदीदा package manager है, और बहुत से डेवलपर्स इसका उपयोग करते हैं
  • लेकिन अपने बनाए हुए CLI को अक्सर npm या RubyGem के ज़रिए distribute किया जाता है, इसलिए Homebrew distribution का तरीका थोड़ा अनजान लग सकता है
  • Homebrew के official core repository में self-made tools को register करने से Homebrew team आमतौर पर बचती है, इसलिए सामान्य डेवलपर्स अलग tap और formula के जरिए distribute करते हैं
  • यह गाइड सरल Ruby-आधारित CLI distribution अनुभव के आधार पर समझाती है

शब्दावली

  • Homebrew beer-brewing theme को दर्शाने वाली अपनी खास terminology इस्तेमाल करता है, इसलिए इन्हें समझने पर system structure को समझना आसान हो जाता है
    • Formula एक package definition file है, जिसमें source code या binary को install करने के निर्देश शामिल होते हैं
    • Tap, Formula का Git repository होता है, जिसमें user या organization के हिसाब से custom packages manage किए जाते हैं
    • Cask, GUI apps या बड़े binaries के installation manifest होते हैं; यह Formula जैसा है, लेकिन prebuilt files को handle करता है
    • Bottle, source से build किए बिना prebuilt binary package को copy करने का तरीका है, जिससे installation speed बढ़ती है
    • Cellar वह directory है जहाँ installed Formula रखे जाते हैं, जैसे /opt/homebrew/Cellar
    • Keg किसी खास Formula का installation instance directory है, जो Cellar के अंदर version के हिसाब से रखा जाता है

अवलोकन

  • Homebrew core repository niche या personal submissions स्वीकार नहीं करता, इसलिए users को CLI distribute करने के लिए अलग tap repository बनानी पड़ती है
    • 1. CLI बनाकर GitHub पर अपलोड करें और tag release करें
    • 2. brew tap-new से Tap बनाएं और GitHub पर push करें
    • 3. brew create से Formula बनाएं (tarball URL और SHA256 सहित)
    • 4. हर नए version release पर Formula update करें ताकि users brew install command से आसानी से install कर सकें
  • distribution पूरा होने के बाद user दो commands से CLI install कर सकता है: brew tap your_github_handle/tap और brew install your_cool_cli
    • यह गाइड CLI development को छोड़कर tap creation, Formula creation और update process पर focus करती है
    • उदाहरण के तौर पर iMessage database से interactive web archive बनाने वाले imsg CLI का उपयोग किया गया है

tap बनाना

  • Homebrew की tap creation guide को follow करें, और अपनी GitHub username या organization name के हिसाब से values बदलें
    • आगे सभी CLI tools को एक ही tap में रखने के लिए homebrew-tap नाम recommend किया गया है; homebrew prefix को CLI में special handling मिलती है और tap prefix प्रचलित convention है
  • tap creation command चलाएँ: brew tap-new searlsco/homebrew-tap
    • यह /opt/homebrew/Library/Taps/searlsco/homebrew-tap में scaffold बनाता है
    • GitHub पर corresponding repository बनाएं, फिर generated contents को push करें: cd /opt/homebrew/Library/Taps/searlsco/homebrew-tap, git remote add origin git@github.com:searlsco/homebrew-tap.git, git push -u origin main
  • tap का ownership लेने के बाद दूसरे users brew tap searlsco/tap command से repository clone करके उसे /opt/homebrew/Library/Taps में रख सकते हैं
    • शुरुआत में इसमें कोई उपयोगी content नहीं होगा, लेकिन basic behavior verify किया जा सकता है

Formula बनाना

  • Homebrew सीधे GitHub repository को refer कर सकता है, लेकिन reproducibility और open-source supply-chain security मजबूत करने के लिए versioned tarball और checksum इस्तेमाल करने की recommendation है
  • Formula creation command: brew create https://github.com/searlsco/imsg/archive/refs/tags/v0.0.5.tar.gz --tap searlsco/homebrew-tap --set-name imsg --ruby
    • --tap flag custom tap specify करता है और Formula को /opt/homebrew/Library/Taps/searlsco/homebrew-tap/Formula में रखता है
    • --set-name imsg Formula name को explicitly set करता है; duplicate names से बचने के लिए unique नाम चुनें (जैसे existing TLDR या standard CLI से conflict का ध्यान रखें)
    • --ruby Ruby CLI के लिए template preset है, जो customization आसान बनाने वाले कई options में से एक है
  • generated Formula शुरुआत में काम न करे तो LLM की मदद से उसे ठीक किया जा सकता है: brew install --verbose imsg चलाएँ, फिर error को ChatGPT में डालें और Formula update दोहराएँ
    • अंतिम Formula/imsg.rb file को Ruby CLI distribution के starting point के रूप में copy किया जा सकता है
    • language-specific package manager के बजाय Homebrew के जरिए distribute करने पर implementation language बदलने के बाद भी user upgrades सुचारु रहते हैं

Formula के मुख्य highlights

  • सभी Formula Ruby में लिखे जाते हैं, क्योंकि JavaScript या AI से पहले लोकप्रिय development tools का बड़ा हिस्सा Ruby-आधारित था
    • head method से Git repository specify किया जा सकता है, लेकिन इसका वास्तविक असर स्पष्ट नहीं है
    • livecheck जोड़ना Formula version updates आसान बनाता है, इसलिए यह उपयोगी है
    • binary execution test को help output check करके सरलता से implement किया जा सकता है; generated comments देखकर घबराने की जरूरत नहीं
    • brew style searlsco/tap command से style errors check करें
    • --ruby template का default uses_from_macos "ruby" 2.6.10 version इस्तेमाल करता है (COVID से पहले की release, 3 साल पहले EOL), इसलिए depends_on "ruby@3" के जरिए latest ruby Formula dependency recommend की जाती है
  • जब Formula संतोषजनक लगे, तो git push के साथ live deploy करें; users फिर brew tap searlsco/tap और brew install imsg से install कर सकते हैं

हर CLI release पर Formula update करना

  • Formula के ऊपर मौजूद url और sha256 hash को हर release पर manually update करना झंझट भरा है, और tag push या GitHub release बनाना भी थकाऊ लग सकता है
    • Homebrew का bump-formula-pr command या GitHub Actions PR बना सकते हैं, लेकिन fork और PR process बेवजह जटिल लगती है
    • अगर tap के owner आप ही हैं, तो main branch पर सीधे commit करने वाला सरल तरीका अधिक बेहतर है
  • इससे बचने के लिए Formula repository में GitHub workflow जोड़ने की recommendation है, ताकि release पर tap अपने आप update हो जाए
    • workflow example को copy करके इस्तेमाल किया जा सकता है
    • setup के लिए: GitHub personal access token (PAT) बनाते समय homebrew-tap repository पर ContentWrite permission दें, और उसे Formula repository Secrets में HOMEBREW_TAP_TOKEN नाम से save करें
    • environment variables के जरिए tap और Formula specify करें (जैसे line 13-15)
    • GitHub bot account update recommend किया गया है: GH_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com, GH_NAME: github-actions[bot]
  • release बनाने के बाद git push --tags चलाते ही कुछ ही सेकंड में automatic update हो जाता है, और users brew updatebrew upgrade imsg से upgrade कर सकते हैं

सबसे अच्छी बात

  • यह process जटिल ज़रूर है, लेकिन tap setup और एक Formula example पूरा हो जाने के बाद अतिरिक्त CLI distribution लगभग मामूली काम रह जाता है
    • कुछ ही मिनटों में नया Formula publish किया जा सकता है, जो काफी सुविधाजनक है
  • Homebrew की official process थोड़ी complex है, लेकिन automation इसे आसान बना देती है
    • हर tool के release और distribution के बीच की झंझट कम होती है, और अलग-अलग languages के CLI तक support बढ़ाया जा सकता है
  • वास्तव में कोई और Formula publish किया जाएगा या नहीं, यह निश्चित नहीं है, लेकिन यह संभावना खुली रहना ही संतोषजनक है

अभी कोई टिप्पणी नहीं है.

अभी कोई टिप्पणी नहीं है.