open-vault/.github/scripts/report_failed_builds.sh

44 lines
1.3 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
set -e
# this script expects the following env vars to be set
# error if these are not set
[ ${GITHUB_TOKEN:?} ]
[ ${RUN_ID:?} ]
[ ${REPO:?} ]
[ ${PR_NUMBER:?} ]
# list of build jobs
[ ${BUILD_OTHER:?} ]
[ ${BUILD_LINUX:?} ]
[ ${BUILD_DARWIN:?} ]
[ ${BUILD_DOCKER:?} ]
[ ${BUILD_UBI:?} ]
[ ${TEST:?} ]
[ ${TEST_DOCKER_K8S:?} ]
# listing out all of the jobs with the status
jobs=( "build-other:$BUILD_OTHER" "build-linux:$BUILD_LINUX" "build-darwin:$BUILD_DARWIN" "build-docker:$BUILD_DOCKER" "build-ubi:$BUILD_UBI" "test:$TEST" "test-docker-k8s:$TEST_DOCKER_K8S" )
# there is a case where even if a job is failed, it reports as cancelled. So, we look for both.
failed_jobs=()
for job in "${jobs[@]}";do
if [[ "$job" == *"failure"* || "$job" == *"cancelled"* ]]; then
failed_jobs+=("$job")
fi
done
# Create a comment to be posted on the PR
# This comment reports failed jobs and the url to the failed workflow
Backport of Limit number of tests in CI comment into release/1.14.x (#21971) * backport of commit dc104898f700447f7764919445c7559baeb7e987 (#21853) * fix multiline * shellcheck, and success message for builds * add full path * cat the summary * fix and faster * fix if condition * base64 in a separate step * echo * check against empty string * add echo * only use matrix ids * only id * echo matrix * remove wrapping array * tojson * try echo again * use jq to get packages * don't quote * only run binary tests once * only run binary tests once * test what's wrong with the binary * separate file * use matrix file * failed test * update comment on success * correct variable name * bae64 fix * output to file * use multiline * fix * fix formatting * fix newline * fix whitespace * correct body, remove comma * small fixes * shellcheck * another shellcheck fix * fix deprecation checker * only run comments for prs * Update .github/workflows/test-go.yml Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * Update .github/workflows/test-go.yml Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * fixes --------- Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * backport of commit 3b00dde1ba4d479fbd67b1d0767e421e495d8cce (#21936) * limit test comments * remove unecessary tee * fix go test condition * fix * fail test * remove ailways entirely * fix columns * make a bunch of tests fail * separate line * include Failures: * remove test fails * fix whitespace * backport of commit 245430215c00d80a38283020fca114bade022e0f (#21973) * only add binary tests if they exist * shellcheck --------- Co-authored-by: miagilepner <mia.epner@hashicorp.com> Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com>
2023-07-20 13:07:20 +00:00
if [ ${#failed_jobs[@]} -eq 0 ]; then
new_body="Build Results:
All builds succeeded! :white_check_mark:"
else
Backport of Limit number of tests in CI comment into release/1.14.x (#21971) * backport of commit dc104898f700447f7764919445c7559baeb7e987 (#21853) * fix multiline * shellcheck, and success message for builds * add full path * cat the summary * fix and faster * fix if condition * base64 in a separate step * echo * check against empty string * add echo * only use matrix ids * only id * echo matrix * remove wrapping array * tojson * try echo again * use jq to get packages * don't quote * only run binary tests once * only run binary tests once * test what's wrong with the binary * separate file * use matrix file * failed test * update comment on success * correct variable name * bae64 fix * output to file * use multiline * fix * fix formatting * fix newline * fix whitespace * correct body, remove comma * small fixes * shellcheck * another shellcheck fix * fix deprecation checker * only run comments for prs * Update .github/workflows/test-go.yml Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * Update .github/workflows/test-go.yml Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * fixes --------- Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * backport of commit 3b00dde1ba4d479fbd67b1d0767e421e495d8cce (#21936) * limit test comments * remove unecessary tee * fix go test condition * fix * fail test * remove ailways entirely * fix columns * make a bunch of tests fail * separate line * include Failures: * remove test fails * fix whitespace * backport of commit 245430215c00d80a38283020fca114bade022e0f (#21973) * only add binary tests if they exist * shellcheck --------- Co-authored-by: miagilepner <mia.epner@hashicorp.com> Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com>
2023-07-20 13:07:20 +00:00
new_body="Build Results:
Build failed for these jobs: ${failed_jobs[*]}. Please refer to this workflow to learn more: https://github.com/hashicorp/vault/actions/runs/$RUN_ID"
fi
Backport of Limit number of tests in CI comment into release/1.14.x (#21971) * backport of commit dc104898f700447f7764919445c7559baeb7e987 (#21853) * fix multiline * shellcheck, and success message for builds * add full path * cat the summary * fix and faster * fix if condition * base64 in a separate step * echo * check against empty string * add echo * only use matrix ids * only id * echo matrix * remove wrapping array * tojson * try echo again * use jq to get packages * don't quote * only run binary tests once * only run binary tests once * test what's wrong with the binary * separate file * use matrix file * failed test * update comment on success * correct variable name * bae64 fix * output to file * use multiline * fix * fix formatting * fix newline * fix whitespace * correct body, remove comma * small fixes * shellcheck * another shellcheck fix * fix deprecation checker * only run comments for prs * Update .github/workflows/test-go.yml Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * Update .github/workflows/test-go.yml Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * fixes --------- Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com> * backport of commit 3b00dde1ba4d479fbd67b1d0767e421e495d8cce (#21936) * limit test comments * remove unecessary tee * fix go test condition * fix * fail test * remove ailways entirely * fix columns * make a bunch of tests fail * separate line * include Failures: * remove test fails * fix whitespace * backport of commit 245430215c00d80a38283020fca114bade022e0f (#21973) * only add binary tests if they exist * shellcheck --------- Co-authored-by: miagilepner <mia.epner@hashicorp.com> Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com>
2023-07-20 13:07:20 +00:00
source ./.github/scripts/gh_comment.sh
update_or_create_comment "$REPO" "$PR_NUMBER" "Build Results:" "$new_body"