Skip to content

Commit

Permalink
Add debug info for multi status api calls (super-linter#1287)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
GaboFDC authored Mar 2, 2021
1 parent a636dea commit 46df948
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 87 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/deploy-DEV.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down Expand Up @@ -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 #
#####################################
Expand Down
128 changes: 41 additions & 87 deletions lib/functions/buildFileList.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 #
Expand All @@ -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
################
Expand All @@ -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}"
Expand Down
6 changes: 6 additions & 0 deletions lib/linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
######################################
Expand All @@ -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 #
##############################################
Expand All @@ -599,6 +603,8 @@ CallStatusAPI() {
#######################
ERROR_CODE=$?

debug "Send status comd output: [$SEND_STATUS_CMD]"

##############################
# Check the shell for errors #
##############################
Expand Down

0 comments on commit 46df948

Please sign in to comment.