Skip to content

Commit

Permalink
convert/gem/ruby: Don't overwrite existing melange files
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Vreeland committed Dec 11, 2024
1 parent b5d4d74 commit 7b5e82b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/build/pipelines/cargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Compile an auditable rust binary with Cargo
| modroot | false | Top directory of the rust package, this is where the target package lives. Before building, the cargo pipeline wil cd into this directory. Defaults to current working directory | . |
| opts | false | Options to pass to cargo build. Defaults to release | --release |
| output | false | Filename to use when writing the binary. The final install location inside the apk will be in prefix / install-dir / output | |
| output-dir | false | Directory where the binaris will be placed after building. Defaults to target/release | target/release |
| prefix | false | Installation prefix. Defaults to usr | usr |


Expand Down
17 changes: 10 additions & 7 deletions pkg/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
"properties": {
"description": {
"type": "string",
"description": "Optional: The human readable description of the input"
"description": "Optional: The human-readable description of the input"
},
"default": {
"type": "string",
Expand Down Expand Up @@ -499,7 +499,7 @@
},
"description": {
"type": "string",
"description": "A human readable description of the package"
"description": "A human-readable description of the package"
},
"url": {
"type": "string",
Expand Down Expand Up @@ -608,6 +608,10 @@
},
"Pipeline": {
"properties": {
"if": {
"type": "string",
"description": "Optional: A condition to evaluate before running the pipeline"
},
"name": {
"type": "string",
"description": "Optional: A user defined name for the pipeline"
Expand All @@ -632,7 +636,7 @@
"$ref": "#/$defs/Pipeline"
},
"type": "array",
"description": "Optional: The list of pipelines to run.\n\nEach pipeline runs in it's own context that is not shared between other\npipelines. To share context between pipelines, nest a pipeline within an\nexisting pipeline. This can be useful when you wish to share common\nconfiguration, such as an alternative `working-directory`."
"description": "Optional: The list of pipelines to run.\n\nEach pipeline runs in its own context that is not shared between other\npipelines. To share context between pipelines, nest a pipeline within an\nexisting pipeline. This can be useful when you wish to share common\nconfiguration, such as an alternative `working-directory`."
},
"inputs": {
"additionalProperties": {
Expand All @@ -649,10 +653,6 @@
"type": "string",
"description": "Optional: Labels to apply to the pipeline"
},
"if": {
"type": "string",
"description": "Optional: A condition to evaluate before running the pipeline"
},
"assertions": {
"$ref": "#/$defs/PipelineAssertions",
"description": "Optional: Assertions to evaluate whether the pipeline was successful"
Expand Down Expand Up @@ -733,6 +733,9 @@
"cpu": {
"type": "string"
},
"cpumodel": {
"type": "string"
},
"memory": {
"type": "string"
},
Expand Down
10 changes: 9 additions & 1 deletion pkg/convert/gem/gem.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -169,7 +171,13 @@ func (c *GemContext) findDependencies(ctx context.Context) error {
return err
}
log.Infof("[%s] Add to generate list", c.ToCheck[0])
c.ToGenerate[c.ToCheck[0]] = g
// This should be ruby3 once the files are multi-versioned
_, err = os.Stat(filepath.Join(c.OutDir, "ruby"+DefaultRubyVersion+"-"+g.Name+".yaml"))
if err == nil {
log.Infof("[%s] Package already exists, skipping", g.Name)
} else {
c.ToGenerate[c.ToCheck[0]] = g
}
c.ToCheck = c.ToCheck[1:]

log.Infof("[%s] Check for dependencies", g.Name)
Expand Down
12 changes: 11 additions & 1 deletion pkg/convert/gem/gem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,28 @@ func TestFindDependencies(t *testing.T) {
gemctx := testGemContext(server.URL + "/%s.json")
gemctx.ToCheck = []string{"async"}

// Verify that if the file exists the dependecy isn't created
_, _ = os.OpenFile("ruby"+DefaultRubyVersion+"-timers.yaml", os.O_RDONLY|os.O_CREATE, 0666)

// Build list of dependencies
err = gemctx.findDependencies(slogtest.Context(t))
assert.NoError(t, err)

for _, gem := range gems {
gemName := strings.TrimSuffix(gem.Name(), ".json")
_, ok := gemctx.ToGenerate[gemName]
assert.True(t, ok)

if gemName == "timers" {
assert.False(t, ok)
} else {
assert.True(t, ok)
}

// Remove dependency from the list
delete(gemctx.ToGenerate, gemName)
}
os.Remove("ruby" + DefaultRubyVersion + "-timers.yaml")

// The dependency list should be empty
assert.Empty(t, gemctx.ToGenerate)
}
Expand Down
Binary file modified pkg/sca/testdata/generated/x86_64/shbang-test-1-r1.apk
Binary file not shown.

0 comments on commit 7b5e82b

Please sign in to comment.