Forgejo Actions and version numbers
Let me be on the record that I hate working on a CI pipeline. It brings me back to a time when we made a single line change and waited ten minutes for C++ templates to compile. I really did not enjoy that. This will serve as documentation so I never have to figure this out again. I have a Go app for which I want to build a Docker image for the app. The build is dispatched manually via the web ui of Forgejo. I want to specify the version number of the build when dispatching the job. Let us get into it.
First we need a variable somewhere in our Go app to inject the version number as build time flag.
// cmd/app/main.go
var Version string
Next we update the Docker file to accept an argument and add the flag to our Go build command.
ARG APP_VERSION
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.Version=${APP_VERSION}'" -o /app cmd/app/main.go
Last but not least: Time to update Forgejos workflow. I am using buildx
and build-push-action
to build the Docker image. Here are the relevant parts. We update the workflow_dispatch
section to accept an input.
on:
workflow_dispatch:
inputs:
version:
description: "Version"
required: true
type: string
now with the variable version
holding our input, we can add it as a build argument to the build-push-action
.
- name: Build and Push
uses: https://github.com/docker/build-push-action@v4
with:
pull: true
push: true
tags: ${{ github.repository }}:${{ inputs.version }}
platforms: linux/amd64
file: Dockerfile
context: .
build-args: |
APP_VERSION=${{ inputs.version }}
Nicely tagged Docker images and the app, once compiled, also knows which version it is supposed to be. Great success.
posted on Oct. 2, 2025, 5:16 p.m. in golang, infrastructure, software engineering
This entry was posted as a "note" and did not undergo the same editing and review as regular posts.