From 46df94844cf76441a9e64578c934daffc7d083fc Mon Sep 17 00:00:00 2001 From: Gabriel Diaz Date: Tue, 2 Mar 2021 09:29:12 -0500 Subject: [PATCH] Add debug info for multi status api calls (#1287) * Add debug info for multi status api calls * Add test for clean action * Add more verbose * Test in action context * Test use local build as action * Improve debug for raw file array * Fix shallow fetch * Fix error messages on diff cmd * Changed repeated code to function * Fix quotes --- .github/workflows/deploy-DEV.yml | 23 ++++++ lib/functions/buildFileList.sh | 128 ++++++++++--------------------- lib/linter.sh | 6 ++ 3 files changed, 70 insertions(+), 87 deletions(-) diff --git a/.github/workflows/deploy-DEV.yml b/.github/workflows/deploy-DEV.yml index 43835a7a..a7438d79 100644 --- a/.github/workflows/deploy-DEV.yml +++ b/.github/workflows/deploy-DEV.yml @@ -42,6 +42,9 @@ jobs: ########################## - name: Checkout Code uses: actions/checkout@v2.3.4 + with: + # Full git history is needed to get a proper list of changed files within `super-linter` + fetch-depth: 0 ######################## # Get the current date # @@ -76,6 +79,26 @@ jobs: shell: bash run: .automation/validate-docker-labels.sh + ######################################## + # Edit action.yml for test local build # + ######################################## + - name: Edit an action.yml file for test local build + run: | + sed -i "s/super-linter:.*/super-linter:${GITHUB_SHA}'/g" action.yml + + ########################## + # Test in action context # + ########################## + # Test the built image in the actions context. + # Not the container directly, and not using RUN_LOCAL=true + - name: Test the local action + uses: ./ + env: + ACTIONS_RUNNER_DEBUG: true + ERROR_ON_MISSING_EXEC_BIT: true + VALIDATE_ALL_CODEBASE: false + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ##################################### # Run Linter against Test code base # ##################################### diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index 2b1a84e0..ed48de18 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -7,6 +7,44 @@ ################################################################################ ########################## FUNCTION CALLS BELOW ################################ ################################################################################ +################################################################################ +#### Function GenerateFileDiff ################################################# +function GenerateFileDiff() { + CMD="${1}" + ################ + # print header # + ################ + debug "----------------------------------------------" + debug "Generating Diff with:[$CMD]" + + ################################################# + # Get the Array of files changed in the commits # + ################################################# + CMD_OUTPUT=$($CMD) + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ ${ERROR_CODE} -ne 0 ]; then + # Error + info "Failed to get Diff with:[$CMD]" + info "Check that you have the full git history, the checkout is not shallow, etc" + info "See https://github.com/github/super-linter#example-connecting-github-action-workflow" + fatal "[${CMD_OUTPUT}]" + fi + + ################################################### + # Map command output to an array to proper handle # + ################################################### + mapfile -t RAW_FILE_ARRAY < <(echo "$DIFF_TREE_CMD_OUTPUT") + debug "RAW_FILE_ARRAY contents: ${RAW_FILE_ARRAY[*]}" +} + ################################################################################ #### Function BuildFileList #################################################### function BuildFileList() { @@ -63,38 +101,7 @@ function BuildFileList() { # push event # ################ DIFF_TREE_CMD="git diff-tree --no-commit-id --name-only -r ${GITHUB_SHA}" - - ################ - # print header # - ################ - debug "----------------------------------------------" - debug "Generating Diff with:[$DIFF_TREE_CMD]" - - ################################################# - # Get the Array of files changed in the commits # - ################################################# - DIFF_TREE_CMD_OUTPUT=$($DIFF_TREE_CMD) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Error - info "Failed to get Diff with:[$DIFF_TREE_CMD]" - info "Check that you have the full git history, the checkout is not shallow, etc" - info "See https://github.com/github/super-linter#example-connecting-github-action-workflow" - fatal "[${DIFF_TREE_CMD}]" - fi - - ################################################### - # Map command output to an array to proper handle # - ################################################### - mapfile -t RAW_FILE_ARRAY < <(echo "$DIFF_TREE_CMD_OUTPUT") + GenerateFileDiff "$DIFF_TREE_CMD" ############################################################### # Need to see if the array is empty, if so, try the other way # @@ -108,35 +115,8 @@ function BuildFileList() { debug "WARN: Generation of File array with diff-tree produced [0] items, trying with git diff..." DIFF_CMD="git -C ${GITHUB_WORKSPACE} diff --name-only ${DEFAULT_BRANCH}...${GITHUB_SHA} --diff-filter=d" + GenerateFileDiff "$DIFF_CMD" - debug "----------------------------------------------" - debug "Generating Diff with:[$DIFF_CMD]" - - ################################################# - # Get the Array of files changed in the commits # - ################################################# - DIFF_CMD_OUTPUT=$($DIFF_CMD) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Error - info "Failed to get Diff with:[$DIFF_CMD]" - info "Check that you have the full git history, the checkout is not shallow, etc" - info "See https://github.com/github/super-linter#example-connecting-github-action-workflow" - fatal "[${DIFF_CMD}]" - fi - - ################################################### - # Map command output to an array to proper handle # - ################################################### - mapfile -t RAW_FILE_ARRAY < <(echo "$DIFF_CMD_OUTPUT") fi else ################ @@ -146,33 +126,7 @@ function BuildFileList() { # print header # ################ DIFF_CMD="git -C ${GITHUB_WORKSPACE} diff --name-only ${DEFAULT_BRANCH}...${GITHUB_SHA} --diff-filter=d" - - debug "----------------------------------------------" - debug "Generating Diff with:[$DIFF_CMD]" - - ################################################# - # Get the Array of files changed in the commits # - ################################################# - DIFF_CMD_OUTPUT=$($DIFF_CMD) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Error - info "Failed to get Diff with:[$DIFF_CMD]" - fatal "[${DIFF_CMD}]" - fi - - ################################################### - # Map command output to an array to proper handle # - ################################################### - mapfile -t RAW_FILE_ARRAY < <(echo "$DIFF_CMD_OUTPUT") + GenerateFileDiff "$DIFF_CMD" fi else WORKSPACE_PATH="${GITHUB_WORKSPACE}" diff --git a/lib/linter.sh b/lib/linter.sh index 845e5314..ae28c5a2 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -558,6 +558,8 @@ CallStatusAPI() { FAIL_MSG='Errors were detected, please view logs' MESSAGE='' # Message to send to status API + debug "Calling Multi-Status API for $LANGUAGE with status $STATUS" + ###################################### # Check the status to create message # ###################################### @@ -579,6 +581,8 @@ CallStatusAPI() { STATUS="success" fi + debug "URL: ${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" + ############################################## # Call the status API to create status check # ############################################## @@ -599,6 +603,8 @@ CallStatusAPI() { ####################### ERROR_CODE=$? + debug "Send status comd output: [$SEND_STATUS_CMD]" + ############################## # Check the shell for errors # ##############################