diff --git a/.github/helper/roulette.py b/.github/helper/roulette.py index ce4c8ed633..311f15c9db 100644 --- a/.github/helper/roulette.py +++ b/.github/helper/roulette.py @@ -1,5 +1,6 @@ import os import re +import requests import shlex import subprocess import sys @@ -14,19 +15,24 @@ def is_py(file): return file.endswith("py") def is_ci(file): - return file.endswith("yml") or ".github" in file + return ".github" in file -def is_js(file): - return file.endswith("js") +def is_frontend_code(file): + return file.endswith((".css", ".scss", ".less", ".sass", ".styl", ".js", ".ts")) def is_docs(file): - regex = re.compile(r'\.(md|png|jpg|jpeg)$|^.github|LICENSE') + regex = re.compile(r'\.(md|png|jpg|jpeg|csv)$|^.github|LICENSE') return bool(regex.search(file)) if __name__ == "__main__": files_list = sys.argv[1:] build_type = os.environ.get("TYPE") + pr_number = os.environ.get("PR_NUMBER") + + if not files_list and pr_number: + res = requests.get(f"https://api.github.com/repos/frappe/frappe/pulls/{pr_number}/files") + files_list = [f["filename"] for f in res.json()] if not files_list: print("No files' changes detected. Build is shutting") @@ -34,7 +40,7 @@ if __name__ == "__main__": ci_files_changed = any(f for f in files_list if is_ci(f)) only_docs_changed = len(list(filter(is_docs, files_list))) == len(files_list) - only_js_changed = len(list(filter(is_js, files_list))) == len(files_list) + only_frontend_code_changed = len(list(filter(is_frontend_code, files_list))) == len(files_list) only_py_changed = len(list(filter(is_py, files_list))) == len(files_list) if ci_files_changed: @@ -44,8 +50,8 @@ if __name__ == "__main__": print("Only docs were updated, stopping build process.") sys.exit(0) - if only_js_changed and build_type == "server": - print("Only JavaScript code was updated; Stopping Python build process.") + if only_frontend_code_changed and build_type == "server": + print("Only Frontend code was updated; Stopping Python build process.") sys.exit(0) if only_py_changed and build_type == "ui": diff --git a/.github/workflows/patch-mariadb-tests.yml b/.github/workflows/patch-mariadb-tests.yml index 27776fb2f1..d0de566e9d 100644 --- a/.github/workflows/patch-mariadb-tests.yml +++ b/.github/workflows/patch-mariadb-tests.yml @@ -26,15 +26,13 @@ jobs: with: python-version: 3.7 - - uses: jitterbit/get-changed-files@v1 - id: files - - name: Check if build should be run id: check-build run: | - python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" ${{ steps.files.outputs.all }} + python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" env: TYPE: "server" + PR_NUMBER: ${{ github.event.number }} - name: Add to Hosts if: ${{ steps.check-build.outputs.build == 'strawberry' }} diff --git a/.github/workflows/server-mariadb-tests.yml b/.github/workflows/server-mariadb-tests.yml index d6d5097a09..da9724c6bd 100644 --- a/.github/workflows/server-mariadb-tests.yml +++ b/.github/workflows/server-mariadb-tests.yml @@ -35,15 +35,13 @@ jobs: with: python-version: 3.7 - - uses: jitterbit/get-changed-files@v1 - id: files - - name: Check if build should be run id: check-build run: | - python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" ${{ steps.files.outputs.all }} + python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" env: TYPE: "server" + PR_NUMBER: ${{ github.event.number }} - uses: actions/setup-node@v2 if: ${{ steps.check-build.outputs.build == 'strawberry' }} diff --git a/.github/workflows/server-postgres-tests.yml b/.github/workflows/server-postgres-tests.yml index b2a283340c..d7658bc1ba 100644 --- a/.github/workflows/server-postgres-tests.yml +++ b/.github/workflows/server-postgres-tests.yml @@ -37,15 +37,13 @@ jobs: with: python-version: 3.7 - - uses: jitterbit/get-changed-files@v1 - id: files - - name: Check if build should be run id: check-build run: | - python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" ${{ steps.files.outputs.all }} + python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" env: TYPE: "server" + PR_NUMBER: ${{ github.event.number }} - uses: actions/setup-node@v2 if: ${{ steps.check-build.outputs.build == 'strawberry' }} diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml index af598d6c40..90c72e7018 100644 --- a/.github/workflows/ui-tests.yml +++ b/.github/workflows/ui-tests.yml @@ -35,15 +35,13 @@ jobs: with: python-version: 3.7 - - uses: jitterbit/get-changed-files@v1 - id: files - - name: Check if build should be run id: check-build run: | - python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" ${{ steps.files.outputs.all }} + python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" env: TYPE: "ui" + PR_NUMBER: ${{ github.event.number }} - uses: actions/setup-node@v2 if: ${{ steps.check-build.outputs.build == 'strawberry' }}