aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/cifuzz/actions
diff options
context:
space:
mode:
authorGravatar jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2020-12-07 10:50:11 -0800
committerGravatar GitHub <noreply@github.com>2020-12-07 10:50:11 -0800
commitb0b99d5ccdf5e2e49cfe3138fbcf64e6fef6ea7f (patch)
tree4afa704c82330c785a468ecfe5097314e7b06365 /infra/cifuzz/actions
parenta24cebec02a0c97247bef31963d5f5fadbaa4ebf (diff)
Cifuzz external build (#4656)
* Support building fuzzers for projects outside of OSS-Fuzz * Use retry wrapper * Fix some tests.
Diffstat (limited to 'infra/cifuzz/actions')
-rw-r--r--infra/cifuzz/actions/build_fuzzers/action.yml8
-rw-r--r--infra/cifuzz/actions/build_fuzzers/build_fuzzers_entrypoint.py96
2 files changed, 70 insertions, 34 deletions
diff --git a/infra/cifuzz/actions/build_fuzzers/action.yml b/infra/cifuzz/actions/build_fuzzers/action.yml
index 20420eb3..2919db40 100644
--- a/infra/cifuzz/actions/build_fuzzers/action.yml
+++ b/infra/cifuzz/actions/build_fuzzers/action.yml
@@ -14,6 +14,12 @@ inputs:
sanitizer:
description: 'The sanitizer to build the fuzzers with.'
default: 'address'
+ project-src-path:
+ description: "The path to the project's source code checkout."
+ required: false
+ build-integration-path:
+ description: "The path to the the project's build integration."
+ required: false
runs:
using: 'docker'
image: '../../../build_fuzzers.Dockerfile'
@@ -22,3 +28,5 @@ runs:
DRY_RUN: ${{ inputs.dry-run}}
ALLOWED_BROKEN_TARGETS_PERCENTAGE: ${{ inputs.allowed-broken-targets-percentage}}
SANITIZER: ${{ inputs.sanitizer }}
+ PROJECT_SRC_PATH: ${{ inputs.project-src-path }}
+ BUILD_INTEGRATION_PATH: ${{ inputs.build-integration-path }}
diff --git a/infra/cifuzz/actions/build_fuzzers/build_fuzzers_entrypoint.py b/infra/cifuzz/actions/build_fuzzers/build_fuzzers_entrypoint.py
index 689862c0..5d467e7b 100644
--- a/infra/cifuzz/actions/build_fuzzers/build_fuzzers_entrypoint.py
+++ b/infra/cifuzz/actions/build_fuzzers/build_fuzzers_entrypoint.py
@@ -27,6 +27,32 @@ logging.basicConfig(
level=logging.DEBUG)
+def get_pr_ref(event_path):
+ """Returns the PR ref from |event_path|."""
+ with open(event_path, encoding='utf-8') as file_handle:
+ event = json.load(file_handle)
+ return 'refs/pull/{0}/merge'.format(event['pull_request']['number'])
+
+
+def get_project_src_path(workspace):
+ """Returns the manually checked out path of the project's source if specified
+ or None."""
+ # TODO(metzman): Get rid of MANUAL_SRC_PATH when Skia switches to
+ # project_src_path.
+ path = os.getenv('PROJECT_SRC_PATH', os.getenv('MANUAL_SRC_PATH'))
+ if not path:
+ logging.debug('No PROJECT_SRC_PATH.')
+ return path
+
+ logging.debug('PROJECT_SRC_PATH set.')
+ if os.path.isabs(path):
+ return path
+
+ # If |src| is not absolute, assume we are running in GitHub actions.
+ # TODO(metzman): Don't make this assumption.
+ return os.path.join(workspace, path)
+
+
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
@@ -51,52 +77,54 @@ def main():
Returns:
0 on success or 1 on failure.
"""
- oss_fuzz_project_name = os.environ.get('OSS_FUZZ_PROJECT_NAME')
- github_repo_name = os.path.basename(os.environ.get('GITHUB_REPOSITORY'))
- commit_sha = os.environ.get('GITHUB_SHA')
- event = os.environ.get('GITHUB_EVENT_NAME')
- workspace = os.environ.get('GITHUB_WORKSPACE')
- sanitizer = os.environ.get('SANITIZER').lower()
+ oss_fuzz_project_name = os.getenv('OSS_FUZZ_PROJECT_NAME')
+ github_repo_name = os.path.basename(os.getenv('GITHUB_REPOSITORY'))
+ commit_sha = os.getenv('GITHUB_SHA')
+ event = os.getenv('GITHUB_EVENT_NAME')
+ workspace = os.getenv('GITHUB_WORKSPACE')
+ sanitizer = os.getenv('SANITIZER').lower()
+ project_src_path = get_project_src_path(workspace)
+ build_integration_path = os.getenv('BUILD_INTEGRATION_PATH')
+ allowed_broken_targets_percentage = os.getenv(
+ 'ALLOWED_BROKEN_TARGETS_PERCENTAGE')
# Check if failures should not be reported.
- dry_run = (os.environ.get('DRY_RUN').lower() == 'true')
-
- # The default return code when an error occurs.
- returncode = 1
+ dry_run = os.getenv('DRY_RUN').lower() == 'true'
if 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 workspace:
- logging.error('This script needs to be run in the Github action context.')
- return returncode
-
- if event == 'push' and not cifuzz.build_fuzzers(oss_fuzz_project_name,
- github_repo_name,
- workspace,
- commit_sha=commit_sha,
- sanitizer=sanitizer):
- logging.error('Error building fuzzers for project %s with commit %s.',
- oss_fuzz_project_name, commit_sha)
+ logging.error('This script needs to be run within Github actions.')
return returncode
if event == 'pull_request':
- event_path = os.environ.get('GITHUB_EVENT_PATH')
- with open(event_path, encoding='utf-8') as file_handle:
- event = json.load(file_handle)
- pr_ref = 'refs/pull/{0}/merge'.format(event['pull_request']['number'])
- if not cifuzz.build_fuzzers(oss_fuzz_project_name,
- github_repo_name,
- workspace,
- pr_ref=pr_ref,
- sanitizer=sanitizer):
- logging.error(
- 'Error building fuzzers for project %s with pull request %s.',
- oss_fuzz_project_name, pr_ref)
- return returncode
+ event_path = os.getenv('GITHUB_EVENT_PATH')
+ pr_ref = get_pr_ref(event_path)
+ else:
+ pr_ref = None
+
+ if not cifuzz.build_fuzzers(oss_fuzz_project_name,
+ github_repo_name,
+ workspace,
+ commit_sha=commit_sha,
+ pr_ref=pr_ref,
+ sanitizer=sanitizer,
+ project_src_path=project_src_path,
+ build_integration_path=build_integration_path):
+ logging.error(
+ 'Error building fuzzers for project %s (commit: %s, pr_ref: %s).',
+ oss_fuzz_project_name, commit_sha, pr_ref)
+ return returncode
out_dir = os.path.join(workspace, 'out')
- if cifuzz.check_fuzzer_build(out_dir, sanitizer=sanitizer):
+ if cifuzz.check_fuzzer_build(
+ out_dir,
+ sanitizer=sanitizer,
+ allowed_broken_targets_percentage=allowed_broken_targets_percentage):
returncode = 0
return returncode