Skip to content

Commit

Permalink
Allow Basic CI Checks for Unauthorized Users (#140)
Browse files Browse the repository at this point in the history
This PR allows CI to run the following for unauthorized users:
 - Linter check
 - Branch check

Commit log:

* Save performance in ci

* Add flask to install

* Allowed for public linting of unauthorized users

* Added run mode for future advancements

* Remove exit statement

* Add error handling in run_ci and fix docs

* Delete new line
  • Loading branch information
kevindweb authored and koolzz committed Jun 12, 2019
1 parent 0090987 commit 247d1c0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
2 changes: 0 additions & 2 deletions ci/helper-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ print_header() {
done
echo "--"
echo ""

sleep 1
}

# sets up dpdk, sets env variables, and runs the install script
Expand Down
17 changes: 17 additions & 0 deletions ci/manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ else
REQUEST=$4
fi

if [[ -z "$5" ]]
then
echo "ERROR: Missing fifth argument, Run mode type!"
exit 1
else
RUN_MODE=$5
fi

. $1 # source the variables from config file

print_header "Checking Required Variables"
Expand Down Expand Up @@ -109,6 +117,15 @@ rm -f ../linter-output.txt
run_linter ../linter-output.txt
cd ..

if [[ "$RUN_MODE" -eq "1" ]]
then
# only run linter and develop checks if unauthorized
print_header "Posting Results in Comment on GitHub"
python3 post-msg.py $GITHUB_CREDS "{\"id\": $PR_ID,\"request\":\"$REQUEST\",\"linter\": 1,\"review\": 1}" $REPO_OWNER $REPO_NAME "Run successful see results:"
check_exit_code "ERROR: Failed to post results to GitHub"
exit 0
fi

print_header "Preparing Workers"

for worker_tuple in "${WORKER_LIST[@]}"
Expand Down
15 changes: 8 additions & 7 deletions ci/post-msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@
ACTION = 'REQUEST_CHANGES'

# PR must not affect performance
with open('./results_summary.stats') as f:
results = json.load(f)
if (results['pass_performance_check']):
comment_body += " :heavy_check_mark: Speed tester performance check passed\n"
else:
comment_body += " :x: PR drops speed tester perforamce bellow minimum requirement\n"
ACTION = 'REQUEST_CHANGES'
if POST_RESULTS:
with open('./results_summary.stats') as f:
results = json.load(f)
if (results['pass_performance_check']):
comment_body += " :heavy_check_mark: Speed tester performance check passed\n"
else:
comment_body += " :x: PR drops speed tester perforamce below minimum requirement\n"
ACTION = 'REQUEST_CHANGES'

# PR must pass linter check
linter_output = None
Expand Down
9 changes: 4 additions & 5 deletions ci/webhook-receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def filter_to_prs_and_pr_comments(json):

@app.route(EVENT_URL, methods=['POST'])
def init_ci_pipeline():
run_mode = 0
request_ctx = filter_to_prs_and_pr_comments(request.json)
if request_ctx is None:
logging.debug("Request filter doesn't match request")
Expand All @@ -180,11 +181,9 @@ def init_ci_pipeline():
return jsonify({"success": True})

if (request_ctx['repo'] == 'openNetVM' and request_ctx['user'] not in authorized_users):
run_mode = 1
# not an authorized user, tell manager to only run linter
print("Incoming request is from an unathorized user")
log_access_denied(request_ctx, "Incoming request is from an unathorized user")
os.system("./ci_busy.sh config {} \"{}\" \"{}\" \"User not authorized to run CI, please contact one of the repo maintainers\""
.format(request_ctx['id'], request_ctx['repo'], request_ctx['body']))
return jsonify({"success": True})

print("Request matches filter, we should RUN CI. {}".format(get_request_info(request_ctx)))

Expand All @@ -202,7 +201,7 @@ def init_ci_pipeline():
.format(request_ctx['id'], request_ctx['repo'], request_ctx['body']))
else:
log_access_granted(request_ctx, "Running CI")
os.system("./manager.sh config {} \"{}\" \"{}\"".format(request_ctx['id'], request_ctx['repo'], request_ctx['body']))
os.system("./manager.sh config {} \"{}\" \"{}\" {}".format(request_ctx['id'], request_ctx['repo'], request_ctx['body'], run_mode))

return jsonify({"status": "ONLINE"})

Expand Down

0 comments on commit 247d1c0

Please sign in to comment.