-
Notifications
You must be signed in to change notification settings - Fork 626
Add clean command to fireci #6563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
56479ef
bump fireci deps
daymxn d93ac5b
Add debug flag to fireci
daymxn 04ab616
Default to info with CI override
daymxn 3733ca0
Implement clean command
daymxn b4f6504
Add extra useful info to ci readme
daymxn 15a5489
Update dir_utils.py
daymxn 2e122e4
Update ci_utils.py
daymxn 039195e
Merge branch 'main' into daymon-add-clean-command
daymxn 3e97408
Address comments
daymxn d366ab6
Update README.md
daymxn 8cd31e0
Update clean.py
daymxn 956e3a7
Merge branch 'main' into daymon-add-clean-command
daymxn 7d9c431
Update setup.cfg
daymxn 4e9782b
Merge branch 'daymon-add-clean-command' of https://github.com/firebas…
daymxn f8913d3
Merge branch 'main' into daymon-add-clean-command
daymxn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed 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. | ||
|
||
import click | ||
import logging | ||
|
||
from fireci import ci_command | ||
from fireci import ci_utils | ||
from fireci import dir_utils | ||
from typing import Tuple, List, Callable, Union | ||
from termcolor import colored | ||
|
||
log = logging.getLogger('fireci.clean') | ||
|
||
@click.argument("projects", | ||
nargs=-1, | ||
type=click.Path(), | ||
required=False | ||
) | ||
@click.option('--gradle/--no-gradle', default=False, help="Delete the local .gradle caches.") | ||
@click.option('--build/--no-build', default=True, help="Delete the local build caches.") | ||
@click.option('--transforms/--no-transforms', default=False, help="Delete the system-wide transforms cache.") | ||
@click.option('--build-cache/--no-build-cache', default=False, help="Delete the system-wide build cache.") | ||
|
||
@click.option('--deep/--no-deep', default=False, help="Delete all of the system-wide files for gradle.") | ||
@click.option('--cache/--no-cache', default=False, help="Delete all of the system-wide caches for gradle.") | ||
@ci_command(epilog=""" | ||
Clean a subset of projects: | ||
|
||
\b | ||
$ fireci clean firebase-common | ||
$ fireci clean firebase-common firebase-vertexai | ||
|
||
Clean all projects: | ||
|
||
$ fireci clean | ||
""") | ||
def clean(projects, gradle, build, transforms, build_cache, deep, cache): | ||
""" | ||
Delete files cached by gradle. | ||
|
||
Alternative to the standard `gradlew clean`, which runs outside the scope of gradle, | ||
and provides deeper cache cleaning capabilities. | ||
""" | ||
if not projects: | ||
log.debug("No projects specified, so we're defaulting to all projects.") | ||
projects = ci_utils.get_projects() | ||
|
||
cache = cache or deep | ||
gradle = gradle or cache | ||
|
||
cleaners = [] | ||
|
||
if build: | ||
cleaners.append(delete_build) | ||
if gradle: | ||
cleaners.append(delete_gradle) | ||
|
||
results = [call_and_sum(projects, cleaner) for cleaner in cleaners] | ||
local_count = tuple(map(sum, zip(*results))) | ||
|
||
cleaners = [] | ||
|
||
if deep: | ||
cleaners.append(delete_deep) | ||
elif cache: | ||
cleaners.append(delete_cache) | ||
else: | ||
if transforms: | ||
cleaners.append(delete_transforms) | ||
if build_cache: | ||
cleaners.append(delete_build_cache) | ||
|
||
results = [cleaner() for cleaner in cleaners] | ||
system_count = ci_utils.counts(results) | ||
|
||
[deleted, skipped] = tuple(a + b for a, b in zip(local_count, system_count)) | ||
|
||
log.info(f""" | ||
Clean results: | ||
|
||
{colored("Deleted:", None, attrs=["bold"])} {colored(deleted, "red")} | ||
{colored("Already deleted:", None, attrs=["bold"])} {colored(skipped, "grey")} | ||
""") | ||
|
||
|
||
def call_and_sum(variables: List[str], func: Callable[[str], Union[bool, int]]) -> Tuple[int, int]: | ||
results = list(map(lambda var: func(var), variables)) | ||
return ci_utils.counts(results) | ||
|
||
def delete_build(dir: str) -> bool: | ||
return dir_utils.rmdir(f"{dir}/build") | ||
|
||
def delete_gradle(dir: str) -> bool: | ||
return dir_utils.rmdir(f"{dir}/.gradle") | ||
|
||
def delete_transforms() -> int: | ||
return dir_utils.rmglob("~/.gradle/caches/transforms-*") | ||
|
||
def delete_build_cache() -> int: | ||
return dir_utils.rmglob("~/.gradle/caches/build-cache-*") | ||
|
||
def delete_deep() -> bool: | ||
return dir_utils.rmdir("~/.gradle") | ||
|
||
def delete_cache() -> bool: | ||
return dir_utils.rmdir("~/.gradle/caches") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.