Browse Source

ci(roulette): Use GitHub REST to figure out changed files

version-14
Gavin D'souza 3 years ago
parent
commit
e01ef7ff52
5 changed files with 21 additions and 23 deletions
  1. +13
    -7
      .github/helper/roulette.py
  2. +2
    -4
      .github/workflows/patch-mariadb-tests.yml
  3. +2
    -4
      .github/workflows/server-mariadb-tests.yml
  4. +2
    -4
      .github/workflows/server-postgres-tests.yml
  5. +2
    -4
      .github/workflows/ui-tests.yml

+ 13
- 7
.github/helper/roulette.py View File

@@ -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":


+ 2
- 4
.github/workflows/patch-mariadb-tests.yml View File

@@ -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' }}


+ 2
- 4
.github/workflows/server-mariadb-tests.yml View File

@@ -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' }}


+ 2
- 4
.github/workflows/server-postgres-tests.yml View File

@@ -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' }}


+ 2
- 4
.github/workflows/ui-tests.yml View File

@@ -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' }}


Loading…
Cancel
Save