Stop Struggling with GoReleaser — Master Automation in Minutes!

Stop Struggling with GoReleaser — Master Automation in Minutes!Streamlining Go Microservices: Simplify Builds and Boost Efficiency Across Your Multiple ServicesThis is my first experience writing about Golang as a programming language. In my project, I…


This content originally appeared on Level Up Coding - Medium and was authored by M Sadewa Wicaksana

Stop Struggling with GoReleaser — Master Automation in Minutes!

Streamlining Go Microservices: Simplify Builds and Boost Efficiency Across Your Multiple Services

This is my first experience writing about Golang as a programming language. In my project, I’m working with four separate repositories, each representing a distinct service — dashboard-services, logger-services, project-services, and auth-services.

Each service operates on a different port but will eventually be integrated into a single domain. Some services, like logger-services, need to run concurrently with others since it manages logging processes directly in the database. Similarly, the auth-services must also run in parallel as it handles authentication, which is a critical first step before any transaction can proceed.

Now, picture this scenario — every time there’s a minor code change, you need to ask the repository maintainer to build binary files manually. Not just once, but multiple times — maybe twice, three times, or even more. This approach quickly becomes inefficient, time-consuming, and difficult to scale.

In this post, I’ll walk you through how to streamline this process by automating builds and deployments — saving time, reducing errors, and simplifying microservices management in Golang.

Go Releases Master Automation

To streamline the process, I discovered GoReleaser — an excellent tool for efficient multiplatform builds. By integrating it with GitHub Actions, I was able to set up a CI/CD workflow that automatically builds and releases applications whenever a branch is pushed.

Why This Matters

By the end of this article, you’ll see how tools like GoReleaser and GitHub Actions can transform a manual, time-consuming build process into a fast, automated pipeline — perfect for scaling microservices in Go.

  1. Github Actions on Self-Hosted VPS
  2. GoReleaser
  3. Setup Workflow Github Actions and GoReleaser

1. Github Actions on Self-Hosted VPS

GitHub Actions is a powerful automation tool built into GitHub that helps developers streamline their workflows. It allows you to automate tasks like building, testing, and deploying applications directly from your repositories. To set up GitHub Actions, you can either use Ubuntu runners provided by GitHub or set up your own self-hosted VPS. If you choose a self-hosted VPS, you’ll need to install runners on your repository by following these simple steps.

a. Navigate to runners configuration like on the image [1], choose new self-hosted runner.

[1] Github Runners

b. Based on the image [2], find the right architecture for your Self-Hosted VPS. Follow the steps one by one, until the process finish.

[2] Step by step installations

c. After call the command ./run.sh the systems runners will be online in our repostiory. But, when we close the command terminal the runners will be terminated. To ensure, the runner run on the background task install with the scriptsvc.sh.

#install the background task
./svc.sh install

#start the svc
./svc.sh start

# check status
./svc.sh status

For documentation references check on this link.

d. To create simple actions, in the menu actions choose golang and configure. Then, changes the runs-on: ubuntu-latest to runs-on: self-hosted, finally commit changes and push it.

[3] actions configuration

2. GoReleaser

GoReleaser

GoReleaser is an open-source tool designed to simplify the release process for Go (Golang) applications. It automates many tasks involved in building, packaging, and publishing Go projects, making the release process faster and more consistent. Releasing software can be repetitive and time-consuming. Manually compiling code, generating release notes, creating version tags, and uploading binaries can introduce human errors. GoReleaser automates these steps, allowing developers to focus on coding rather than managing releases.

To install GoReleaser in our repository, use the following command

go install github.com/goreleaser/goreleaser/v2@latest

Or, for full documentations you can references to this part.

3. Setup Workflow Github Actions and GoReleaser

A. Run GoReleaser manually from our computer

[4] Flow Process GoReleaser on our local computer

The explanation based on the image [4] you can follow on the following steps:

  1. Run this command to initialize and will automatically create the file .goreleaser.yaml
goreleaser init

Configure the build process for a Go binary targeting three platforms: macOS (Apple Silicon), Windows, and Linux (AMD64).

# .goreleaser.yaml
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 2

project_name: go-logger-releasers

before:
hooks:
- go mod tidy
- go mod download

builds:
- id: windows
goos:
- windows
goarch:
- amd64
main: ./cmd/app
ldflags:
- -s -w
binary: logger_service

- id: macos-arm64
goos:
- darwin
goarch:
- arm64 # Specifically for M-series chips
main: ./cmd/app
ldflags:
- -s -w
binary: logger_service

archives:
- format: zip
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
files:
- dist/windows_windows_amd64_v1/logger_service.exe
- dist/macos-arm64_darwin_arm64_v8.0/logger_service

checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt"

2. Execute this command to build the applications. The compiled binary files for each target platform will be generated and stored in the dist/ directory. This ensures organized output and easy access to the built binaries.

goreleaser release - snapshot - clean
Example Output Binary Applications

3. The goreleaser check command plays a crucial role in ensuring a smooth release process. This command verifies that your current environment meets all the requirements for a successful build and release.

goreleaser check

4. To release your build to your GitHub repository, ensure you have a GitHub token configured. This token is required to setup the built application to the repository securely.

export GITHUB_TOKEN="YOUR_GH_TOKEN"

Create tag and push it into Github

git tag -a v0.1.0 -m "First release"
git push origin v0.1.0

Finally publish it into the repository

goreleaser release

B. Run GoReleaser with Github Actions

[5] Flow Automation Process

Image[5] illustrates the process flow for building multiplatform binary applications. The sequence begins when a push is made to the deployment-app branch, triggering GitHub Actions to initiate the build process. Using GoReleaser, the binary applications are built and, upon successful completion, released to the repository. The image[4] is the basic flow automation process to make you easy to understand. But for full instructions process that we will create will be visualize on the image[5].

image[6] Full scenario build application process

Based on the image[6], there are additional process to make our flow more comprehensive such as there are notifications by discord which that can be useful to make informations to our teams that the build apps will be start, still progress, and done. In the other hand, because our process is automatically we also need logic to handle semantic version tag. To handle all that process you can see in my workflow below, but for the configurations .goreleaser.yaml you can references on the point A.

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go Dashboard Services

on:
push:
branches: ["deployment-app"]

permissions:
contents: write # needed to write releases
id-token: write # needed for keyless signing
packages: write # needed for ghcr access

build:
runs-on: self-hosted
steps:
- name: send start notify
uses: appleboy/discord-action@master
with:
webhook_id: ${{ secrets.WEBHOOK_ID }}
webhook_token: ${{ secrets.WEBHOOK_TOKEN }}
color: "#bf2837"
username: "GitHub Bot"
message: "Starting to Deployment App LOGGER :)"

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "github-actions@github.com"

- name: Remove all tags
run: |
# Check if there are any tags
if git tag -l | grep -q .; then
# Remove local tags
git tag -l | xargs git tag -d
# Fetch and remove remote tags if they exist
git fetch --tags
if git tag -l | grep -q .; then
git tag -l | xargs -n 1 git push --delete origin
fi
else
echo "No tags found to delete"
fi
env:
GITHUB_TOKEN: ${{ secrets.GTH_TOKEN }}

- name: Create semantic version tag
run: |
# Get latest tag or start with v0.0.1
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.1")

# Extract version components
MAJOR=$(echo $LATEST_TAG | sed 's/v//' | cut -d. -f1)
MINOR=$(echo $LATEST_TAG | sed 's/v//' | cut -d. -f2)
PATCH=$(echo $LATEST_TAG | sed 's/v//' | cut -d. -f3)

# Increment patch version
NEXT_VERSION="v${MAJOR}.${MINOR}.$((PATCH+1))"

git tag $NEXT_VERSION
git push origin $NEXT_VERSION
echo "RELEASE_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GTH_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Set Go environment
run: |
# mkdir -p /root/go
echo "HOME=/root" >> $GITHUB_ENV
echo "XDG_CACHE_HOME=/root/.cache" >> $GITHUB_ENV
echo "GOCACHE=/root/.cache/go-build" >> $GITHUB_ENV
echo "GOPATH=/root/go" >> $GITHUB_ENV
echo "GOMODCACHE=/root/go/pkg/mod" >> $GITHUB_ENV
echo "PATH=/root/go/bin:$PATH" >> $GITHUB_ENV

- name: Go mod tidy
run: go mod tidy
env:
HOME: /root
XDG_CACHE_HOME: /root/.cache
GOCACHE: /root/.cache/go-build
GOPATH: /root/go
GOMODCACHE: /root/go/pkg/mod
PATH: /root/go/bin:$PATH

- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GTH_TOKEN }}
HOME: /root
XDG_CACHE_HOME: /root/.cache
GOCACHE: /root/.cache/go-build

- name: send finish notify
uses: appleboy/discord-action@master
with:
webhook_id: ${{ secrets.WEBHOOK_ID }}
webhook_token: ${{ secrets.WEBHOOK_TOKEN }}
color: "#1c9174"
username: "GitHub Bot"
message: "Finished Deployment App LOGGER Tag $RELEASE_VERSION :)"

Thank you for taking the time to read my article. If you have any questions, need further clarification, or wish to discuss technology-related topics, feel free to reach out to me via email. I’m always open to sharing insights, collaborating on projects, or offering guidance on your tech journey. Let’s connect and build something amazing together! wicaksanasadewa@proton.me

Let’s Explore IT! 😁😁


Stop Struggling with GoReleaser — Master Automation in Minutes! was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by M Sadewa Wicaksana


Print Share Comment Cite Upload Translate Updates
APA

M Sadewa Wicaksana | Sciencx (2024-12-31T20:41:11+00:00) Stop Struggling with GoReleaser — Master Automation in Minutes!. Retrieved from https://www.scien.cx/2024/12/31/stop-struggling-with-goreleaser-master-automation-in-minutes/

MLA
" » Stop Struggling with GoReleaser — Master Automation in Minutes!." M Sadewa Wicaksana | Sciencx - Tuesday December 31, 2024, https://www.scien.cx/2024/12/31/stop-struggling-with-goreleaser-master-automation-in-minutes/
HARVARD
M Sadewa Wicaksana | Sciencx Tuesday December 31, 2024 » Stop Struggling with GoReleaser — Master Automation in Minutes!., viewed ,<https://www.scien.cx/2024/12/31/stop-struggling-with-goreleaser-master-automation-in-minutes/>
VANCOUVER
M Sadewa Wicaksana | Sciencx - » Stop Struggling with GoReleaser — Master Automation in Minutes!. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/12/31/stop-struggling-with-goreleaser-master-automation-in-minutes/
CHICAGO
" » Stop Struggling with GoReleaser — Master Automation in Minutes!." M Sadewa Wicaksana | Sciencx - Accessed . https://www.scien.cx/2024/12/31/stop-struggling-with-goreleaser-master-automation-in-minutes/
IEEE
" » Stop Struggling with GoReleaser — Master Automation in Minutes!." M Sadewa Wicaksana | Sciencx [Online]. Available: https://www.scien.cx/2024/12/31/stop-struggling-with-goreleaser-master-automation-in-minutes/. [Accessed: ]
rf:citation
» Stop Struggling with GoReleaser — Master Automation in Minutes! | M Sadewa Wicaksana | Sciencx | https://www.scien.cx/2024/12/31/stop-struggling-with-goreleaser-master-automation-in-minutes/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.