def main(): """Build OSS-Fuzz project's fuzzers for CI tools. This script is used to kick off the Github Actions CI tool. It is the entrypoint of the Dockerfile in this directory. This action can be added to any OSS-Fuzz project's workflow that uses Github. Note: The resulting clusterfuzz binaries of this build are placed in the directory: ${GITHUB_WORKSPACE}/out Required environment variables: OSS_FUZZ_PROJECT_NAME: The name of OSS-Fuzz project. GITHUB_REPOSITORY: The name of the Github repo that called this script. GITHUB_SHA: The commit SHA that triggered this script. GITHUB_EVENT_NAME: The name of the hook event that triggered this script. GITHUB_EVENT_PATH: The path to the file containing the POST payload of the webhook: https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners GITHUB_WORKSPACE: The shared volume directory where input artifacts are. DRY_RUN: If true, no failures will surface. SANITIZER: The sanitizer to use when running fuzzers. Returns: 0 on success or 1 on failure. """ config = config_utils.BuildFuzzersConfig() if config.dry_run: # Sets the default return code on error to success. returncode = 0 else: # The default return code when an error occurs. returncode = 1 if not config.workspace: logging.error('This script needs to be run within Github actions.') return returncode if not build_fuzzers.build_fuzzers(config): logging.error( 'Error building fuzzers for project %s (commit: %s, pr_ref: %s).', config.project_name, config.commit_sha, config.pr_ref) return returncode out_dir = os.path.join(config.workspace, 'out') if not config.bad_build_check: # If we've gotten to this point and we don't need to do bad_build_check, # then the build has succeeded. returncode = 0 # yapf: disable elif build_fuzzers.check_fuzzer_build( out_dir, config.sanitizer, config.language, allowed_broken_targets_percentage=config.allowed_broken_targets_percentage ): # yapf: enable returncode = 0 return returncode
def build_fuzzers_entrypoint(): """Builds OSS-Fuzz project's fuzzers for CI tools.""" config = config_utils.BuildFuzzersConfig() if config.dry_run: # Sets the default return code on error to success. returncode = 0 else: # The default return code when an error occurs. returncode = 1 if not build_fuzzers.build_fuzzers(config): logging.error('Error building fuzzers for (commit: %s, pr_ref: %s).', config.commit_sha, config.pr_ref) return returncode if not config.bad_build_check: # If we've gotten to this point and we don't need to do bad_build_check, # then the build has succeeded. returncode = 0 # yapf: disable elif build_fuzzers.check_fuzzer_build( config_utils.Workspace(config), config.sanitizer, config.language, allowed_broken_targets_percentage=config.allowed_broken_targets_percentage ): # yapf: enable returncode = 0 return returncode
def create_config(**kwargs): """Creates a config object and then sets every attribute that is a key in |kwargs| to the corresponding value. Asserts that each key in |kwargs| is an attribute of Config.""" with mock.patch('os.path.basename', return_value=None), mock.patch( 'config_utils.get_project_src_path', return_value=None), mock.patch('config_utils._is_dry_run', return_value=True): config = config_utils.BuildFuzzersConfig() for key, value in kwargs.items(): assert hasattr(config, key), 'Config doesn\'t have attribute: ' + key setattr(config, key, value) return config
def build_fuzzers_entrypoint(): """Builds OSS-Fuzz project's fuzzers for CI tools.""" config = config_utils.BuildFuzzersConfig() if config.dry_run: # Sets the default return code on error to success. returncode = 0 else: # The default return code when an error occurs. returncode = 1 if not build_fuzzers.build_fuzzers(config): logging.error('Error building fuzzers for (commit: %s, pr_ref: %s).', config.commit_sha, config.pr_ref) return returncode return 0
def build_fuzzers_entrypoint(): """Builds OSS-Fuzz project's fuzzers for CI tools.""" config = config_utils.BuildFuzzersConfig() if config.dry_run: # Sets the default return code on error to success. returncode = 0 else: # The default return code when an error occurs. returncode = 1 if not build_fuzzers.build_fuzzers(config): logging.error('Error building fuzzers for (commit: %s, pr_ref: %s).', config.commit_sha, config.pr_ref) return returncode if not config.bad_build_check: # If we've gotten to this point and we don't need to do bad_build_check, # then the build has succeeded. returncode = 0 elif build_fuzzers.check_fuzzer_build(config): returncode = 0 return returncode
def _create_config(self): return config_utils.BuildFuzzersConfig()