bash-lib Library for bash utility methods and tool开源项目

我要开发同款
匿名用户2021年11月09日
33阅读
开发技术SHELL
所属分类终端/远程登录、应用工具
授权协议Apache-2.0 License

作品详情

bash-lib

Introductoryblogpost:https://www.conjur.org/blog/stop-bashing-bash/

______________________________.'.'.|.'.'.'|.'_______________.'______________.'||___________||___________||||_=_|__=__|_=_||||_=_|__=__|_=_|||______||_____===_____||||_____===_____|||__________.'||_____===_____||||_____===_____||.'.'|.'||_____===_____||||_____===_____||.'.'|.'___________|_______________||_______________|.'__________.'||.----------.|.-----___-----.||.-----___-----.|||_____.----------.|]|||_____________||||_____________|||.'[|||||.-----___-----.||.-----___-----.||.'|||||||_____________||||_____________|||==========||||||.-----___-----.||.-----___-----.|||_____|||]o|||_____________||||_____________|||.'['o|||||.-----___-----.||.-----___-----.||.'|||||||||||_____________|||==========||||||||||.-----___-----.|||_____|||]||||||||||.'[|||__________|||_____________||||_____________|||.'________|__________|''----------'''------------------------------'''----------''(o)LGB(o)

Theplacetostorefunctionsthatareusedinpipelinesformultiplerepos.

Pleaseaddwhateverisusefultoyou,butkeepittidysoitsstillusefultoeveryoneelse:)

ReleaseStatus:Alpha

TL;DR:Readyforuse,butneedsexpansion.

Thefunctionsinthisrepoaretestedandreadyforuse,butcertainlibsareprettymuchplaceholders(eglogging).Thoseneedfurthercontributionsbeforetheyprovideacomprehensivesolution.

License:Apache2.0

Seethelicensefile

Usage

Addbash-libintoyourprojectinthewaythatbestfitsyourworkflow.Theonlyrequirementisthatyoupintheversionofbash-libthatyouuse.Thisisimportantsothatchangestobash-libdonothavethepowertobreakallprojectsthatusebash-lib.Yourprojectcanthentestupdatestobash-libandrollforwardperiodically.

Options:

Addasubmodule:theyareaneasywaytointegratebash-libandautomaticallyuseasingleSHAuntilmanuallyupdated.Submodulesaddapointerfromamountpointinyourrepototheexternalrepo(bash-lib),andrequireworkflowchangestoensurethatpointerisderferencedduringclone,checkoutandsomeotheropertaions.Addasubtree:Thisrepousessubtreestopullintestdependencies.Subtreescopyanexternalrepointoasubdirectoryofthehostrepo,noworkflowchangesarerequired.Subtreesnaturallykeepasingleversionofbash-libuntilexplicitlyupdated.Notethatsubtreemergecommitsdonotrebasewell⚠️,sobesttokeepsubtreeupdatesinseparatePRsfromnormalcommits.Clonebash-libinyourdeploymentprocess,bash-libdoesn'thavetobewithinyourrepo,justneedstobesomewherewhereyourscriptscansourceinit.Thisiswhereit'smostimportantthatyouimplementamechanismtoalwaysusethesameSHA,asaclonewilltrackmasterbydefault,whichisnotanalloweduseofbash-lib.

Onceyouhavebash-libclonedinyourproject,yousourcetwothings:

Sourcebash-lib/init.ThisensuressubmodulesareinitalisedandsetstheBASH_LIB_DIRenvvartotheabsolutepathtothebash-libdir.Thismakesiteasytosourcelibrariesfromotherscripts.Source${BASH_LIB_DIR}/lib-name/libforanylibrariesyouareinterestedin.

Youarenowreadytousebash-libfunctions:)

Structure

The/initscriptsetsupeverythingrequiredtousethelibrary,mostimportantlytheBASH_LIB_DIRvariablewhichgivestheabsolutepathtotherootofthelibraryandshouldbeusedforsourcingthemodules.

Therepoisorganizedintolibraries,eachlibraryisadirectorythathasalibfile.Sourcingthelibforalibraryshouldexposeallthefunctionsthatlibraryoffers.Thelibfilemaysourceorreferenceothersupportingfileswithinit'sdirectory.

.├──libname│├──lib│└──supporting-file├──init#initscript,sourcethisfirst├──run-tests#topleveltestscript,executesalltests├──secrets.yml#secretsrequiredforexecutingtests├──test-utils│├──bats#gitsubtree│├──bats-assert-1#gitsubtree│├──bats-support#gitsubtree│├──lib│└──tap2junit└──tests-for-this-repo├──filehandling.bats├──fixtures#│└──libname#Dircontainingtestfixturesforalibrary├──tap2junit├──libname.bats#containstestsforlibname/lib├──python-lint#supportingfilesforpythonlint├──run-bats-tests#scripttorunbatstests├──run-gitleaks#scripttocheckforleakedsecrets└──run-python-lint#scripttorunpythonlintContentsLibraryDescriptionFunctionsfilehandlingFunctionsrelatingtofileandpathhandlingbl_abs_path:EnsureapathisabsolutegitGithelpersbl_git_available:Trueifgitbinaryorfunctionisavailablebl_in_git_repo:Trueifcurrentdirectoryisagitworkingdirectorybl_github_owner_repo:returns$owner/$repoextractedfromtheurloftheoriginremotebl_repo_root:Findtherootofthecurrentgitrepo.bl_all_files_in_repo:Listfilestrackedbygit,excludessubmodules.bl_remote_latest_tag:Returnsthesymbolicnameofthelatesttagfromaremote.bl_remote_latest_tagged_commit:ReturnstheSHAofthemostrecentlytaggedcommitinaremoterepo(tag^{}).bl_remote_sha_for_ref:ReturnstheSHAforagivenreffromanamedremote.bl_remote_tag_for_sha:ReturnsthetagcorrespondingtoaSHAfromanamedremote-ifthereisone.bl_tracked_files_excluding_subtrees:Listfilestrackedbygit,butexcludinganyfilesthatareinpathslistedin.gittrees.bl_gittrees_present:Succeedsif.gittreesispresentintherootoftherepo,otherwisefails.bl_cat_gittrees:Returnsthecontentsof.gittreesfromthetopleveloftherepo,excludinganycomments.Failsif.gittreesisnotpresent.githubGithubRelatedFunctionsbl_hub_available:Trueifhubbinaryorfunctionisavailablebl_hub_creds_available:Trueifhubcredsareavailable(fileorenvvars)bl_hub_check:Preflightcheckforhub,trueifgitinstalled,ingitrepo,hubinstalledandhubcredsareavailablebl_hub_download_latest:Downloadlatesthubbinaryfromgithubandinstallto~/binorspecifiedpathbl_hub_issue_number_for_title:Findtheissuenumberforanissuefromitstitle,searchesopenissuesinthecurrentrepo.(currentrepo=workdingdirectory,repoisfoundbyoriginremote).Ifmultipleissuesmatchthesuppliedtitlestring,onlythefirstisreturned.bl_hub_add_issue_comment:Addacommenttoanissuebl_hub_comment_or_create_issue:Createissueifanissuematchingthetitledoesn'texist.Ifamatchisfound,addacommenttoithelpersBashscriptinghelpersbl_die:printmessageandexit1bl_fail:printmessageandreturn1bl_spushd/bl_spopd:Safeverisonsofpushd&popdthatcalldieifthepush/popfails,theyalsodropstdout.bl_is_num:Checkifavalueisanumberviaregexbl_retry:Retryacommanduntilitsucceedsuptoauserspecifiedmaximumnumberofattempts.Escalatingdelaybetweenattempts.bl_retry_constant:Retryacommanduntilitsucceedswithaconstantdelaybetweenattemptsk8sUtilsforconnectingtoK8sbl_build_gke_image:BuilddockerimageforrunningkubectlcommandsagainstGKE.bl_delete_gke_image:DeleteimagefromGKE.bl_run_docker_gke_command:Runcommandingke-utilscontainer,alreadyauthenticatedtok8scluster.loggingHelpersrelatedtologging.bl_announce:Echomessageinasciibannertodistinguishitfromotherlogmessages.bl_log:Logamessageatthespecifiedlevel.Defaultloglevelisinfo,changelevelbysettingenvironmentvariableBASH_LIB_LOG_LEVELbl_check_log_level:Checkifavalueisavalidbashlibloglevelbl_debug:Logamessageatdebuglevelbl_info:Logamessageatinfolevelbl_warning:Logamessageatwarninglevelbl_error:Logamessageaterrorlevelbl_fatal:LogamessageatfatallevelRubyHelpersrelatedtorubyinfrastructurebl_gem_latest_version:Returnthelatestversionofagemfromrubygems.orgbl_jq_available:Checkjqbinaryisavailablebl_curl_available:Checkcurlbinaryisavailabletest-utilsHelpersforexecutingtestsbl_shellcheck_script:Executeshellcheckagainstascript,usesdocker.bl_find_scripts:Findgittrackedfileswithextension.bl_tap2junit:ConvertasubsetofTAPtoJUnitXML.Retainslogsforerrors.bl_validate_changelog:CheckCHANGELOG.md(oraspecifiedfile)complieswithkeepachangelog.comformat.Contributing

Forfurtherinformationoncontributing,style&testing,pleaseseeCONTRIBUTING.md

MaintainersHughSaunders
查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论