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

This commit is contained in:
Gavin D'souza 2021-08-25 12:40:44 +05:30
parent 597d237f63
commit e01ef7ff52
5 changed files with 21 additions and 23 deletions

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

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

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

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

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