Publishing Go Modules To JFrog Artifactory Using The JFrog CLI

Publishing Go Modules with JFrog CLI

Over the coming weeks, we’ll release a series of blog posts on how you can use the JFrog CLI, Artifactory, and GitHub Actions to build awesome software.Last weekwe built a Go app using Artifactory, the CLI and GitHub Actions and this week we’ll continue that by publishing the Go app as a module.

Go modules are collections of related Go packages that are versioned together as a single unit. Those “units” make it possible to share the code between developers without asking them to download the code over and over. In this post, we’ll use a built an app and store the module in Artifactory using the JFrog CLI.

All the code and files I refer to are available onGitHub

The workflow

You can use the same app as for the previous blog post, so let’s go over the steps:

  • Publish the package to Artifactory
  • Collect and publish the build information

Step 1: Publish package

The first step is to publish the module to the Go repository in Artifactory. You can use any version you want (likev1.0.0) and use the--build-nameand--build-numberflags to record the uploaded module as an artifact as well.

action "Step1 - Publish package" { uses = "retgits/actions/jfrog-cli-go@master" secrets = ["URL", "USER", "PASSWORD"] args = ["go-publish go v1.0.0 --build-name=my-build --build-number=1"] env = { CRED = "username" } }

Step 2: Collect Build Info

As mentioned in the previous post,Build Integrationis one of the most awesome features of Artifactory and the JFrog CLI. You can collect and store that in Artifactory so you have an immutable log of what happened during the build step. The reason that you need to execute two commands (theargsare now an array) is that the GitHub Actions workflow only keeps the working folder and discards the rest from step to step. The JFrog CLI stores the build info it collects in a separate folder, so when moving to another step it would otherwise lose that.

Build Integration is one of the most awesome features of Artifactory and the JFrog CLI.Click To Tweet
action "Step2 - Collect Build Info" { uses = "retgits/actions/jfrog-cli-go@master" secrets = ["URL", "USER", "PASSWORD"] args = ["build-collect-env my-build 1","build-publish my-build 1"] env = { CRED = "username" } needs = ["Step1 - Publish package"] }

You can find the entire filehereand after you commit the changes GitHub will process the steps

Only two ✅, and everything still works!

Truth is in the eye of the beholder

Now that everything is completed successfully, you can look at the logs

Step 1: Publish package

### STARTED Step1 - Publish package 21:14:09Z ... snip ... Authentication using username [Info] Encrypting password... Running 'go-publish go v1.0.0 --build-name=my-build --build-number=1'... [Info] Using go: go version go1.11.4 linux/amd64 [Info] Publishing github.com/you/hello to go [Info] Running 'go mod graph' in /github/workspace go: finding rsc.io/quote v1.5.2 go: finding rsc.io/sampler v1.3.0 go: finding golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c { "status": "success", "totals": { "success": 1, "failure": 0 } } Successfully ran 'go-publish go v1.0.0 --build-name=my-build --build-number=1' ### COMPLETED Step1 - Publish package 21:16:20Z (2m11.222s)

Step 2: Collect Build Info

### STARTED Step2 - Collect Build Info 21:14:09Z ... snip ... Authentication using username [Info] Encrypting password... Running 'build-collect-env my-build 1'... [Info] Collecting environment variables... [Info] Collected environment variables for my-build/1. Successfully ran 'build-collect-env my-build 1' Running 'build-publish my-build 1'... [Info] Deploying build info... [Info] Build info successfully deployed. Browse it in Artifactory under https://xxx.xxx.xxx.xxx/artifactory/webapp/builds/my-build/1 Successfully ran 'build-publish my-build 1' ### COMPLETED Step2 - Collect Build Info 21:16:26Z (2m16.733s)

Artifactory

In Artifactory, you’ll now find the newly published module in the Artifact Repository Browser

In the Artifact Repository Browser…

我和所有构建信息s available too…

…in the build information section.

从那里你可以看到所有环境variables and other data that was recorded during the build!

What’s next

If you want to try out GitHub Actions, head over to theGitHub websiteand sign up for their beta program. For an environment to test drive all the features of JFrog Artifactory (and a lot more), you can sign up for a test drive on ourdemo environment. For questions or comments, feel free to leave a message here or onTwitter!