Skip to content

Commit

Permalink
fix(deb): changelog fixes (#597)
Browse files Browse the repository at this point in the history
* fix(deb): changelog fixes

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
Co-authored-by: Andrei Belov <defanator@users.noreply.github.com>

* fix: test

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
Co-authored-by: Andrei Belov <defanator@users.noreply.github.com>
  • Loading branch information
caarlos0 and defanator authored Dec 30, 2022
1 parent dedee6d commit f2e5d2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 55 deletions.
19 changes: 7 additions & 12 deletions deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@ func createChangelogInsideDataTar(tarw *tar.Writer, md5w io.Writer,
created map[string]bool, info *nfpm.Info,
) (int64, error) {
var buf bytes.Buffer
out := gzip.NewWriter(&buf)
out, err := gzip.NewWriterLevel(&buf, gzip.BestCompression)
if err != nil {
return 0, fmt.Errorf("could not create gzip writer: %w", err)
}
// the writers are properly closed later, this is just in case that we have
// an error in another part of the code.
defer out.Close() // nolint: errcheck
Expand All @@ -500,13 +503,14 @@ func createChangelogInsideDataTar(tarw *tar.Writer, md5w io.Writer,
}

if err = out.Close(); err != nil {
return 0, fmt.Errorf("closing changelog.gz: %w", err)
return 0, fmt.Errorf("closing changelog.Debian.gz: %w", err)
}

changelogData := buf.Bytes()

// https://www.debian.org/doc/manuals/developers-reference/pkgs.de.html#recording-changes-in-the-package
changelogName := normalizePath(fmt.Sprintf("/usr/share/doc/%s/changelog.gz", info.Name))
// https://lintian.debian.org/tags/debian-changelog-file-missing-or-wrong-name
changelogName := normalizePath(fmt.Sprintf("/usr/share/doc/%s/changelog.Debian.gz", info.Name))
if err = createTree(tarw, changelogName, created); err != nil {
return 0, err
}
Expand Down Expand Up @@ -570,15 +574,6 @@ func createControl(instSize int64, md5sums []byte, info *nfpm.Info) (controlTarG
"conffiles": conffiles(info),
}

if info.Changelog != "" {
changeLogData, err := formatChangelog(info)
if err != nil {
return nil, err
}

filesToCreate["changelog"] = []byte(changeLogData)
}

triggers := createTriggers(info)
if len(triggers) > 0 {
filesToCreate["triggers"] = triggers
Expand Down
39 changes: 1 addition & 38 deletions deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,43 +544,6 @@ func TestDEBConventionalFileName(t *testing.T) {
}
}

func TestDebChangelogControl(t *testing.T) {
info := &nfpm.Info{
Name: "changelog-test",
Arch: "amd64",
Description: "This package has changelogs.",
Version: "1.0.0",
Changelog: "../testdata/changelog.yaml",
}
err := info.Validate()
require.NoError(t, err)

controlTarGz, err := createControl(0, []byte{}, info)
require.NoError(t, err)

controlChangelog := extractFileFromTar(t, inflate(t, "gz", controlTarGz), "changelog")

goldenChangelog := readAndFormatAsDebChangelog(t, info.Changelog, info.Name)

require.Equal(t, goldenChangelog, string(controlChangelog))
}

func TestDebNoChangelogControlWithoutChangelogConfigured(t *testing.T) {
info := &nfpm.Info{
Name: "no-changelog-test",
Arch: "amd64",
Description: "This package has explicitly no changelog.",
Version: "1.0.0",
}
err := info.Validate()
require.NoError(t, err)

controlTarGz, err := createControl(0, []byte{}, info)
require.NoError(t, err)

require.False(t, tarContains(t, inflate(t, "gz", controlTarGz), "changelog"))
}

func TestDebChangelogData(t *testing.T) {
info := &nfpm.Info{
Name: "changelog-test",
Expand All @@ -595,7 +558,7 @@ func TestDebChangelogData(t *testing.T) {
dataTarball, _, _, dataTarballName, err := createDataTarball(info)
require.NoError(t, err)

changelogName := fmt.Sprintf("/usr/share/doc/%s/changelog.gz", info.Name)
changelogName := fmt.Sprintf("/usr/share/doc/%s/changelog.Debian.gz", info.Name)
dataChangelogGz := extractFileFromTar(t,
inflate(t, dataTarballName, dataTarball), changelogName)

Expand Down
16 changes: 11 additions & 5 deletions testdata/acceptance/deb.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ FROM test_base AS withchangelog
# image filters out changelogs by default
# so we have to remove that rule
RUN apt update -y
RUN apt install -y gzip
RUN apt install -y gzip lintian
RUN dpkg -i /tmp/foo.deb
RUN zcat "/usr/share/doc/foo/changelog.gz" | grep "Carlos A Becker <pkg@carlosbecker.com>"
RUN zcat "/usr/share/doc/foo/changelog.gz" | grep "note 1"
RUN zcat "/usr/share/doc/foo/changelog.gz" | grep "note 2"
RUN zcat "/usr/share/doc/foo/changelog.gz" | grep "note 3"
RUN zcat "/usr/share/doc/foo/changelog.Debian.gz" | grep "Carlos A Becker <pkg@carlosbecker.com>"
RUN zcat "/usr/share/doc/foo/changelog.Debian.gz" | grep "note 1"
RUN zcat "/usr/share/doc/foo/changelog.Debian.gz" | grep "note 2"
RUN zcat "/usr/share/doc/foo/changelog.Debian.gz" | grep "note 3"
RUN lintian /tmp/foo.deb > lintian.out
RUN test $(grep -c 'debian-changelog-file-missing-or-wrong-name' lintian.out) = 0
RUN test $(grep -c 'changelog-not-compressed-with-max-compression' lintian.out) = 0
RUN test $(grep -c 'unknown-control-file' lintian.out) = 0
# TODO: RUN test $(grep -c 'package-contains-timestamped-gzip' lintian.out) = 0
# TODO: RUN test $(grep -c 'syntax-error-in-debian-changelog' lintian.out) = 0

# ---- rules test ----
FROM min AS rules
Expand Down

0 comments on commit f2e5d2a

Please sign in to comment.