Skip to content

Commit

Permalink
Merge pull request #1786 from rnc/YAML
Browse files Browse the repository at this point in the history
Fix yaml output generation
  • Loading branch information
stuartwdouglas authored Jun 3, 2024
2 parents 143a1bc + df7d6f1 commit 850b81e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.redhat.hacbs.recipes;

import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR;
import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.MINIMIZE_QUOTES;
import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.SPLIT_LINES;

Expand All @@ -11,15 +12,22 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

public interface RecipeManager<T> {

ObjectMapper MAPPER = new ObjectMapper(
new YAMLFactory().disable(SPLIT_LINES).enable(MINIMIZE_QUOTES))
ObjectMapper MAPPER = JsonMapper.builder(new YAMLFactory()
.disable(SPLIT_LINES)
.disable(MINIMIZE_QUOTES)
.enable(INDENT_ARRAYS_WITH_INDICATOR))
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
.build().setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);

default T parse(Path file) throws IOException {
try (var in = Files.newInputStream(file)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,59 @@

import static org.junit.jupiter.api.Assertions.*;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class BuildRecipeInfoManagerTest {

@Test
void parse()
void parse(@TempDir Path tempDir)
throws IOException, URISyntaxException {
BuildRecipeInfoManager buildRecipeInfoManager = new BuildRecipeInfoManager();
var result = buildRecipeInfoManager.parse(Path.of(
Objects.requireNonNull(
BuildRecipeInfoManagerTest.class.getClassLoader().getResource("build.yaml")).toURI()));
assertNotNull(result);

assertEquals(1, result.additionalArgs.size());
assertEquals("-DskipDocs", result.additionalArgs.get(0));

File written = new File(tempDir.toFile(), "result.yaml");
BuildRecipeInfoManager.MAPPER.writeValue(written, result);
String generated = Files.readString(written.toPath());

assertEquals("---\n" +
"additionalArgs:\n" +
" - \"-DskipDocs\"\n" +
"additionalBuilds:\n" +
" pureJava:\n" +
" additionalArgs:\n" +
" - \"-Dlz4-pure-java=true\"\n" +
" preBuildScript: \"./autogen.sh\\n/bin/sh -c \\\"$(rpm --eval %configure); $(rpm --eval %__make) $(rpm --eval %_smp_mflags)\\\"\\n\"\n"
+
"additionalDownloads:\n" +
" - binaryPath: \"only_for_tar/bin\"\n" +
" fileName: \"yq\"\n" +
" sha256: \"30459aa144a26125a1b22c62760f9b3872123233a5658934f7bd9fe714d7864d\"\n" +
" type: \"executable\"\n" +
" uri: \"https://github.com/mikefarah/yq/releases/download/v4.30.4/yq_linux_amd64\"\n" +
" - packageName: \"glibc-devel\"\n" +
" type: \"rpm\"\n" +
"additionalMemory: 4096\n" +
"allowedDifferences:\n" +
" - \"\\\\Q-:jbossws-common-4.0.0.Final.jar:class:org/jboss/ws/common/CalendarTest\\\\E\"\n" +
"alternativeArgs:\n" +
" - \"'set Global / baseVersionSuffix:=\\\"\\\"'\"\n" +
" - \"enableOptimizer\"\n" +
"enforceVersion: true\n" +
"repositories:\n" +
" - \"caucho\"\n", generated);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
repositories:
- caucho
additionalArgs:
- "-DskipDocs"
additionalDownloads:
- uri: https://github.com/mikefarah/yq/releases/download/v4.30.4/yq_linux_amd64
sha256: 30459aa144a26125a1b22c62760f9b3872123233a5658934f7bd9fe714d7864d
type: executable
fileName: yq
binaryPath: only_for_tar/bin
- type: rpm
packageName: glibc-devel
additionalMemory: 4096
additionalBuilds:
pureJava:
preBuildScript: |
./autogen.sh
/bin/sh -c "$(rpm --eval %configure); $(rpm --eval %__make) $(rpm --eval %_smp_mflags)"
additionalArgs:
- "-Dlz4-pure-java=true"
allowedDifferences:
- \Q-:jbossws-common-4.0.0.Final.jar:class:org/jboss/ws/common/CalendarTest\E
alternativeArgs:
- "'set Global / baseVersionSuffix:=\"\"'"
- "enableOptimizer"
enforceVersion: true
2 changes: 1 addition & 1 deletion pkg/reconciler/dependencybuild/buildrecipeyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func additionalPackages(recipe *v1alpha1.BuildRecipe) string {
}

func gitScript(db *v1alpha1.DependencyBuild, recipe *v1alpha1.BuildRecipe) string {
gitArgs := "echo \"Cloning $(params." + PipelineParamScmUrl + ")\" && "
gitArgs := "echo \"Cloning $(params." + PipelineParamScmUrl + ") and resetting to $(params." + PipelineParamScmHash + ")\" && "
if db.Spec.ScmInfo.Private {
gitArgs = gitArgs + "echo \"$GIT_TOKEN\" > $HOME/.git-credentials && chmod 400 $HOME/.git-credentials && "
gitArgs = gitArgs + "echo '[credential]\n helper=store\n' > $HOME/.gitconfig && "
Expand Down

0 comments on commit 850b81e

Please sign in to comment.