Skip to content

Commit

Permalink
Merge pull request #50 from rwalker-apple/shellcheck
Browse files Browse the repository at this point in the history
run shellcheck on run_clang.sh

Merging based on 3 approvals, thanks all!
  • Loading branch information
woody-apple authored Mar 13, 2020
2 parents 85da9c0 + 7b0c733 commit ab58f0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
id: clang-tidy
env:
GITHUB_TOKEN: ${{ github.token }}
CLANG_ARGUMENTS: "-checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* -- -Isrc/includes"
CLANG_TIDY_ARGUMENTS: "-checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* -- -Isrc/includes"
FILES_MODIFIED: ${{ steps.get-changed-files.outputs.files_updated }}
FILES_ADDED: ${{ steps.get-changed-files.outputs.files_created }}
47 changes: 15 additions & 32 deletions integrations/github/actions/clang-tidy/run_clang.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
#!/bin/bash
#!/usr/bin/env bash

cd $GITHUB_WORKSPACE
cd "$GITHUB_WORKSPACE" || exit

echo "clang arguments: $CLANG_ARGUMENTS"
echo "files modified: $FILES_MODIFIED"
echo "files added: $FILES_ADDED"

read -r -a MODIFIED_FILES <<< "$FILES_MODIFIED"
read -r -a ADDED_FILES <<< "$FILES_ADDED"
# convert to arrays
read -r -a FILES_MODIFIED <<< "$FILES_MODIFIED"
read -r -a FILES_ADDED <<< "$FILES_ADDED"

clang_arguments=""
# shellcheck disable=SC2206
CLANG_TIDY_ARGUMENTS=( "${FILES_MODIFIED[@]}" "${FILES_ADDED[@]}" $CLANG_TIDY_ARGUMENTS )

for element in "${MODIFIED_FILES[@]}"
do
clang_arguments+="$element "
done
for element in "${ADDED_FILES[@]}"
do
clang_arguments+="$element "
done

clang_arguments+=" -export-fixes=fixes.yml"

clang_arguments+=" $CLANG_ARGUMENTS "


echo "final clang arguments: $clang_arguments"

# Run clang-tidy for real
clang-tidy $clang_arguments > clang_output.txt

if [ $? -eq 0 ]; then
# nun clang-tidy
if clang-tidy "${CLANG_TIDY_ARGUMENTS[@]}" -export-fixes=fixes.yml > clang_output.txt; then
echo "Clang passed! Good job!"
echo ::set-output name=clang-result::""
else
CLANG_OUTPUT=`cat clang_output.txt`
FIXES_OUTPUT=`cat fixes.yml`
LINES_OF_FIXES=$(echo $FIXES_OUTPUT | wc -l)
CLANG_OUTPUT=$(cat clang_output.txt)
FIXES_OUTPUT=$(cat fixes.yml)

# Cleanup the files we don't need
rm clang_output.txt
Expand All @@ -55,11 +38,11 @@ else
PULL_REQUEST_COMMENT+="$FIXES_OUTPUT"
PULL_REQUEST_COMMENT+=$'\n```\n'

PULL_REQUEST_COMMENT_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url)
echo ::set-output name=clang-result::$CLANG_OUTPUT
PULL_REQUEST_COMMENT_URL=$(jq -r .pull_request.comments_url < "$GITHUB_EVENT_PATH")

echo ::set-output name=clang-result::"$CLANG_OUTPUT"

if [ ! -z "$PULL_REQUEST_COMMENT_URL" -a "$str"!="" -a "$str"!="null" ]; then
if [[ -n $PULL_REQUEST_COMMENT_URL && ${str:?null} != null ]]; then
echo "Posting to comment URL: $PULL_REQUEST_COMMENT_URL"

REQUEST_DATA=$(echo '{}' | jq --arg body "$PULL_REQUEST_COMMENT" '.body = $body')
Expand Down

0 comments on commit ab58f0c

Please sign in to comment.