Skip to content

Commit

Permalink
convert/gem: Update convert gem to reflect the state of ruby3.3
Browse files Browse the repository at this point in the history
Changes:
- Update default ruby to 3.3
- Remove keyring entries wolfictl lint rejects them
```
❯ wolfictl lint ruby3.2-diff-lcs.yaml
2024/11/19 09:51:17 INFO Package: ruby3.2-diff-lcs: [forbidden-repository-used]: forbidden repository https://packages.wolfi.dev/os is used (ERROR)
[forbidden-keyring-used]: forbidden keyring https://packages.wolfi.dev/os/wolfi-signing.rsa.pub is used (ERROR)
```
- Remove README it causes build to fial
- Remove patch people will notice when it fails and the sed in
  pipelines/ruby/build should account for it
- Truncate dscription becuase it breaks index generation
```
2024/11/19 10:01:40 ERRO failed to build package: unable to generate index: updating index: failed to parse package packages/aarch64/ruby3.2-diff-lcs-1.5.1-r0.apk: ini.ShadowLoad(): key-value delimiter not found: McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities
```
  • Loading branch information
Justin Vreeland committed Nov 19, 2024
1 parent 9b14cd2 commit be3875e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 51 deletions.
33 changes: 13 additions & 20 deletions pkg/convert/gem/gem.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

const (
DefaultRubyVersion = "3.2"
DefaultRubyVersion = "3.3"
DefaultBaseURIFormat = "https://rubygems.org/api/v1/gems/%s.json"
)

Expand Down Expand Up @@ -237,6 +237,7 @@ func (c *GemContext) generateManifest(ctx context.Context, g GemMeta) (manifest.
generated.Environment = c.generateEnvironment()
generated.Vars = c.generateVars(g)
generated.Pipeline = c.generatePipeline(ctx, g)
generated.VarTransforms = c.generateVarTransforms()

return generated, nil
}
Expand All @@ -249,7 +250,7 @@ func (c *GemContext) generatePackage(g GemMeta) config.Package {
pkg := config.Package{
Epoch: 0,
Name: fmt.Sprintf("ruby%s-%s", c.RubyVersion, g.Name),
Description: g.Info,
Description: strings.Split(g.Info, "\n")[0],
Version: g.Version,
Copyright: []config.Copyright{},
Dependencies: config.Dependencies{
Expand Down Expand Up @@ -279,20 +280,12 @@ func (c *GemContext) generateEnvironment() apkotypes.ImageConfiguration {
"busybox",
"ca-certificates-bundle",
"git",
fmt.Sprintf("ruby-%s", c.RubyVersion),
fmt.Sprintf("ruby-%s-dev", c.RubyVersion),
"ruby-${{rubyMM}}",
"ruby-${{rubyMM}}-dev",
},
},
}

if len(c.AdditionalRepositories) > 0 {
env.Contents.BuildRepositories = append(env.Contents.BuildRepositories, c.AdditionalRepositories...)
}

if len(c.AdditionalKeyrings) > 0 {
env.Contents.Keyring = append(env.Contents.Keyring, c.AdditionalKeyrings...)
}

return env
}

Expand Down Expand Up @@ -323,16 +316,10 @@ func (c *GemContext) generatePipeline(ctx context.Context, g GemMeta) []config.P
Uses: "fetch",
With: map[string]string{
"uri": strings.ReplaceAll(artifactURI, g.Version, "${{package.version}}"),
"README": fmt.Sprintf("CONFIRM WITH: curl -L %s | sha256sum", artifactURI),
"expected-sha256": artifactSHA,
},
}, {
Uses: "patch",
With: map[string]string{
"README": "This is only required if the gemspec is using a signing key",
"patches": "patches/${{package.name}}.patch",
},
}, {
},
{
Uses: "ruby/build",
With: map[string]string{
"gem": "${{vars.gem}}",
Expand Down Expand Up @@ -385,3 +372,9 @@ func (c *GemContext) generateVars(g GemMeta) map[string]string {
"gem": g.Name,
}
}

// generateTransforms handles mapping package name to a ruby version
func (c *GemContext) generateVarTransforms() []config.VarTransforms {
return []config.VarTransforms{{From: "${{package.name}}", Match: "^ruby(\\d.\\d+)-.", Replace: "$1", To: "rubyMM"}}

}
41 changes: 10 additions & 31 deletions pkg/convert/gem/gem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ func TestGenerateManifest(t *testing.T) {

gemctx.RubyVersion = DefaultRubyVersion

// Add additionalReposities and additionalKeyrings
gemctx.AdditionalRepositories = []string{"https://packages.wolfi.dev/os"}
gemctx.AdditionalKeyrings = []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub"}

// Read the gem meta into
data, err := os.ReadFile(filepath.Join(gemMetaDir, "async.json"))
assert.NoError(t, err)
Expand All @@ -171,53 +167,43 @@ func TestGenerateManifest(t *testing.T) {
assert.Equal(t, "MIT", got.Package.Copyright[0].License)

// Check Environment
assert.Equal(t, []string{"https://packages.wolfi.dev/os"}, got.Environment.Contents.BuildRepositories)
assert.Equal(t, []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub"}, got.Environment.Contents.Keyring)
assert.Equal(t, []string{
"build-base",
"busybox",
"ca-certificates-bundle",
"git",
fmt.Sprintf("ruby-%s", DefaultRubyVersion),
fmt.Sprintf("ruby-%s-dev", DefaultRubyVersion),
"ruby-${{rubyMM}}",
"ruby-${{rubyMM}}-dev",
}, got.Environment.Contents.Packages)

// Check Pipeline
assert.Equal(t, 5, len(got.Pipeline))
assert.Equal(t, 4, len(got.Pipeline))

// Check Pipeline - fetch
assert.Equal(t, "fetch", got.Pipeline[0].Uses)
// NOTE: The sha256 here is the sha256 of the v2.3.1.tar.gz in the testdata/archive
// directory, which is just a tarball of the async.json, not the
// actual artifact. It's simply used for testing.
assert.Equal(t, map[string]string{
"README": fmt.Sprintf("CONFIRM WITH: curl -L %s/archive/refs/tags/v2.3.1.tar.gz | sha256sum", server.URL),
"expected-sha256": "2481a44fc272b64a4a1775edf57c52b5367c8a07afd7996901d3c57c77542e6c",
"uri": fmt.Sprintf("%s/archive/refs/tags/v${{package.version}}.tar.gz", server.URL),
}, got.Pipeline[0].With)

// Check Pipeline - patch
assert.Equal(t, "patch", got.Pipeline[1].Uses)
assert.Equal(t, map[string]string{
"README": "This is only required if the gemspec is using a signing key",
"patches": "patches/${{package.name}}.patch",
}, got.Pipeline[1].With)

// Check Pipeline - ruby/build
assert.Equal(t, "ruby/build", got.Pipeline[2].Uses)
assert.Equal(t, "ruby/build", got.Pipeline[1].Uses)
assert.Equal(t, map[string]string{
"gem": "${{vars.gem}}",
}, got.Pipeline[2].With)
}, got.Pipeline[1].With)

// Check Pipeline - ruby/install
assert.Equal(t, "ruby/install", got.Pipeline[3].Uses)
assert.Equal(t, "ruby/install", got.Pipeline[2].Uses)
assert.Equal(t, map[string]string{
"gem": "${{vars.gem}}",
"version": "${{package.version}}",
}, got.Pipeline[3].With)
}, got.Pipeline[2].With)

// Check Pipeline - ruby/clean
assert.Equal(t, "ruby/clean", got.Pipeline[4].Uses)
assert.Equal(t, "ruby/clean", got.Pipeline[3].Uses)
}

// TestGeneratePackage tests when a gem has multiple licenses
Expand Down Expand Up @@ -252,29 +238,22 @@ func TestGeneratePackage(t *testing.T) {
assert.Equal(t, expected, got)
}

// TestGenerateEnvironment tests when there are additional keyring and
// repository entries
func TestGenerateEnvironment(t *testing.T) {
expected := apkotypes.ImageConfiguration{
Contents: apkotypes.ImageContents{
BuildRepositories: []string{"https://packages.wolfi.dev/os", "local /github/workspace/packages"},
Keyring: []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub", "melange.rsa.pub"},
Packages: []string{
"build-base",
"busybox",
"ca-certificates-bundle",
"git",
fmt.Sprintf("ruby-%s", DefaultRubyVersion),
fmt.Sprintf("ruby-%s-dev", DefaultRubyVersion),
fmt.Sprintf("ruby-${{rubyMM}}"),

Check failure on line 249 in pkg/convert/gem/gem_test.go

View workflow job for this annotation

GitHub Actions / lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
fmt.Sprintf("ruby-${{rubyMM}}-dev"),

Check failure on line 250 in pkg/convert/gem/gem_test.go

View workflow job for this annotation

GitHub Actions / lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
},
},
}

gemctx := testGemContext("unused")

// Add additionalReposities and additionalKeyrings
gemctx.AdditionalRepositories = []string{"https://packages.wolfi.dev/os", "local /github/workspace/packages"}
gemctx.AdditionalKeyrings = []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub", "melange.rsa.pub"}
gemctx.RubyVersion = DefaultRubyVersion

got := gemctx.generateEnvironment()
Expand Down

0 comments on commit be3875e

Please sign in to comment.