Browse Source

ci: separate cache for UI jobs and selective test

This is reusing normal cache which doesn't contain half the things

(cherry picked from commit 236ab8dbed)
version-14
Ankush Menat 2 years ago
committed by Ankush Menat
parent
commit
1e81a2a2b5
2 changed files with 38 additions and 14 deletions
  1. +34
    -7
      .github/helper/roulette.py
  2. +4
    -7
      .github/workflows/ui-tests.yml

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

@@ -17,39 +17,57 @@ def fetch_pr_data(pr_number, repo, endpoint=""):

req = urllib.request.Request(api_url)
res = urllib.request.urlopen(req)
return json.loads(res.read().decode('utf8'))
return json.loads(res.read().decode("utf8"))


def get_files_list(pr_number, repo="frappe/frappe"):
return [change["filename"] for change in fetch_pr_data(pr_number, repo, "files")]


def get_output(command, shell=True):
print(command)
command = shlex.split(command)
return subprocess.check_output(command, shell=shell, encoding="utf8").strip()


def has_skip_ci_label(pr_number, repo="frappe/frappe"):
return has_label(pr_number, "Skip CI", repo)


def has_run_server_tests_label(pr_number, repo="frappe/frappe"):
return has_label(pr_number, "Run Server Tests", repo)


def has_run_ui_tests_label(pr_number, repo="frappe/frappe"):
return has_label(pr_number, "Run UI Tests", repo)


def has_label(pr_number, label, repo="frappe/frappe"):
return any([fetched_label["name"] for fetched_label in fetch_pr_data(pr_number, repo)["labels"] if fetched_label["name"] == label])
return any(
[
fetched_label["name"]
for fetched_label in fetch_pr_data(pr_number, repo)["labels"]
if fetched_label["name"] == label
]
)


def is_py(file):
return file.endswith("py")


def is_ci(file):
return ".github" in file


def is_frontend_code(file):
return file.lower().endswith((".css", ".scss", ".less", ".sass", ".styl", ".js", ".ts", ".vue", ".html"))
return file.lower().endswith(
(".css", ".scss", ".less", ".sass", ".styl", ".js", ".ts", ".vue", ".html")
)


def is_docs(file):
regex = re.compile(r'\.(md|png|jpg|jpeg|csv|svg)$|^.github|LICENSE')
regex = re.compile(r"\.(md|png|jpg|jpeg|csv|svg)$|^.github|LICENSE")
return bool(regex.search(file))


@@ -78,8 +96,13 @@ if __name__ == "__main__":
only_py_changed = updated_py_file_count == len(files_list)

if has_skip_ci_label(pr_number, repo):
print("Found `Skip CI` label on pr, stopping build process.")
sys.exit(0)
if build_type == "ui" and has_run_ui_tests_label(pr_number, repo):
print("Running UI tests only.")
elif build_type == "server" and has_run_server_tests_label(pr_number, repo):
print("Running server tests only.")
else:
print("Found `Skip CI` label on pr, stopping build process.")
sys.exit(0)

elif ci_files_changed:
print("CI related files were updated, running all build processes.")
@@ -88,7 +111,11 @@ if __name__ == "__main__":
print("Only docs were updated, stopping build process.")
sys.exit(0)

elif only_frontend_code_changed and build_type == "server" and not has_run_server_tests_label(pr_number, repo):
elif (
only_frontend_code_changed
and build_type == "server"
and not has_run_server_tests_label(pr_number, repo)
):
print("Only Frontend code was updated; Stopping Python build process.")
sys.exit(0)



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

@@ -105,19 +105,16 @@ jobs:
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-yarn-ui-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
${{ runner.os }}-yarn-ui-

- name: Cache cypress binary
if: ${{ steps.check-build.outputs.build == 'strawberry' }}
uses: actions/cache@v3
with:
path: ~/.cache
key: ${{ runner.os }}-cypress-
restore-keys: |
${{ runner.os }}-cypress-
${{ runner.os }}-
path: ~/.cache/Cypress
key: ${{ runner.os }}-cypress

- name: Install Dependencies
if: ${{ steps.check-build.outputs.build == 'strawberry' }}


Loading…
Cancel
Save