Skip to content

feat: split build.tmpl.yml into pure Go and CGo variants#26

Open
alnr wants to merge 3 commits into
masterfrom
alnr/cgo-optional
Open

feat: split build.tmpl.yml into pure Go and CGo variants#26
alnr wants to merge 3 commits into
masterfrom
alnr/cgo-optional

Conversation

@alnr

@alnr alnr commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What

Splits the monolithic build.tmpl.yml (600 lines) into two composable templates, keeping the original filename as a backward-compatible aggregator:

  • build-base.tmpl.yml — shared infrastructure (variables, cosign signing, checksum, release, changelog) plus the CGO_ENABLED=0 builds (default, static-nosqlite), their archives, the distroless Docker images, and the *-distroless manifests. Needs no C toolchain.
  • build-cgo.tmpl.yml — the seven CGO builds (macOS, glibc/musl Linux amd64/arm64/arm, Windows mingw), their archives, universal_binaries, Homebrew, Scoop, the Alpine Docker images, and the :tag/:major/:minor/:patch/:latest manifests.
  • build.tmpl.yml — now a thin aggregator that pulls in both via nested from_url includes. Existing consumers need no changes.

Why

Projects without SQLite/HSM (e.g. ory/cli) can now include only build-base.tmpl.yml and drop the entire CGO build matrix — no cross-compilers, much faster releases — while still publishing distroless images and manifests.

Verification

  • The two new files merged together are content-identical to the old monolith (verified by parsing and diffing the YAML; only list-item ordering within builds/archives/docker_manifests differs, which does not affect produced artifacts).
  • test/.goreleaser.yml now includes both files, so the existing CI docker test validates the full-matrix merge path (a list overwrite instead of append would fail the run via the dangling static-nosqlite build id reference).
  • New test/no-cgo/ mini-project exercises the base-only path end to end; wired into the CI workflow as a second step.

Notes for reviewers

  • includes requires GoReleaser Pro, which the image already ships (2.12.5). Docs state files are "included recursively", which the aggregator relies on.
  • The aggregator's nested from_url chain cannot be tested pre-merge (its URLs point at master, where the new files don't exist yet), making the switchover atomic at merge time. Recommend a manual goreleaser check/snapshot against the real URL chain after merge, before cutting a downstream release.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added reusable GoReleaser build templates to generate no-CGO and CGO releases, including SBOMs, signatures, package manager artifacts, and multi-arch Docker images (distroless + Alpine) with release manifests.
    • Introduced a no-CGO release test fixture with its own Go module, sample program, and Docker environments.
    • Updated the main build template to assemble configuration from the shared no-CGO and CGO templates.
  • Documentation
    • Reworked template documentation to explain the new split between shared no-CGO/common and CGO add-ons, plus “no-CGO only” usage.
  • Tests
    • Added an extra Docker-based workflow step to validate the no-CGO build path.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The release configuration is split into base and CGO-specific GoReleaser templates. The legacy aggregator and test configurations are updated, README guidance is expanded, and a no-CGO fixture with Docker-based validation is added.

Changes

GoReleaser template split

Layer / File(s) Summary
Base release and distroless template
build-base.tmpl.yml
Defines no-CGO builds, signing, SBOM generation, archives, release metadata, Homebrew configuration, distroless Docker images, Alpine images, and multi-architecture manifests.
CGO packaging template
build-cgo.tmpl.yml
Adds CGO builds across macOS, Linux, Alpine, and Windows, plus archives, Homebrew, Scoop, Alpine Docker images, and Docker manifests.
Template aggregation and project configuration
build.tmpl.yml, test/.goreleaser.yml, README.md
Replaces the inlined aggregator with base and CGO includes, updates test includes, and documents template selection and no-CGO usage.
No-CGO fixture and Docker validation
test/no-cgo/*, .github/workflows/docker-test.yml
Adds a no-CGO Go module, build metadata variables, GoReleaser configuration, Dockerfiles, and a workflow step that builds and runs the snapshot container.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: splitting the build template into base and CGO variants.
Description check ✅ Passed The description covers what changed, why, verification, and reviewer notes, but it omits an explicit related issue or design document reference.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch alnr/cgo-optional

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
build-base.tmpl.yml (1)

45-46: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove redundant -tags=json1 for a no-CGO build.

The static-nosqlite build correctly disables CGO (CGO_ENABLED=0), meaning the SQLite driver will not be compiled. Passing json1 as a build tag is redundant and can be confusing in a template dedicated to non-SQLite builds.

♻️ Proposed refactor
   - id: static-nosqlite
-    flags:
-      - "-tags=json1"
     ldflags:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build-base.tmpl.yml` around lines 45 - 46, Remove the redundant "-tags=json1"
entry from the flags configuration in build-base.tmpl.yml, leaving the no-CGO
static-nosqlite build without the SQLite-specific build tag.
test/no-cgo/.goreleaser.yml (1)

1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add version: 2 to the configuration.

GoReleaser v2 configurations should explicitly declare their version. Since the included build-base.tmpl.yml is a v2 template, declaring version: 2 at the root ensures consistent parsing and compatibility.

♻️ Proposed refactor
+version: 2
+
 includes:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/no-cgo/.goreleaser.yml` at line 1, Add the GoReleaser configuration
version declaration at the root of the no-CGO configuration, alongside the
existing includes entry, setting it to version 2 so it matches the included
build-base.tmpl.yml template.
test/no-cgo/.docker/Dockerfile-goreleaser (1)

5-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove redundant file path in ADD instruction.

The source path test/no-cgo/go.mod is specified twice. Providing identical source arguments to ADD is redundant and can be simplified.

♻️ Proposed refactor
-ADD test/no-cgo/go.mod test/no-cgo/go.mod ./
+ADD test/no-cgo/go.mod ./
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/no-cgo/.docker/Dockerfile-goreleaser` at line 5, Update the Dockerfile’s
ADD instruction to include test/no-cgo/go.mod only once as the source, while
preserving ./ as the destination.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build-base.tmpl.yml`:
- Line 88: Update the SBOM output filename in the CycloneDX command to remove
the `_sqlite_` segment, matching the filename expected by the subsequent hook
while preserving the existing project, version, target, and `.bom.json`
components.

---

Nitpick comments:
In `@build-base.tmpl.yml`:
- Around line 45-46: Remove the redundant "-tags=json1" entry from the flags
configuration in build-base.tmpl.yml, leaving the no-CGO static-nosqlite build
without the SQLite-specific build tag.

In `@test/no-cgo/.docker/Dockerfile-goreleaser`:
- Line 5: Update the Dockerfile’s ADD instruction to include test/no-cgo/go.mod
only once as the source, while preserving ./ as the destination.

In `@test/no-cgo/.goreleaser.yml`:
- Line 1: Add the GoReleaser configuration version declaration at the root of
the no-CGO configuration, alongside the existing includes entry, setting it to
version 2 so it matches the included build-base.tmpl.yml template.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ce470eea-fb77-438a-be2f-b333296a3c00

📥 Commits

Reviewing files that changed from the base of the PR and between 7191425 and 6ffcb8f.

📒 Files selected for processing (11)
  • .github/workflows/docker-test.yml
  • README.md
  • build-base.tmpl.yml
  • build-cgo.tmpl.yml
  • build.tmpl.yml
  • test/.goreleaser.yml
  • test/no-cgo/.docker/Dockerfile-distroless-static
  • test/no-cgo/.docker/Dockerfile-goreleaser
  • test/no-cgo/.goreleaser.yml
  • test/no-cgo/go.mod
  • test/no-cgo/main.go

Comment thread build-base.tmpl.yml
alnr and others added 2 commits July 14, 2026 12:13
The base template's before hook runs 'git checkout -- go.sum go.mod',
which requires a tracked go.sum even for a dependency-free module.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
build-base.tmpl.yml now ships no-CGO variants of the Homebrew formula,
the Alpine Docker images, and the main :tag/:major/:minor/:patch/:latest
manifests, built from the pure-Go 'default' binaries. They are gated on
the internal 'cgo' variable: build-cgo.tmpl.yml sets it to true, which
disables the base variants (via templated skip_upload/skip_build/skip_push)
so the CGO-built ones are published instead. Including both templates
therefore behaves exactly as before.

Verified against goreleaser-pro 2.15.2 and 2.12.5 (the CI image version):
include variables merge with later-include-wins precedence, list sections
append, templated skip fields are honored, and duplicate image tags are
fine when one entry's build is skipped. The Homebrew upload is also
skipped when brew_name is unset.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
build-base.tmpl.yml (1)

183-270: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Dedup repeated OCI label blocks and image-template lists with YAML anchors.

The four alpine-nocgo-* dockers entries each repeat the identical 8-line build_flag_templates label block (Lines 196-203, 217-224, 239-246, 261-268), and the image_templates list ({{ .Tag }}-amd64/-arm64/-armv7/-armv6) is duplicated across tag-nocgo, major-nocgo, minor-nocgo, patch-nocgo, latest-nocgo. Since none of these blocks vary per entry, a YAML anchor/alias avoids the duplication without touching GoReleaser's schema (the alias just inlines the same list, so strict-unmarshal validation is unaffected).

♻️ Example anchor-based dedup
   - id: alpine-nocgo-amd64
     ...
-    build_flag_templates:
+    build_flag_templates: &oci_labels
       - "--label=org.opencontainers.image.title={{ .ProjectName }}"
       - "--label=org.opencontainers.image.vendor=Ory"
       - "--label=org.opencontainers.image.version={{ .Version }}"
       - "--label=org.opencontainers.image.created={{ .Date }}"
       - "--label=org.opencontainers.image.source={{ .GitURL }}"
       - "--label=org.opencontainers.image.revision={{ .FullCommit }}"
       - "--label=org.opencontainers.image.url=https://www.ory.sh"
       - "--label=org.opencontainers.image.documentation=https://www.ory.sh/docs"
       - "--platform=linux/amd64"
   - id: alpine-nocgo-arm64
     ...
-    build_flag_templates:
-      - "--label=org.opencontainers.image.title={{ .ProjectName }}"
-      - "--label=org.opencontainers.image.vendor=Ory"
-      - "--label=org.opencontainers.image.version={{ .Version }}"
-      - "--label=org.opencontainers.image.created={{ .Date }}"
-      - "--label=org.opencontainers.image.source={{ .GitURL }}"
-      - "--label=org.opencontainers.image.revision={{ .FullCommit }}"
-      - "--label=org.opencontainers.image.url=https://www.ory.sh"
-      - "--label=org.opencontainers.image.documentation=https://www.ory.sh/docs"
-      - "--platform=linux/arm64/v8"
+    build_flag_templates:
+      - *oci_labels
+      - "--platform=linux/arm64/v8"

(similarly for the armv7/armv6 entries, and for the repeated image_templates list in docker_manifests)

Since GoReleaser's config parser is external, please confirm anchors/aliases parse cleanly with the pinned goreleaser version before adopting.

Also applies to: 271-318

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build-base.tmpl.yml` around lines 183 - 270, Deduplicate the repeated OCI
label blocks in the four alpine-nocgo entries and the shared image_templates
list across the nocgo docker_manifests using YAML anchors and aliases. Define
each anchor once and reference it from the relevant build_flag_templates or
image_templates fields without changing GoReleaser’s schema or per-architecture
values; validate that the pinned GoReleaser version parses the anchored
configuration successfully.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/no-cgo/.docker/Dockerfile-alpine`:
- Line 1: Update the base image in the Dockerfile’s FROM directive from obsolete
Alpine 3.12 to a supported release, using Alpine 3.21 or newer.

---

Nitpick comments:
In `@build-base.tmpl.yml`:
- Around line 183-270: Deduplicate the repeated OCI label blocks in the four
alpine-nocgo entries and the shared image_templates list across the nocgo
docker_manifests using YAML anchors and aliases. Define each anchor once and
reference it from the relevant build_flag_templates or image_templates fields
without changing GoReleaser’s schema or per-architecture values; validate that
the pinned GoReleaser version parses the anchored configuration successfully.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a872b8af-943d-421b-826e-e6fc6201c41c

📥 Commits

Reviewing files that changed from the base of the PR and between 6ffcb8f and 763095a.

⛔ Files ignored due to path filters (1)
  • test/no-cgo/go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • README.md
  • build-base.tmpl.yml
  • build-cgo.tmpl.yml
  • test/no-cgo/.docker/Dockerfile-alpine
  • test/no-cgo/.docker/Dockerfile-goreleaser
  • test/no-cgo/.goreleaser.yml
🚧 Files skipped from review as they are similar to previous changes (3)
  • test/no-cgo/.goreleaser.yml
  • README.md
  • build-cgo.tmpl.yml

@@ -0,0 +1,5 @@
FROM alpine:3.12

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

alpine:3.12 is obsolete. Bump this fixture to a supported Alpine release such as 3.21+.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/no-cgo/.docker/Dockerfile-alpine` at line 1, Update the base image in
the Dockerfile’s FROM directive from obsolete Alpine 3.12 to a supported
release, using Alpine 3.21 or newer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant