Building a Go Project - Travis CI Docs

文章推薦指數: 80 %
投票人數:10人

The rest of this guide covers configuring Go projects in Travis CI. ... As go get uses HTTPS to clone dependencies from GitHub rather than SSH, ... GettingStarted CoreConceptsforBeginners TravisCITutorial CustomizingtheBuild SpeedinguptheBuild UsingDockerinyourBuild HeadlessTestingwithBrowsers BuildingPullRequests CronJobs CommonBuildProblems CommandLineClient BuildConfigImports BuildConfigValidation Jobs,Builds,MatricesandStages JobLifecycle BuildMatrix BuildStages ConditionalBuilds,Stages,andJobs InstallingDependencies InstallingDependencies PrivateDependenciesGitHub PrivateDependenciesBitbucket SettingupServicesandDatabases CachingDependencies AddingtoSSHKnownHosts ProgrammingLanguages Android C C# C++ Clojure Crystal D Dart Elixir Elm Erlang F# Generic Go Groovy Haskell Haxe Java JavaScript(withNode.js) Julia MATLAB Minimal Nix Objective-C Perl Perl6 PHP Python R Ruby Rust Scala Smalltalk Swift VisualBasic Addingalanguage DeploymentsandUploads Overview anynines Atlas AWSCodeDeploy AWSElasticBeanstalk AWSLambda AWSOpsWorks AWSS3 AzureWebApps bintray BitBalloon BluemixCloudFoundry Boxfuse Catalyze ChefSupermarket Cloud66 CloudFoundry Cargo EngineYard GitHubPages GitHubReleases GoogleAppEngine GoogleCloudStorage GoogleFirebase Hackage Hephy Heroku Launchpad npm OpenShift packagecloud.io PuppetForge PyPI RackspaceCloudFiles RubyGems Scalingo Script SnapStore Surge.sh TestFairy Transifex UploadingBuildArtifacts CIEnvironmentReference Overview UbuntuLinuxCIEnvironmentReferences macOSCIEnvironmentReference WindowsCIEnvironmentReference FreeBSDCIEnvironmentReference BuildingonMultipleOperatingSystems BuildingonMultipleCPUArchitectures EnvironmentVariables BuildEnvironmentUpdates BuildMachinesIPAddresses EncryptingFilesandData EncryptingSensitiveData EncryptingFiles GitHubPermissionsusedbyTravisCI BitbucketPermissionsusedbyTravisCI AssemblaPermissionsusedbyTravisCI GitLabPermissionsusedbyTravisCI BestPracticesinSecuringYourData IntegrationsandNotifications ConfiguringNotifications ShowingBuildStatusImages CodeClimate DeepSource Coveralls CoverityScan BrowserStack SauceLabs SonarCloud SourceClear AtomFeeds CCMenu/CCTrayFeeds EmbeddedBuildswithPlatformIO 3rdPartyApps,ClientsandTools DeveloperProgram Overview APIV3 TriggeringBuildswithAPIV3 TheRubyLibrary HostedBilling Overview Auto-refill FAQ TravisCIEnterprise EnterpriseDocs Thisdocumentationsiteisopensource. TheREADMEinourGitrepositoryexplainshowtocontribute. ImprovethispageonGitHub BuildingaGoProject WhatThisGuideCovers SpecifyingaGoversiontouse GoModules GoImportPath DependencyManagement DefaultBuildScript EnvironmentVariable BuildConfigReference Examples WhatThisGuideCovers# Go Default Defaultinstall travis_install_go_dependencies[gobuild-args] Defaultscript travis_script_go{gobuild-args} Matrixkeys go,env Support TravisCI Minimalexample: language:go Notethat,inordertochooseGo1.10,youmustusego:"1.10"(astring),not go:1.10(afloat).UsingafloatresultsintheuseofGo1.1. ForLanguageversionsandotherbuild-environmentspecific informationvisitourreferencepages: Precise Trusty Xenial Bionic Windows FreeBSD TherestofthisguidecoversconfiguringGoprojectsinTravisCI.Ifyou’re newtoTravisCIpleasereadourTutorialandbuild configurationguidesfirst. SpecifyingaGoversiontouse# YoucanuseanytaggedversionofGo,aversionwithxinplaceoftheminor orpatchleveltousethelatestforagivenmajororminorversion,oruse mastertogetthelatestversionfromsource.Allgoversionmanagementis handledbygimme. language:go go: -1.x -"1.10" -1.11.x -master GoModules# AnyvaluesetforGO111MODULEvia.travis.ymlorrepositorysettingsisleft as-is.Ifabsent,adefaultvalueofGO111MODULE=autoisset. GoImportPath# TheprojectsourcecodewillbeplacedinGOPATH/src/{repo-source},butif vanityimportsare necessary(especiallyforinternalpackage imports), go_import_path:maybespecifiedatthetopleveloftheconfig,e.g.: go_import_path:example.org/pkg/foo DependencyManagement# Thedefaultinstallstepoftravis_install_go_dependencies [gobuild-args]willbehavedifferentlydependingontheGoversionspecified, aswellasthepresenceofcertainenvironmentvariablesandfilepaths. IfaMakefileispresentbyanyofthefollowingnames,thennofurtheractions aretakenintheinstallstep: GNUMakefile Makefile BSDmakefile makefile Inallothercases,thecommandgoget${gobuild_args}./...isrun. godepsupport# Thereissupportincludedforgodepwhenused withvendoreddependenciessuchthattheGOPATHwillbeprefixedwith ${TRAVIS_BUILD_DIR}/Godeps/_workspaceandPATHwillbeprefixedwith ${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin.Additionally,ifthe Godeps/_workspace/srcdirectorydoesnotexist,godepwillbeinstalledand agodeprestorewillberun. ItisimportanttonotethatusingtheolderstyleGodeps.jsonatthetop levelisnotsupported. Allofthegodepintegrationstepsareperformedpriortotheseparate gogetandmakefilestepslistedabove. Notethatthegodepsupportisonlyactivatedifacustominstallstepis notspecified. InstallingPrivateDependencies# AsgogetusesHTTPStoclonedependenciesfromGitHubratherthanSSH,it requiresadifferentworkaroundfromourrecommendedwayofhandlingprivate dependencies. WhencloningviaHTTPS,gitusescurlunderthecovers,whichinturnallows youtospecifya.netrc file,whereyoucanstorecustomauthenticationcredentialsforspecific domains,github.comforinstance. GotoyourGitHubaccountand createapersonalaccesstoken. Makesuretogiveitthereposcope,whichallowsaccessingprivate repositories. Toreduceaccessrightsofthetoken,youcanalsocreateaseparateuser accountwithaccesstoonlytherepositoriesyouneedforaparticularproject. Copythetokenandstoreitina.netrcinyourrepository,withthefollowing data: machinegithub.com login password Addthistoyourrepositoryandaddthefollowingstepstoyour.travis.yml: before_install: -cp.netrc~/.netrc -chmod600~/.netrc DefaultBuildScript# GoprojectsassumethateitherMakeorGobuildtoolareusedbydefault.In casethereisaMakefileintherepositoryroot,thedefaultcommandTravisCI willusetorunyourprojecttestsuiteis make IncasethereisnoMakefile,itwillbe gotest${gobuild_args}./... instead. Thesedefaultcommandscanbeoverriddenasdescribedinthegeneralbuild configurationguide.Forexample,toaddthe -vflag,overridethescript:keyin.travis.ymllikethis: script:gotest-v./... Theargumentspassedtothedefaultgotestcommandmaybeoverriddenby specifyinggobuild_args:atthetopleveloftheconfig,e.g.: gobuild_args:-x-ldflags"-Xmain.VersionStringv1.2.3" whichwillresultinthescriptstepbeing: gotest-x-ldflags"-Xmain.VersionStringv1.2.3"./... TobuildbyrunningSconswithoutarguments,usethis: script:scons EnvironmentVariable# TheversionofGoajobisusingisavailableas: TRAVIS_GO_VERSION Thismaycontain.xattheend,asdescribedabove. Useofthisvariableinthedeploymentconditionshould takethispossibilityintoconsideration. Forexample: go: -1.7.x ⋮ deploy: ... on: condition:$TRAVIS_GO_VERSION=~^1\.7 BuildConfigReference# YoucanfindmoreinformationonthebuildconfigformatforGoinourTravisCIBuildConfigReference. Examples# GoAMQPclient mrb/hob



請為這篇文章評分?