Skip to content

fix: Include optional dependencies in Arch packages - #1131

Merged
caarlos0 merged 4 commits into
goreleaser:mainfrom
fredrikblau:fix/1123-arch-optdepend
Oct 12, 2026
Merged

caarlos0 merged 4 commits into
goreleaser:mainfrom
fredrikblau:fix/1123-arch-optdepend

Conversation

@fredrikblau

Copy link
Copy Markdown
Contributor

What changed

Arch packages now include recommends and suggests entries as optdepend metadata in .PKGINFO.

Verification

  • go test ./...
  • go build ./cmd/nfpm
  • go vet ./...
  • git diff --check

Closes #1123

@pull-request-size pull-request-size Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 29, 2026
caarlos0
caarlos0 previously approved these changes Sep 9, 2026

@caarlos0 caarlos0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. The mapping of recommends + suggests to optdepend is correct for .PKGINFO, it follows the existing loop pattern in createPkginfo, and it adds no configuration surface. The two comments below are non-blocking.

Acceptance coverage (no single site in this diff)

testdata/acceptance/core.complex.yaml already sets recommends: fish and suggests: zsh, and the complex stage of testdata/acceptance/archlinux.dockerfile already greps pacman -Qi for Depends On, Replaces and Provides. Nothing there asserts the new field, so the unit test is the only proof. One more line in that stage makes pacman itself prove that it parses the new entry:

RUN pacman -Qi foo | grep "Optional Deps\\s*: fish"

I verified that no acceptance stage does strict output matching, so this change breaks no current stage.

Verification gaps

  • I did not build or run tests locally, as requested. exampleInfo() is shared by 12 tests in arch/arch_test.go, so go test ./arch/... is the check that matters.
  • I did not run the independent caarlos0 and anvil sub-agent checks. The diff is 7 lines and fits one direct read.

This review is from an automated (bot) reviewer.

Comment thread arch/arch.go Outdated
}
}

for _, optdepend := range append(info.Recommends, info.Suggests...) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit, non-blocking: append(info.Recommends, ...) writes into the caller's backing array when cap > len. This can occur, because expandEnvVarsStringSlice uses slices.Delete, which keeps the capacity after it removes an empty entry (recommends: [git, "${UNSET}"] gives len 1, cap 2).

I could not build a repro that a user can observe: all writes land past len, and no code in this repository reads past len of Recommends. So this is style, not a bug. slices.Concat removes the question:

for _, optdepend := range slices.Concat(info.Recommends, info.Suggests) {

No new test is necessary.

Comment thread arch/arch_test.go Outdated
Comment on lines +170 to +171
require.Contains(t, string(pkginfoData), "optdepend = git\n")
require.Contains(t, string(pkginfoData), "optdepend = fish\n")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These two assertions read the raw bytes, because extractPkginfoFields (line 248) puts each key in a map[string]string and thus keeps only the last value of a repeated key. Result: no test can find a dropped, duplicated, or wrongly repeated optdepend, and this is the first field in .PKGINFO that occurs more than one time in the example data.

A small helper keeps the assertion at the same layer as the others and makes the count part of the contract:

func extractPkginfoValues(data []byte, key string) []string {
	var out []string
	for _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {
		if k, v, ok := strings.Cut(line, " = "); ok && k == key {
			out = append(out, v)
		}
	}
	return out
}

Then:

require.ElementsMatch(t, []string{"git", "fish"}, extractPkginfoValues(pkginfoData, "optdepend"))

ElementsMatch prints both slices on failure and does not make the line order a contract.

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.82%. Comparing base (60154f1) to head (c4f1868).

Files with missing lines Patch % Lines
arch/arch.go 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1131      +/-   ##
==========================================
- Coverage   83.85%   83.82%   -0.03%     
==========================================
  Files          30       30              
  Lines        2787     2789       +2     
==========================================
+ Hits         2337     2338       +1     
- Misses        450      451       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

fredrikniche and others added 2 commits September 9, 2026 11:28
Serialize recommends and suggests as Arch optdepend metadata so optional dependencies are retained in generated packages.

See goreleaser#1123
@fredrikblau
fredrikblau force-pushed the fix/1123-arch-optdepend branch from 474ad78 to 1c37fbc Compare September 9, 2026 08:01
@fredrikblau

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

Added the acceptance assertion you suggested to the complex stage of testdata/acceptance/archlinux.dockerfile, right after the existing Provides check:

RUN pacman -Qi foo | grep "Optional Deps\\s*: fish"

core.complex.yaml sets recommends: fish and suggests: zsh, and optdepend entries are written recommends-first, so fish is the first line pacman prints under Optional Deps. I have no Docker available locally, so that stage is verified by CI rather than by me.

Also rebased on current main. The previous run's ruleguard / scan failure was internal error: package "maps" without types was imported from ...internal/maps, which is unrelated to this diff and no longer reproduces on main; the rebase should clear it.

go test ./arch/... passes on the rebased branch.

@fredrikblau

Copy link
Copy Markdown
Contributor Author

Applied both non-blocking suggestions in a040b70: slices.Concat for the optdepend loop, and an extractPkginfoValues helper with ElementsMatch so the test asserts the full list of optdepend values. go test ./arch/... passes. The workflows on this head will need approval again to run.

@caarlos0 caarlos0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No findings. Approving the reviewed head.

The complete merge-base-to-head diff received independent read-only caarlos0 maintainer and anvil adversarial checks; both reported no findings, independently checked against the code and Arch PKGINFO specification.

Verification gaps: No local builds, tests, or Docker acceptance runs were performed. git diff --check passed. Exact-head product workflows report action_required; only WIP reports success. Unit and Arch acceptance results remain unverified and should pass before merge.

This supersedes automated review 5149516868.

This review is from an automated (bot) reviewer.

@caarlos0
caarlos0 dismissed their stale review October 8, 2026 17:01

Superseded by automated full-diff review 5460189475 of a040b70; previous non-blocking suggestions are addressed.

Address the review nits: avoid writing into the Recommends backing array,
and assert the full list of optdepend values instead of substrings, since
extractPkginfoFields keeps only the last value of a repeated key.

Signed-off-by: amirahrari <[email protected]>
@fredrikblau
fredrikblau force-pushed the fix/1123-arch-optdepend branch from a040b70 to b1c3749 Compare October 10, 2026 16:21
@caarlos0
caarlos0 enabled auto-merge October 12, 2026 17:09
@caarlos0
caarlos0 disabled auto-merge October 12, 2026 17:09
@caarlos0
caarlos0 enabled auto-merge October 12, 2026 17:09
Co-authored-by: Copilot <[email protected]>
Copilot-Session: cb68ab4e-96d3-4658-a1c0-c2c33e8c52a0
Signed-off-by: Carlos Alexandro Becker <[email protected]>
@caarlos0
caarlos0 added this pull request to the merge queue Oct 12, 2026
Merged via the queue into goreleaser:main with commit c2b0995 Oct 12, 2026
19 of 21 checks passed
@github-actions github-actions Bot added this to the 2.38.0 milestone Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

archlinux: the optdepend info was not generated

3 participants