You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/03/23 13:30:29 UTC

[GitHub] [beam] KhaninArtur commented on a change in pull request #17164: [BEAM-14140][Playground] Fix Deploy examples CI to run only on changed examples

KhaninArtur commented on a change in pull request #17164:
URL: https://github.com/apache/beam/pull/17164#discussion_r833267842



##########
File path: playground/infrastructure/checker.py
##########
@@ -0,0 +1,66 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License 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.
+
+"""
+Module implements check to define if it is needed to run CI step for Beam
+Playground examples
+"""
+import os
+import sys
+
+from config import Config
+from helper import get_tag
+
+root_dir = os.getenv("BEAM_ROOT_DIR")
+
+
+def _check_envs():
+  if root_dir is None:
+    raise KeyError(
+      "BEAM_ROOT_DIR environment variable should be specified in os")
+
+
+def check(paths) -> bool:
+  pathsArr = []
+  startInd = 0
+  lastInd = 0
+  while lastInd < len(paths):
+    if paths[lastInd] == ".":
+      lastInd += 1
+      while lastInd < len(paths) and paths[lastInd] != " ":
+        lastInd += 1
+      pathsArr.append(paths[startInd:lastInd])
+      lastInd += 1
+      startInd = lastInd
+    lastInd += 1
+  for filepath in pathsArr:
+    extension = filepath.split(os.extsep)[-1]
+    if extension not in Config.SDK_TO_EXTENSION.values():
+      continue
+    filepath = root_dir + filepath
+    if get_tag(filepath) is not None:
+      return True
+  return False
+
+
+if __name__ == "__main__":
+  paths = ""
+  if len(sys.argv) > 1:
+    for arg in sys.argv[1:len(sys.argv) - 1]:
+      paths += arg + " "
+    paths += sys.argv[len(sys.argv) - 1]
+  else:
+    print(False)

Review comment:
       ```suggestion
     paths = " ".join(sys.argv[1:])
   ```

##########
File path: .github/workflows/playground_deploy_examples.yml
##########
@@ -21,17 +21,48 @@ on:
     branches: ['master', 'release-*']
   pull_request:
   workflow_dispatch:
-
+env:
+  BEAM_ROOT_DIR: ../../
+  BEAM_EXAMPLE_CATEGORIES: ../categories.yaml
+  BEAM_VERSION: 2.33.0
+  K8S_NAMESPACE: playground-backend
+  HELM_APP_NAME: playground-backend
 jobs:
+  check_examples:
+    name: Check examples
+    runs-on: ubuntu-latest
+    outputs:
+      example_has_changed: ${{ steps.check_has_example.outputs.example_has_changed }}
+    steps:
+      - name: Check out the repo
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+      - uses: actions/setup-python@v2
+        with:
+          python-version: '3.8'
+      - name: install deps
+        run: pip install -r requirements.txt
+        working-directory: playground/infrastructure
+      - shell: pwsh
+        name: get Difference
+        id: check_file_changed
+        run: |
+          $diff = git diff --name-only master
+          Write-Host "::set-output name=example_diff::$diff"
+      - name: has Exapmles

Review comment:
       ```suggestion
         - name: has Examples
   ```

##########
File path: playground/infrastructure/checker.py
##########
@@ -0,0 +1,66 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License 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.
+
+"""
+Module implements check to define if it is needed to run CI step for Beam
+Playground examples
+"""
+import os
+import sys
+
+from config import Config
+from helper import get_tag
+
+root_dir = os.getenv("BEAM_ROOT_DIR")
+
+
+def _check_envs():
+  if root_dir is None:
+    raise KeyError(
+      "BEAM_ROOT_DIR environment variable should be specified in os")
+
+
+def check(paths) -> bool:
+  pathsArr = []
+  startInd = 0
+  lastInd = 0
+  while lastInd < len(paths):
+    if paths[lastInd] == ".":
+      lastInd += 1
+      while lastInd < len(paths) and paths[lastInd] != " ":
+        lastInd += 1
+      pathsArr.append(paths[startInd:lastInd])
+      lastInd += 1
+      startInd = lastInd
+    lastInd += 1
+  for filepath in pathsArr:
+    extension = filepath.split(os.extsep)[-1]
+    if extension not in Config.SDK_TO_EXTENSION.values():
+      continue
+    filepath = root_dir + filepath
+    if get_tag(filepath) is not None:
+      return True
+  return False
+
+
+if __name__ == "__main__":
+  paths = ""
+  if len(sys.argv) > 1:
+    for arg in sys.argv[1:len(sys.argv) - 1]:
+      paths += arg + " "
+    paths += sys.argv[len(sys.argv) - 1]
+  else:
+    print(False)
+  print(check(paths))

Review comment:
       Should we print it?
   And should we run the `check` function if `paths` is empty?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org