Skip to content
Snippets Groups Projects
Commit a6959ee5 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[build] Separate and improve git-clean action

parent 1fc67b0b
No related branches found
No related tags found
No related merge requests found
Pipeline #26163 failed
...@@ -81,6 +81,10 @@ build_macosx_36: ...@@ -81,6 +81,10 @@ build_macosx_36:
- source ${CONDA_ROOT}/etc/profile.d/conda.sh - source ${CONDA_ROOT}/etc/profile.d/conda.sh
- conda activate bdt - conda activate bdt
- bdt ci deploy -vv - bdt ci deploy -vv
after_script:
- source ${CONDA_ROOT}/etc/profile.d/conda.sh
- conda activate bdt
- bdt ci clean -vv
dependencies: dependencies:
- build_linux_36 - build_linux_36
- build_macosx_36 - build_macosx_36
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import os import os
import re import re
import sys import sys
import glob
import json import json
import shutil import shutil
import platform import platform
...@@ -370,26 +371,39 @@ def check_version(workdir, envtag): ...@@ -370,26 +371,39 @@ def check_version(workdir, envtag):
return version, is_prerelease return version, is_prerelease
def git_clean_build(runner, arch): def git_clean_build(runner, verbose):
'''Runs git-clean to clean-up build products '''Runs git-clean to clean-up build products
Args: Args:
runner: A pointer to the ``run_cmdline()`` function runner: A pointer to the ``run_cmdline()`` function
verbose: A boolean flag indicating if the git command should report erased
files or not
''' '''
# runs git clean to clean everything that is not needed. This helps to keep # glob wild card entries we'd like to keep
# the disk usage on CI machines to a minimum.
exclude_from_cleanup = [ exclude_from_cleanup = [
"miniconda.sh", #the installer, cached "miniconda.sh", #the installer, cached
"miniconda/pkgs/*.tar.bz2", #downloaded packages, cached
"miniconda/pkgs/urls.txt", #download index, cached "miniconda/pkgs/urls.txt", #download index, cached
"miniconda/conda-bld/%s/*.tar.bz2" % (arch,), #build artifact -- conda
"dist/*.zip", #build artifact -- pypi package
"sphinx", #build artifact -- documentation "sphinx", #build artifact -- documentation
] ]
runner(['git', 'clean', '-qffdx'] + \
# cache
exclude_from_cleanup += glob.glob("miniconda/pkgs/*.tar.bz2")
# artifacts
exclude_from_cleanup += glob.glob("miniconda/conda-bld/*/*.tar.bz2")
exclude_from_cleanup += glob.glob("dist/*.zip")
logger.debug('Excluding the following paths from git-clean:\n - %s',
' - '.join(exclude_from_cleanup))
# decide on verbosity
flags = '-ffdx'
if not verbose: flags += 'q'
runner(['git', 'clean', flags] + \
['--exclude=%s' % k for k in exclude_from_cleanup]) ['--exclude=%s' % k for k in exclude_from_cleanup])
...@@ -437,13 +451,15 @@ if __name__ == '__main__': ...@@ -437,13 +451,15 @@ if __name__ == '__main__':
bootstrap.setup_logger(logger, args.verbose) bootstrap.setup_logger(logger, args.verbose)
bootstrap.set_environment('DOCSERVER', bootstrap._SERVER, verbose=True) VERB = (verbose >= 2)
bootstrap.set_environment('LANG', 'en_US.UTF-8', verbose=True)
bootstrap.set_environment('LC_ALL', os.environ['LANG'], verbose=True) bootstrap.set_environment('DOCSERVER', bootstrap._SERVER, verbose=VERB)
bootstrap.set_environment('LANG', 'en_US.UTF-8', verbose=VERB)
bootstrap.set_environment('LC_ALL', os.environ['LANG'], verbose=VERB)
# get information about the version of the package being built # get information about the version of the package being built
version, is_prerelease = check_version(args.work_dir, args.tag) version, is_prerelease = check_version(args.work_dir, args.tag)
bootstrap.set_environment('BOB_PACKAGE_VERSION', version, verbose=True) bootstrap.set_environment('BOB_PACKAGE_VERSION', version, verbose=VERB)
# create the build configuration # create the build configuration
conda_build_config = os.path.join(mydir, 'data', 'conda_build_config.yaml') conda_build_config = os.path.join(mydir, 'data', 'conda_build_config.yaml')
...@@ -474,7 +490,7 @@ if __name__ == '__main__': ...@@ -474,7 +490,7 @@ if __name__ == '__main__':
build_number, _ = next_build_number(channels[0], args.name, version, build_number, _ = next_build_number(channels[0], args.name, version,
args.python_version) args.python_version)
bootstrap.set_environment('BOB_BUILD_NUMBER', str(build_number), bootstrap.set_environment('BOB_BUILD_NUMBER', str(build_number),
verbose=True) verbose=VERB)
# runs the build using the conda-build API # runs the build using the conda-build API
arch = conda_arch() arch = conda_arch()
...@@ -484,4 +500,4 @@ if __name__ == '__main__': ...@@ -484,4 +500,4 @@ if __name__ == '__main__':
conda_build.api.build(os.path.join(args.work_dir, 'conda'), conda_build.api.build(os.path.join(args.work_dir, 'conda'),
config=conda_config) config=conda_config)
git_clean_build(bootstrap.run_cmdline, arch) git_clean_build(bootstrap.run_cmdline, verbose=VERB)
...@@ -263,8 +263,6 @@ def build(ctx, dry_run): ...@@ -263,8 +263,6 @@ def build(ctx, dry_run):
""" """
from ..constants import CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND from ..constants import CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND
from ..build import conda_arch, git_clean_build
from ..bootstrap import run_cmdline
from .build import build from .build import build
ctx.invoke(build, ctx.invoke(build,
...@@ -281,4 +279,26 @@ def build(ctx, dry_run): ...@@ -281,4 +279,26 @@ def build(ctx, dry_run):
ci=True, ci=True,
) )
git_clean_build(run_cmdline, conda_arch())
@ci.command(epilog='''
Examples:
1. Cleans the current build (and prints what it cleans)
$ bdt ci clean -vv
''')
@verbosity_option()
@bdt.raise_on_error
@click.pass_context
def clean(ctx):
"""Cleans builds
This command cleans builds in the CI infrastructure. It is **not** meant
to be used outside this context.
"""
from ..build import git_clean_build
from ..bootstrap import run_cmdline
git_clean_build(run_cmdline, verbose=(ctx.meta['verbosity']>=2))
...@@ -68,6 +68,8 @@ test: ...@@ -68,6 +68,8 @@ test:
- bdt ci build --help - bdt ci build --help
- bdt ci deploy --help - bdt ci deploy --help
- bdt ci pypi --help - bdt ci pypi --help
- bdt ci readme --help
- bdt ci clean --help
- sphinx-build -aEW ${PREFIX}/share/doc/{{ name }}/doc {{ project_dir }}/sphinx - sphinx-build -aEW ${PREFIX}/share/doc/{{ name }}/doc {{ project_dir }}/sphinx
about: about:
......
...@@ -56,6 +56,7 @@ setup( ...@@ -56,6 +56,7 @@ setup(
'bdt.ci.cli': [ 'bdt.ci.cli': [
'build = bob.devtools.scripts.ci:build', 'build = bob.devtools.scripts.ci:build',
'clean = bob.devtools.scripts.ci:clean',
'deploy = bob.devtools.scripts.ci:deploy', 'deploy = bob.devtools.scripts.ci:deploy',
'readme = bob.devtools.scripts.ci:readme', 'readme = bob.devtools.scripts.ci:readme',
'pypi = bob.devtools.scripts.ci:pypi', 'pypi = bob.devtools.scripts.ci:pypi',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment