My contributions to goreleaser
Photo by goreleaser
contribution

My contributions to goreleaser

The highlight of my contribution GitLab support and a private homebrew tap.

  • Date: 29 Nov, 2019
  • Client: Open Source
  • Role: Contributor

Reason

Back then, I needed the functionality from goreleaser to release Golang binaries to GitLab. However, this feature did not exist yet so I decided to build it.!

pr-snapshot

You find the full contribution here: https://github.com/goreleaser/goreleaser/pull/1038

Furthermore, as part of the DevOps automation I wanted to have a private homebrew tap, for the engineers to be able to download the tools of the platform team from a central location.

Creating the homebrew tap

GoReleaser created the formula from the following snippet:

# This file was generated by GoReleaser. DO NOT EDIT.
require_relative "./PrivateRepositoryDownloadStrategy"
class MyTool < Formula
  desc "mytool desc"
  homepage "https://gitab.mycompany/group/tool"
  version "0.0.1"
  bottle :unneeded

  if OS.mac?
    url "https://gitab.mycompany/group/tool/uploads/d046fcf878e88dd02312f15da23c5e00/mytool_Darwin_x86_64.tar.gz", :using => PrivateRepositoryDownloadStrategy
    sha256 "8f3957fdf78fde15d900229b29cae81c490eb585ff220acd7f0d71b4244f8d02"
  elsif OS.linux?
    if Hardware::CPU.intel?
      url "https://gitab.mycompany/group/tool/uploads/6082ce9fead78d6029c9ac091d4dacda/mytool_Linux_x86_64.tar.gz", :using => PrivateRepositoryDownloadStrategy
      sha256 "d9713c89f565f2981ef7bc7a63d87ab7f7d84a00c7b3ffbc585ff959097f3d64"
    end
  end

  def install
    bin.install "mytool"
  end

  test do
    system "#{bin}/mytool --help"
  end
end

The necessary manual tweak which needed to be made to the https://gitab.mycompany/homebrew-tap git repository, was to add a custom formula as follows:

require "download_strategy"

class PrivateRepositoryDownloadStrategy < CurlDownloadStrategy
  def initialize(url, name, version, **meta)
    super
    set_gitlab_session_token
  end

  private

  def _curl_args
    args = ["-b", "_gitlab_session=#{@gitlab_session_token}"]
    args
  end

  def set_gitlab_session_token
    @gitlab_session_token = ENV["HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN"]
    unless @gitlab_session_token
      raise CurlDownloadStrategyError, "Environment variable HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN is required."
    end
  end
end

To use it you need to export HOMEBREW_GITLAB_SESSION_ACCESS_TOKEN from your current session to GitLab from the browser. Yes, I know this is cumbersome, and not optimal. But it was a start.

You can find the detail in the stackoverflow post I opened back then

Cheers