From 46bd6e8772f1263e9bd6b6b36dfdfcd346140c85 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 31 Oct 2024 22:52:36 +0100 Subject: [PATCH] Stop overfit of recipes to CI jobs named build --- .../github/AutoCancelInProgressWorkflow.java | 4 ++-- .../java/org/openrewrite/github/SetupJavaCaching.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/openrewrite/github/AutoCancelInProgressWorkflow.java b/src/main/java/org/openrewrite/github/AutoCancelInProgressWorkflow.java index 4fd52f1..7893738 100644 --- a/src/main/java/org/openrewrite/github/AutoCancelInProgressWorkflow.java +++ b/src/main/java/org/openrewrite/github/AutoCancelInProgressWorkflow.java @@ -51,8 +51,8 @@ public String getDescription() { @Override public TreeVisitor 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" + diff --git a/src/main/java/org/openrewrite/github/SetupJavaCaching.java b/src/main/java/org/openrewrite/github/SetupJavaCaching.java index f1c1277..b7b89b6 100644 --- a/src/main/java/org/openrewrite/github/SetupJavaCaching.java +++ b/src/main/java/org/openrewrite/github/SetupJavaCaching.java @@ -39,22 +39,22 @@ public TreeVisitor 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;