Repository: deepjavalibrary/djl
Pull request #1742 (2022-06-22 17:56:26)

[ci] Fixes serving publish github actions
Change-Id: I81504d21ef5bccb52eec129e7465015d869be8f1

## Description ##

Brief description of what this PR is about

- If this change is a backward incompatible change, why must this change be made?
- Interesting edge cases to note here



Patch:
diff --git a/.github/workflows/serving_publish.yml b/.github/workflows/serving_publish.yml
index 2a10ef668..c3c0ca83e 100644
--- a/.github/workflows/serving_publish.yml
+++ b/.github/workflows/serving_publish.yml
@@ -64,7 +64,7 @@ jobs:
           ./gradlew :serving:createDeb -Psnapshot
           DJL_VERSION=$(cat gradle.properties | awk -F '=' '/djl_version/ {print $2}')
           aws s3 cp serving/build/distributions/*.deb s3://djl-ai/publish/djl-serving/
-          aws cloudfront create-invalidation --distribution-id E371VB8JQ6NRVY --paths "/djl-serving/djl-serving_${DJL_VERSION}~SNAPSHOT*"
+          aws cloudfront create-invalidation --distribution-id E371VB8JQ6NRVY --paths "/djl-serving/djl-serving_${DJL_VERSION}*"
       - name: Publish release deb
         if: ${{ github.event.inputs.mode == 'staging' }}
         run: |
diff --git a/api/src/main/java/ai/djl/repository/zoo/Criteria.java b/api/src/main/java/ai/djl/repository/zoo/Criteria.java
index c90c0aa92..c8e528d3a 100644
--- a/api/src/main/java/ai/djl/repository/zoo/Criteria.java
+++ b/api/src/main/java/ai/djl/repository/zoo/Criteria.java
@@ -353,6 +353,29 @@ public class Criteria<I, O> {
         return sb.toString();
     }
 
+    /**
+     * Creates a new {@link Builder} which starts with the values of this {@link Criteria}.
+     *
+     * @return a new {@link Builder}
+     */
+    public Builder<I, O> toBuilder() {
+        return Criteria.builder()
+                .setTypes(inputClass, outputClass)
+                .optApplication(application)
+                .optEngine(engine)
+                .optDevice(device)
+                .optGroupId(groupId)
+                .optArtifactId(artifactId)
+                .optModelZoo(modelZoo)
+                .optFilters(filters)
+                .optArguments(arguments)
+                .optOptions(options)
+                .optTranslatorFactory(factory)
+                .optBlock(block)
+                .optModelName(modelName)
+                .optProgress(progress);
+    }
+
     /**
      * Creates a builder to build a {@code Criteria}.
      *
@@ -626,6 +649,7 @@ public class Criteria<I, O> {
          * @return this {@code Builder}
          */
         public Builder<I, O> optTranslator(Translator<I, O> translator) {
+            this.factory = null;
             this.translator = translator;
             return this;
         }
@@ -637,6 +661,7 @@ public class Criteria<I, O> {
          * @return this {@code Builder}
          */
         public Builder<I, O> optTranslatorFactory(TranslatorFactory factory) {
+            this.translator = null;
             this.factory = factory;
             return this;
         }


Test patch:
diff --git a/api/src/test/java/ai/djl/repository/ZooTest.java b/api/src/test/java/ai/djl/repository/ZooTest.java
new file mode 100644
index 000000000..65425903b
--- /dev/null
+++ b/api/src/test/java/ai/djl/repository/ZooTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
+ * with the License. A copy of the License is located at
+ *
+ * http://aws.amazon.com/apache2.0/
+ *
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ */
+package ai.djl.repository;
+
+import ai.djl.modality.Input;
+import ai.djl.modality.Output;
+import ai.djl.repository.zoo.Criteria;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class ZooTest {
+
+    @Test
+    public void testCriteriaToBuilder() {
+        Criteria<Input, Output> criteria1 =
+                Criteria.builder()
+                        .setTypes(Input.class, Output.class)
+                        .optEngine("testEngine1")
+                        .optModelName("testModelName")
+                        .build();
+
+        Criteria<Input, Output> criteria2 = criteria1.toBuilder().optEngine("testEngine2").build();
+
+        Assert.assertEquals("testEngine1", criteria1.getEngine());
+        Assert.assertEquals("testEngine2", criteria2.getEngine());
+        Assert.assertEquals("testModelName", criteria1.getModelName());
+        Assert.assertEquals("testModelName", criteria2.getModelName());
+    }
+}