Skip to content

Commit

Permalink
Stop overfit of recipes to CI jobs named build
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Oct 31, 2024
1 parent b4187fe commit 46bd6e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public String getDescription() {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
JsonPathMatcher firstStep = new JsonPathMatcher("$.jobs.build.steps[:1].uses");
JsonPathMatcher jobSteps = new JsonPathMatcher("$.jobs.build.steps.*");
JsonPathMatcher firstStep = new JsonPathMatcher("$.jobs..steps[:1].uses");
JsonPathMatcher jobSteps = new JsonPathMatcher("$.jobs..steps.*");

String userProvidedAccessTokenTemplate = "" +
"- uses: styfle/cancel-workflow-action@0.9.1\n" +
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/openrewrite/github/SetupJavaCaching.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
@Override
public Yaml visitDocuments(Yaml.Documents documents, ExecutionContext ctx) {
Yaml.Documents d = documents;
if (!FindKey.find(documents, "$.jobs.build.steps[?(@.run =~ '.*gradle.*')]").isEmpty()) {
d = (Yaml.Documents) new MergeYaml("$.jobs.build.steps[?(@.uses =~ 'actions/setup-java(?:@v.+)?')]",
if (!FindKey.find(documents, "$.jobs..steps[?(@.run =~ '.*gradle.*')]").isEmpty()) {
d = (Yaml.Documents) new MergeYaml("$.jobs..steps[?(@.uses =~ 'actions/setup-java(?:@v.+)?')]",
"" +
"with:\n" +
" cache: 'gradle'", true, null, null)
.getVisitor().visitNonNull(d, ctx);
}
if (!FindKey.find(documents, "$.jobs.build.steps[?(@.run =~ '.*mvn.*')]").isEmpty()) {
d = (Yaml.Documents) new MergeYaml("$.jobs.build.steps[?(@.uses =~ 'actions/setup-java(?:@v.+)?')]",
if (!FindKey.find(documents, "$.jobs..steps[?(@.run =~ '.*mvn.*')]").isEmpty()) {
d = (Yaml.Documents) new MergeYaml("$.jobs..steps[?(@.uses =~ 'actions/setup-java(?:@v.+)?')]",
"" +
"with:\n" +
" cache: 'maven'", true, null, null)
.getVisitor().visitNonNull(d, ctx);
}
if (d != documents) {
d = (Yaml.Documents) new DeleteKey("$.jobs.build.steps[?(@.uses =~ 'actions/cache(?:@v.+)?')]", null)
d = (Yaml.Documents) new DeleteKey("$.jobs..steps[?(@.uses =~ 'actions/cache(?:@v.+)?')]", null)
.getVisitor().visitNonNull(d, ctx);
}
return d;
Expand Down

0 comments on commit 46bd6e8

Please sign in to comment.