From 1193d731aa0912f49003d6df63a1a7862dfbd5ec Mon Sep 17 00:00:00 2001 From: "Randolph W. Aarseth II" Date: Mon, 2 Dec 2024 15:02:43 -0700 Subject: [PATCH] added stuff --- .../actions/cerebro-download-build/action.yml | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/.github/actions/cerebro-download-build/action.yml b/.github/actions/cerebro-download-build/action.yml index 05c159c..80059b3 100644 --- a/.github/actions/cerebro-download-build/action.yml +++ b/.github/actions/cerebro-download-build/action.yml @@ -33,6 +33,18 @@ runs: id: fetch_build shell: bash run: | + report_error() { + local message="$1" + + # Get the line number where the function was called + local lineno="${BASH_LINENO[0]}" + + # Get the file name of the script (use $0 if running directly) + local file="${BASH_SOURCE[1]##*/}" + + # Trigger GitHub Actions error annotation + echo "::error file=$file,line=$lineno::${message}" + } # Fetch build data from Cerebro RESPONSE=$(curl -s -X GET "${{ inputs.cerebro_url }}/api/v1/enginebuilds/${{ inputs.run_id }}/${{ inputs.name }}" \ -H "Content-Type: application/json" \ @@ -41,10 +53,12 @@ runs: echo "## Fetching Build Data" >> $GITHUB_STEP_SUMMARY echo "Run ID: ${{ inputs.run_id }}" >> $GITHUB_STEP_SUMMARY echo "Build Name: ${{ inputs.name }}" >> $GITHUB_STEP_SUMMARY + echo "Raw Response: $RESPONSE" >> $GITHUB_STEP_SUMMARY + # Check if the request succeeded - if [[ $(echo '$RESPONSE' | jq -r '.success') != "true" ]]; then - echo "Error: Failed to fetch build data. Response:\n $RESPONSE" >> $GITHUB_STEP_SUMMARY + if [[ $(echo "$RESPONSE" | jq -r '.success') != "true" ]]; then + report_error "Error: Failed to fetch build data. Response: $RESPONSE" exit 1 fi @@ -55,6 +69,18 @@ runs: id: parse_build shell: bash run: | + report_error() { + local message="$1" + + # Get the line number where the function was called + local lineno="${BASH_LINENO[0]}" + + # Get the file name of the script (use $0 if running directly) + local file="${BASH_SOURCE[1]##*/}" + + # Trigger GitHub Actions error annotation + echo "::error file=$file,line=$lineno::${message}" + } # Parse the build_data JSON using fromJSON build_data=$(echo '${{ steps.fetch_build.outputs.build_data }}' | jq -c '.') completed_at=$(echo '$build_data' | jq -r '.completed_at') @@ -66,13 +92,13 @@ runs: # Check if completed_at is null if [[ "$completed_at" == "null" || -z "$completed_at" ]]; then - echo "Error: Build is not completed yet (completed_at is null)." >> $GITHUB_STEP_SUMMARY + report_error "Error: Build is not completed yet (completed_at is null)." exit 1 fi # Check if file_url is valid if [[ "$file_url" == "null" || -z "$file_url" ]]; then - echo "Error: No file URL provided in the build data." >> $GITHUB_STEP_SUMMARY + report_error "Error: No file URL provided in the build data." exit 1 fi @@ -83,6 +109,18 @@ runs: id: download_file shell: bash run: | + report_error() { + local message="$1" + + # Get the line number where the function was called + local lineno="${BASH_LINENO[0]}" + + # Get the file name of the script (use $0 if running directly) + local file="${BASH_SOURCE[1]##*/}" + + # Trigger GitHub Actions error annotation + echo "::error file=$file,line=$lineno::${message}" + } # Ensure the folder exists if [ ! -d "${{ inputs.folder }}" ]; then echo "Folder ${{ inputs.folder }} does not exist. Creating it." @@ -97,7 +135,7 @@ runs: echo "Downloading file from ${{ steps.parse_build.outputs.file_url }} to $FULL_PATH" curl -L -o "$FULL_PATH" "${{ steps.parse_build.outputs.file_url }}" if [ $? -ne 0 ]; then - echo "Error: Failed to download the file from ${{ steps.parse_build.outputs.file_url }}" >> $GITHUB_STEP_SUMMARY + report_error "Error: Failed to download the file from ${{ steps.parse_build.outputs.file_url }}" >> $GITHUB_STEP_SUMMARY exit 1 fi